Rahul has a Dell company's laptop
with 4 GB RAM, 1 TB HDD, 2 GB
Graphics card, Windows 10, and Intel i5
processor. But, now he wants to buy
another laptop from another company
with the same exact configuration. So,
he takes his laptop to the shop and
shows his laptop to the shopkeeper,
and asks him to give him a different
company's laptop with the same
configuration
#include <iostream>
#include <string>
using namespace std;
class Laptop{
private:
string name;
int RAM;
int HDD;
int graphicCard;
string OS;
string processor;
public:
//constructor
Laptop(string name,int RAM,int HDD,int graphicCard,string OS,string processor){
this->name=name;
this->RAM=RAM;
this->HDD=HDD;
this->graphicCard=graphicCard;
this->OS=OS;
this->processor=processor;
}
// Copy constructor
Laptop(const Laptop &laptop) {
this->name=laptop.name;
this->RAM=laptop.RAM;
this->HDD=laptop.HDD;
this->graphicCard=laptop.graphicCard;
this->OS=laptop.OS;
this->processor=laptop.processor;
}
//Displays info about Laptop
void display(){
cout<<"Name: "<<this->name<<"\n";
cout<<"RAM: "<<this->RAM<<" GB\n";
cout<<"HDD: "<<this->HDD<<" TB\n";
cout<<"Graphic card: "<<this->graphicCard<<" GB\n";
cout<<"OS: "<<this->OS<<"\n";
cout<<"Processor: "<<this->processor<<"\n\n";
}
~Laptop(){}
};
int main (){
//Create the current Rahul laptop
Laptop currentRahulLaptop=Laptop("Dell",4,1,2,"Windows 10","Intel i5");
cout<<"Current Rahul laptop: \n";
//display the current Rahul laptop
currentRahulLaptop.display();
//Create the company laptop using copy constructor
Laptop companyLaptop=currentRahulLaptop; // Copy constructor is called here
//display the company laptop
cout<<"\nCompany's laptop with the same configuration:\n";
companyLaptop.display();
system("pause");
return 0;
}
Comments
Leave a comment