Sponsored Links


Results 1 to 3 of 3

Thread: CS201 Assignment vo 3 Solution 20th January 2016

  1. #1
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

    Thumbs up CS201 Assignment vo 3 Solution 20th January 2016

    Sponsored Links1


    Assignment


    Write a C++ program that will create a class named Computer. This class will have 4 data members
    1. Vendor
    2. CPU
    3. Hard disk
    4. RAM

    You are required to write a default and a parameterized constructor for this class. Also write getter and setter functions for each data member of the class.

    In the default constructor, you will initialize all the data members with default values. The message “Default constructor called…” should be displayed whenever an object is created using default constructor.

    In parameterized constructor, you will initialize all the data members with the values passed to it as arguments. You are required to use setter functions inside parameterized constructor to initialize the data members. The message “Parameterized constructor called…” should be displayed whenever an object is created with parameterized constructor.

    In the main() function, create 2 objects (1 using default and 1 using parameterized constructor) and display the values of data members of both objects using getter functions.

    Sample output for the program is shown below:

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    These two constructors should be defined in the Public not in the Private of the Class

    To define the default constructor

    Computer ::Computer ();

    To define the parametric constructor

    Computer ::Computer(string,string,int,int);

  3. #3
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    //Memona Raza ID:BC150404237
    #include <iostream>
    using namespace std;
    class Computer{
    private:
    string Vendor;
    string Cpu;
    int Ram ;
    int Hardisk ;
    public :
    Computer();
    Computer(string Vin ,string Cp,int rm,int hr) {
    Vendor=Vin;
    Cpu=Cp;
    Ram=rm;
    Hardisk=hr;}
    void show(){
    cout Vendor" "endlCpu " "endl "Ram : " Ram" "endl"Hard Disk : "Hardisk" "endl;

    };

    void setVendor(string);
    void setCpu(string);
    void setRam(int);
    void setHardisk(int);
    string getVendor();
    string getCpu();
    int getRam();
    int getHardisk();
    };
    Computer::Computer(){
    Vendor;
    Cpu;
    Ram ;
    Hardisk;

    }
    void Computer::setVendor(string Ven){
    Ven= " :None";
    Vendor=Ven;
    }
    void Computer::setCpu(string cap){
    cap = " :None";
    Cpu= cap;
    }
    void Computer::setRam(int r){
    r = 0 ;
    Ram = r;
    }
    void Computer::setHardisk(int h){
    h = 0;
    Hardisk = h;
    }
    string Computer::getVendor(){
    return Vendor;
    }
    string Computer::getCpu(){
    return Cpu;
    }
    int Computer::getRam(){
    return Ram;

    Sponsored Links

    }
    int Computer::getHardisk(){
    return Hardisk;
    }

    int main(){
    Computer sys ;
    string Vin;
    string Cp;
    int rm;
    int hr;
    sys.setVendor(Vin);
    sys.setCpu(Cp);
    sys.setRam(rm);
    sys.setHardisk(hr);
    cout "The default Constructor is called....."endl;
    cout "Vendor:"sys.getVendor()endl;
    cout " Cpu: "sys.getCpu()endl;
    cout "Ram:"sys.getRam()endl;
    cout "Hard disk:" sys.getHardisk()endl;
    cout endl;
    cout "The parameterized Constructor is called......" endlendl;
    Computer para(" Vendor : Intel"," CPU :i5",4, 500);
    para.show();
    return 0;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 01-20-2016, 02:19 PM
  2. Replies: 1
    Last Post: 01-20-2016, 02:18 PM
  3. Replies: 1
    Last Post: 01-20-2016, 02:15 PM
  4. Replies: 0
    Last Post: 01-20-2016, 02:10 PM
  5. Replies: 2
    Last Post: 01-26-2012, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft