Question Number 4 (CLO 3) (25 marks) Write an object oriented program that will ask the user to enter the specifications of a mobile phone so that the viewers can see them in advertisement form and can compare them for their best choice. Make the program in such a way that user can view the mobiles one by one or all the brands on the same screen. Some Useful Hints Create a class named smart_phone Put the mobile name, price, display size, memory, processor speed, camera and display resolution in private data. A member function will ask the user to enter the data for mobile • Another function will display the data of each object Another function will display the data by combining all the objects (this function will accept 3 objects as argument) and 4th object will be the object on which the function is called. • In main program declare 4 objects • Ask the owner to enter the details for 4 mobiles
#include<iostream>
using namespace std;
class smart_phone{
private:
string mobile_name;
string price;
string size;
string memory;
string processor_speed;
string camera;
string display_resolution;
public:
void setName(string n){
mobile_name = n;
}
void setPrice(string p){
price = p;
}
void setSize(string s){
size = s;
}
void setMemory(string m){
memory = m;
}
void setProcessor(string s){
processor_speed = s;
}
void setCamera(string c){
camera = c;
}
void setResolution(string r){
display_resolution = r;
}
string getName(){
return mobile_name;
}
string getPrice(){
return price;
}
string getSize(){
return size;
}
string getMemory(){
return memory;
}
string getProcessor(){
return processor_speed;
}
string getCamera(){
return camera;
}
string getResolution(){
return display_resolution;
}
void enter_data(){
string n, p, s, me, pr, c, d;
cout<<"Enter the mobile name"<<endl;
getline(cin,mobile_name);
cout<<"Enter the price"<<endl;
getline(cin,price);
cout<<"Enter the size"<<endl;
getline(cin,size);
cout<<"Enter the memory"<<endl;
getline(cin,memory);
cout<<"Enter the processor_speed"<<endl;
getline(cin,processor_speed);
cout<<"Enter the camera"<<endl;
getline(cin,camera);
cout<<"Enter the display resolution"<<endl;
getline(cin,display_resolution);
setName(mobile_name); setPrice(price); setSize(size); setMemory(memory); setProcessor(processor_speed); setCamera(camera);
setResolution(display_resolution);
}
void display_data(){
cout<<"Name"<<"\t\t"<<getName()<<endl;
cout<<"Price"<<"\t\t"<<getPrice()<<endl<<"Display Size"<<"\t\t"<<getSize()<<endl;
cout<<"Memory \t\t"<<getMemory()<<endl<<"Processor Speed \t\t"<<getProcessor()<<endl;
cout<<"Camera \t\t"<<getCamera()<<endl;
cout<<"Display Resolution \t\t"<<getResolution()<<endl;
}
void display_all(smart_phone first, smart_phone second, smart_phone third, smart_phone fourth){
cout<<"Properties"<<"\t\t"<<"Mobile 1"<<"\t\t"<<"Mobile 2"<<"\t\t"<<"Mobile 3 "<<"\t\t"<<"Mobile 4"<<endl;
cout<<"Name \t\t\t"<<first.mobile_name<<"\t\t\t"<<second.mobile_name<<"\t\t\t"<<third.mobile_name<<"\t\t\t"<<fourth.mobile_name<<endl;
cout<<"Price \t\t"<<first.price<<"\t\t\t"<<second.price<<"\t\t\t"<<third.price<<"\t\t\t"<<fourth.price<<endl;
cout<<"Size \t\t\t"<<first.getSize()<<"\t\t\t"<<second.getSize()<<"\t\t\t"<<third.getSize()<<"\t\t\t"<<fourth.getSize()<<endl;
cout<<"Memory \t\t"<<first.memory<<"\t\t\t"<<second.memory<<"\t\t\t"<<third.memory<<"\t\t\t"<<fourth.memory<<endl;
cout<<"Speed \t\t\t"<<first.getProcessor()<<"\t\t\t"<<second.processor_speed<<"\t\t\t"<<third.getProcessor()<<"\t\t\t"<<fourth.getProcessor()<<endl;
cout<<"Camera \t\t"<<first.camera<<"\t\t\t"<<second.camera<<"\t\t\t"<<third.camera<<"\t\t\t"<<fourth.camera<<endl;
cout<<"Resolution \t\t"<<first.display_resolution<<"\t\t\t"<<second.display_resolution<<"\t\t\t"<<third.display_resolution<<"\t\t\t"<<fourth.display_resolution<<endl;
}
};
int main(){
smart_phone smart;
smart_phone smart1;
smart_phone smart2;
smart_phone smart3;
smart_phone smart4;
cout<<"\nEnter details of Smart Phone 1 : \n";
smart1.enter_data();
cout<<"\nEnter details of smart Phone 2 : \n";
smart2.enter_data();
cout<<"\nEnter details of smart Phone 3 : \n";
smart3.enter_data();
cout<<"\nEnter details of smart Phone 4 : \n";
smart4.enter_data();
cout<<"\n"<<endl;
smart.display_all(smart1,smart2,smart3,smart4);
}
Comments
Leave a comment