Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS201 Assignment vo 3 Solution 20th January 2016
#1
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:

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#2
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);

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#3
//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:ConfusedetVendor(string Ven){
Ven= " :None";
Vendor=Ven;
}
void Computer:ConfusedetCpu(string cap){
cap = " :None";
Cpu= cap;
}
void Computer:ConfusedetRam(int r){
r = 0 ;
Ram = r;
}
void Computer:ConfusedetHardisk(int h){
h = 0;
Hardisk = h;
}
string Computer::getVendor(){
return Vendor;
}
string Computer::getCpu(){
return Cpu;
}
int Computer::getRam(){
return Ram;

}
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;
}

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,196 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,086 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,278 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,868 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,093 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,907 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,526 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,557 05-15-2015, 03:52 AM
Last Post: Xpert
  Assignment No. 01 Spring 2015 Information Systems CS507 idea solution spring 2015 Xpert 0 2,445 05-15-2015, 03:49 AM
Last Post: Xpert
  cs401 assignment no 1 spring may 2015 solution for idea Xpert 0 4,369 05-15-2015, 03:45 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)