Develop a functional flowchart and then write a C++ program as explained below.
ID: 3680025 • Letter: D
Question
Develop a functional flowchart and then write a C++ program as explained below. You will be using classes, objects, strings, and appropriate data members and member functions, constructors, destructor, etc. to handle the tasks outlined below.
The class will be named Car and will contain the following data members (in the private access region):
Manufacturer - Car Manufacturer
Model - Car Model
Price - Car Price
Rebate - Car Rebate, if any
You will determine the type of data to be used for each data member.
After the declaration of the class, declare two objects of the class called car1 and car2. Both objects will be initialized using the default constructor. You will prompt the user to provide the necessary data for the first object and the second object. A member function display() will display the information about each car in the format shown below. You will need to define and implement all of the needed accessor and mutator member functions. A user-defined function named displayCars() will retrieve the information about each car and displays them in the format shown below (This is a second display of the information). At the beginning of each display, display a label indicting the output is displayed via the member function display() and the output is displayed via the user-defined function displayCars().
Car1 Car2
Manufacturer
Model
Price
Rebate
Explanation / Answer
Please find the required code below:
#include <iostream>
#include <string.h>
using namespace std;
class Car
{
private:
string Manufacturer;
string Model;
double Price;
double Rebate;
public:
Car(){
}
Car(string mn, string mo, double pr, double re){
Manufacturer = mn;
Model = mo;
Price = pr;
Rebate = re;
}
~Car(void){
}
void setManufacturer(string mn){
Manufacturer = mn;
}
void setModel(string mo){
Model = mo;
}
void setPrice(double pr){
Price = pr;
}
void setRebate(double re){
Rebate = re;
}
string getManufacturer(){
return Manufacturer;
}
string getModel(){
return Model;
}
double getPrice(){
return Price;
}
double getRebate(){
return Rebate;
}
};
void display(Car c1, Car c2){
cout << "the output is displayed via the member function display()" << endl;
cout << " Car1 Car2" << endl;
cout << "Manufacturer " << c1.getManufacturer() <<" "<< c2.getManufacturer() << endl;
cout << "Model " << c1.getModel() <<" "<< c2.getModel() << endl;
cout << "Price " << c1.getPrice() <<" "<< c2.getPrice() << endl;
cout << "Rebate " << c1.getRebate() <<" "<< c2.getRebate() << endl;
}
void displayCars(Car c1, Car c2){
cout << "the output is displayed via the member function displayCars()" << endl;
cout << " Car1 Car2" << endl;
cout << "Manufacturer " << c1.getManufacturer() <<" "<< c2.getManufacturer() << endl;
cout << "Model " << c1.getModel() <<" "<< c2.getModel() << endl;
cout << "Price " << c1.getPrice() <<" "<< c2.getPrice() << endl;
cout << "Rebate " << c1.getRebate() <<" "<< c2.getRebate() << endl;
}
int main( )
{
Car car1;
Car car2;
string mn,mo;
double pr,re;
cout << "Enter car 1 details : Manufacturer, Model, price, and rebate" << endl;
cin >> mn;
cin >> mo;
cin >> pr;
cin >> re;
car1.setManufacturer(mn);
car1.setModel(mo);
car1.setPrice(pr);
car1.setRebate(re);
cout << "Enter car 2 details : Manufacturer, Model, price, and rebate" << endl;
cin >> mn;
cin >> mo;
cin >> pr;
cin >> re;
car2.setManufacturer(mn);
car2.setModel(mo);
car2.setPrice(pr);
car2.setRebate(re);
display(car1,car2);
displayCars(car1,car2);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.