Answer to Question #186485 in C++ for Root

Question #186485

You

are required to design a software for a vehicle showroom to manage its

activities in C++. Given the following requirements:


 


The showroom has a name, address

and sales tax number. The showroom sells cars and trucks. Car has a

manufacturer, model and number of doors, truck has a manufacturer, model and

loading capacity.

  •  Please decide which classes would be needed and what would be the relationship between those classes.
  •  Write the interface of the classes decided above .
1
Expert's answer
2021-05-05T10:31:21-0400
#include <iostream>
#include <string>


using namespace std;


class Vehicle{
private:
	string manufacturer;
	string model;
public:
	//Constructor
	Vehicle(){}
	//Constructor
	Vehicle(string manufacturer,string model){
		this->manufacturer=manufacturer;
		this->model=model;
	}
	virtual void display(){
		cout<<"Manufacturer: "<<this->manufacturer<<"\n";
		cout<<"Model: "<<this->model<<"\n";
	}
};


//define class Car inherits Vehicle
class Car:public Vehicle{
//Car has a manufacturer, model and number of doors
private:
	int numberDoors;
public:
	//Constructor
	Car(){}
	//Constructor
	Car(string manufacturer,string model,int numberDoors):Vehicle(manufacturer,model){
		this->numberDoors=numberDoors;
	}
	void display(){
		Vehicle::display();
		cout<<"The number of doors: "<<this->numberDoors<<"\n";
	}
};




//define class Truck inherits Vehicle
class Truck:public Vehicle{
	//Truck has a manufacturer, model and loading capacity.
private:
	int loadingCapacity;
public:
	//Constructor
	Truck(){}
	//Constructor
	Truck(string manufacturer,string model,int loadingCapacity):Vehicle(manufacturer,model){
		this->loadingCapacity=loadingCapacity;
	}
	void display(){
		Vehicle::display();
		cout<<"The loading capacity: "<<this->loadingCapacity<<"\n";
	}
};




//define class showroom 
class Showroom {
private:
	string name; 
	string address;
	string salesTaxNumber;
	Vehicle** vehicles;
	int totalVehicles;
public:
	//Constructor
	Showroom(string name,string address,string salesTaxNumber){
		this->name=name;
		this->address=address;
		this->salesTaxNumber=salesTaxNumber;
		this->totalVehicles=0;
		vehicles=new Vehicle*[100];
	}
	//add vehicle
	void addVehicle(Vehicle* newVehicle){
		this->vehicles[this->totalVehicles]=newVehicle;
		this->totalVehicles++;
	}
	void displayShowroom(){
		cout<<"Showroom name: "<<this->name<<"\n"; 
		cout<<"Showroom address: "<<this->address<<"\n"; 
		cout<<"Showroom sales tax number: "<<this->salesTaxNumber<<"\n"; 
	}
	void displayVehicles(){
		cout<<"Total number of vehicles: "<<this->totalVehicles<<"\n";
		for(int i=0;i<this->totalVehicles;i++){
			this->vehicles[i]->display();
			cout<<"\n";
		}
	}
};




int main()
{
	Showroom showroom("Car Showroom","Main road 456","789465464312");
	showroom.addVehicle(&Car("Manufacturer 1","Model 1",4));
	showroom.addVehicle(&Car("Manufacturer 2","Model 2",2));
	showroom.addVehicle(&Car("Manufacturer 3","Model 3",4));


	showroom.addVehicle(&Truck("Manufacturer 1","Model 45",2000));
	showroom.addVehicle(&Truck("Manufacturer 2","Model 78",3000));
	showroom.addVehicle(&Truck("Manufacturer 3","Model 78",5000));


	showroom.displayShowroom();
	cout<<"\n";
	showroom.displayVehicles();


	system("pause");
	return 0;
}



Output:



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