Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ Assignment Help using arrays... I think :D

  • 23-02-2009 03:07PM
    #1
    Registered Users, Registered Users 2 Posts: 1,507 ✭✭✭


    Hello,
    I've been set an assignment in uni to design a program that allows the user to input a set of values for the components of pcs. They must then be presented with a list of the computer brand names. When one of these brand names is chosen, the programme spits out the info relating to that pc. I know it's a stupid programme but thats what he wants so I gotta do it.

    The code I've done is shown below
    // asdasdasdasdsada.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    // fshshsh.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    #include <iostream.h>
    #include <string.h>
    
    class motherboard {
     public:
       void m_set();
       void m_get();
     private:
       char processor[32];
       int speed;
       int ram;
    };
    void motherboard::m_set()
    {
     cout<<"Enter manufacturer of processor:"<<endl;
     cin>>processor;
    
     cout<<"Enter processor speed in GHZ:"<<endl;
     cin>>speed;
    
     cout<<"Enter RAM value in GB:"<<endl;
     cin>>ram;
    
     cout << "" << endl;
    };
    
    void motherboard::m_get()
    {
     cout<<"Processor: "<< processor <<endl;
      cout <<"Processor Speed: "<<speed<< " GHZ " <<endl;
      cout <<"RAM: "<< ram << "GB" <<endl;
    }
    
    
    class videocard {
     public:
       void v_set();
       void v_get();
     private:
       char brand[32];
       int xresn;
       int yresn;
       int memorysize;
    };
    void videocard::v_set()
    {
     cout<<"Enter manufacturer of video card:"<<endl;
     cin>>brand;
    
     cout<<"Enter video-card memory size:"<<endl;
     cin>>memorysize;
    
     cout<<"Enter X-Plane Resolution:"<<endl;
     cin>>xresn;
    
     cout<<"Enter Y-Plane Resolution:"<<endl;
     cin>>yresn;
    };
    
    void videocard::v_get()
    {
     cout<<"Videocard Manufacturer: "<< brand <<endl;
      cout<<"Size of videocard memory: "<< memorysize<<endl;
      cout<<"Resolution: "<< xresn <<" by "<< yresn<<endl;
    }
    
    
    class computer : public motherboard, public videocard
     {
     public:
       void c_set();
       void c_get();
     private:   
       char name[32];
       int hard_disk;
       float price;
    };
    
    void computer::c_set()
    {
     cout<<"Enter manufacturer of the computer:"<<endl;
     cin>>name;
    
     cout<<"Hard-disk Capacity in GB:"<<endl;
     cin>>hard_disk;
    
     cout<<"Cost:"<<endl;
     cin>>price;
    };
    
    void computer::c_get()
    {
    cout 	 << "Computer Manufacturer :" << name << endl;
    cout     << "Hard-Disk Capacity: " << hard_disk << "GB" << endl;
    cout     << "Cost of unit: " << price << "GBP" << endl;
      
    }
    
    int main (void)
    {
    int count = 0;
    int num = 0;
    int back = 0;
    
    computer my_pc [10];
    videocard vcard[10];
    motherboard mb[10];
    
    cout << " Please enter the number of computer specifications that you wish to input: " << endl;
    cin >> num;
    
    for ( count = 0;  count<num ; count++ )
    {
    
    my_pc[count].c_set();
    vcard[count].v_set();
    mb[count].m_set();
    
    }
    cout << " Which computer would you like to choose? From 0 -" << num - 1 << endl;
    cin>> back;
    
    cout << " Computer " << back << endl;
    my_pc[back].c_get();
    cout << "" << endl;
    cout << " Video Card Specifications " << endl;
    vcard[back].v_get();
    cout << "" << endl;
    cout << " Motherboard Specifications " <<endl;
    mb[back].m_get();
    
    
    }
    
    This works so far and I'm pretty happy with it tbh. The only thing I'm stuck on is the brand name list. Can anyone suggest how I might be able to do this? I basically want a list e.g 1: Compaq, 2: Dell, 3: Avion, that will show the corresponding components. As you can see from above, I can choose a pc if I write down what position I entered them in.

    I hope I've made myself clear but I'm not the best at explaining, thanks for any help anyway.


Advertisement