Answer to Question #179770 in C++ for Kalyan

Question #179770

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


1
Expert's answer
2021-04-09T03:41:31-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS