PC class is solely for relationship purposes to show our understanding of the co
ID: 3707434 • Letter: P
Question
PC class is solely for relationship purposes to show our understanding of the concept
Develop an object-oriented model and then write a C+program as explained below. You will be using classes and objects, and appropriate member functions, constructors, destructor, etc. to handle the tasks outlined below. You will divide up your H5 code into multiple-modu le program as discussed in class. Develop a C++ program that declares a base class Computer and will contain the following data member in the private access region: Manufacturer Model Processor Model Year Weight - PC Model Processor Type and Speed - Year Manufactured Shipping Weight There are two classes derived from the base class Computer. One class is Desktop and the other class is Laptop. The class Deskto p adds the following data members in the Registration Number Serial Number Owner private acce ss regions region as shown below - PC Registration Number -PC Serial Number -PC Owner The class Laptop adds the following data members in the private access regions region as shown below Screen Size Hard Drive Size Color Options -in inches -in GB or TB - case color The third class is named PC and will contain objects of the other two classes as its members (declared in the private access region). This class is ane xample of has a relationship. You will declare and define all member functions for all three classes as needed, including constructors and Declare two objects of the class Desktop. Initialize the first object using the default constructor. Initialize the second object using overloaded constructor. The data needed for the second object is obtained from the keyboard before the object is constructed. Follow the same procedure for the Laptop objects. Once all objects are created, you print the information for each of the four objects. You can define your own method(s) to accomplish these tasks (you have many options).Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
class General
{
private:
string Manufacturer;
string Model;
struct Processor
{
string type;
float speed;
}p;
int Model_year;
float weight;
public:
void setManufacturer(string manufacturer_info)
{
Manufacturer=manufacturer_info;
}
void setModel(string model_info)
{
Model=model_info;
}
void setProcessorType(string processor_type_info)
{
p.type=processor_type_info;
}
void setProcessorSpeed(float speed)
{
p.speed=speed;
}
void setModelYear(int modelyear_info)
{
Model_year=modelyear_info;
}
void setWeiht(float weight_info)
{
weight=weight_info;
}
string getManufacturer()
{
return Manufacturer;
}
string getModel()
{
return Model;
}
string getProcessorType()
{
return p.type;
}
float getProcessorSpeed()
{
return p.speed;
}
int getModelYear()
{
return Model_year;
}
float getWeiht()
{
return weight;
}
};
class Spec
{
private:
string Registration_numer;
string Serial_number;
string Owner;
public:
void setRegistrationNumber(string registration_numer_info)
{
Registration_numer=registration_numer_info;
}
void setSerialNumber(string serial_number_info)
{
Serial_number=serial_number_info;
}
void setOwner(string owner_info)
{
Owner=owner_info;
}
string getRegistrationNumber()
{
return Registration_numer;
}
string getSerialNumber()
{
return Serial_number;
}
string getOwner()
{
return Owner;
}
};
class PC
{
private:
General general_info;
Spec spec_info;
public:
void setManufacturer(string manufacturer_info)
{
general_info.setManufacturer(manufacturer_info);
}
void setModel(string model_info)
{
general_info.setModel(model_info);
}
void setProcessorType(string processor_type_info)
{
general_info.setProcessorType(processor_type_info);
}
void setProcessorSpeed(float processor_speed_info)
{
general_info.setProcessorSpeed(processor_speed_info);
}
void setModelYear(int modelyear_info)
{
general_info.setModelYear(modelyear_info);
}
void setWeiht(float weight)
{
general_info.setWeiht(weight);
}
void setRegistrationNumber(string registration_numer_info)
{
spec_info.setRegistrationNumber(registration_numer_info);
}
void setSerialNumber(string serial_number_info)
{
spec_info.setSerialNumber(serial_number_info);
}
void setOwner(string owner_info)
{
spec_info.setOwner(owner_info);
}
string getManufacturer()
{
string manufacturer_info=general_info.getManufacturer();
return manufacturer_info;
}
string getModel()
{
string model_info=general_info.getModel();
return model_info;
}
string getProcessorType()
{
string processor_type_info=general_info.getProcessorType();
return processor_type_info;
}
float getProcessorSpeed()
{
float processor_speed_info=general_info.getProcessorSpeed();
return processor_speed_info;
}
int getModelYear()
{
int modelyear_info=general_info.getModelYear();
return modelyear_info;
}
float getWeight()
{
float weight=general_info.getWeiht();
return weight;
}
string getRegistrationNumber()
{
string registration_numer_info=spec_info.getRegistrationNumber();
return registration_numer_info;
}
string getSerialNumber()
{
string serial_number_info=spec_info.getSerialNumber();
return serial_number_info;
}
string getOwner()
{
string owner_info=spec_info.getOwner();
return owner_info;
}
};
int main()
{
PC pc1,pc2,PC,twopc[2];;
string info;
float weight,processor_speed_info;
int year;
pc1.setManufacturer("Dell");
pc1.setModel("inspiron 254");
pc1.setProcessorType("i5");
pc1.setProcessorSpeed(2.3);
pc1.setModelYear(2015);
pc1.setWeiht(1.8);
pc1.setRegistrationNumber("asd2345");
pc1.setSerialNumber("234567");
pc1.setOwner("John Dear");
cout<<"Enter PC2 Detail"<<endl;
cout<<"Enter Manufacturer:"<<endl;
cin>>info;
pc2.setManufacturer(info);
cout<<"Enter Model:"<<endl;
cin>>info;
pc2.setModel(info);
cout<<"Enter Proce Type:"<<endl;
cin>>info;
pc2.setProcessorType(info);
cout<<"Enter processor_speed_info:"<<endl;
cin>>processor_speed_info;
pc2.setProcessorSpeed(processor_speed_info);
cout<<"Enter Model year"<<endl;
cin>>year;
pc2.setModelYear(year);
cout<<"Enter weight:"<<endl;
cin>>weight;
pc2.setWeiht(weight);
cout<<"Enter registration_numer_info:"<<endl;
cin>>info;
pc2.setRegistrationNumber(info);
cout<<"Enter serial_number_info:"<<endl;
cin>>info;
pc2.setSerialNumber(info);
cout<<"Enter Owner:"<<endl;
cin>>info;
pc2.setOwner(info);
//twopc[0]=pc1;
//twopc[1]=pc2;
cout<<" PC1 Pc2"<<endl;
cout<<"Model";
cout<<" "<<pc1.getModel()<<" "<<pc2.getModel()<<endl;
cout<<"Processor";
cout<<" "<<pc1.getProcessorType()<<" "<<pc1.getProcessorSpeed()<<" "<<pc2.getProcessorType()<<" "<<pc2.getProcessorSpeed()<<endl;
cout<<"registration Numer";
cout<<" "<<pc1.getRegistrationNumber()<<" "<<pc2.getRegistrationNumber()<<endl;
cout<<"Serial Numer";
cout<<" "<<pc1.getSerialNumber()<<" "<<pc2.getSerialNumber()<<endl;
cout<<"Owner";
cout<<" "<<pc1.getOwner()<<" "<<pc2.getOwner()<<endl;
cout<<"Model year";
cout<<" "<<pc1.getModelYear()<<" "<<pc2.getModelYear()<<endl;
cout<<"Weight";
cout<<" "<<pc1.getWeight()<<" "<<pc2.getWeight()<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.