Picture a car dealership. There are many different types of vehicles for sale. The salespeople know every detail about every one. But the accountants inside only care that a vehicle is getting sold. Model this system:
Make two functions that take a Vehicle pointer as an argument. Call one Salesperson and the other Accountant.
The salesperson function:
The Accountant function:
If you are looking at this in a panic, stop just looking at. You can see there is a Hatchback class and a Sedan class. They have a lot of similarities so they need a base class. Then just start putting things places. If you find you put the same thing in two classes, move it to the parent.
//screenshot of code
//screenshot of output
//code to copy
#include<iostream>
using namespace std;
class Car //base class for Car
{
protected:
string type;
double price;
int doors;
double trunkSize;
bool start;
public:
Car() //constructor for base Car class
{
start=true; //Both car start.
}
void salesPerson() //required salesPerson function
{
cout<<"Type:"<<type<<endl;
cout<<"Doors:"<<doors<<endl;
cout<<"trunkSize:"<<trunkSize<<endl;
if(start)
{
cout<<"Starts the car."<<endl;
}
}
void accountant()
{
cout<<"Price::"<<price<<" $"<<endl;
}
};
class Hatchbacks:public Car //Hatchbacks class derived from Car
class
{
public:
Hatchbacks()
{
type="Hatchbacks";
doors=5;
trunkSize=30.0;
price=31500.00;
}
};
class Sedan: public Car //Sedan class derived from Car
class
{
public:
Sedan()
{
type="Sedan";
doors=4;
trunkSize=20.0;
price=14900.00;
}
};
int main()
{
Car *ptr; //pointer of base class(Car class)
char input;
cout<<"Enter H for Hatchback and S for Sedan:";
cin>>input;
if(input=='H'||input=='h')
{
ptr =new Hatchbacks(); //give refrence of Hatchback class object to
Car class pointer
}
else if(input=='S'||input=='s')
{
ptr =new Sedan(); //give refrence of Sedan class object to Car
class pointer
}
else
{
cout<<"Enter valid Input."<<endl;
exit(1);
}
ptr->salesPerson(); //call salesPerson function of base
class(Car class )
ptr->accountant(); //call accountant function of base class(Car
class )
return 0;
}
Picture a car dealership. There are many different types of vehicles for sale. The salespeople know...
Kevis Family RV Kevis Family RV is a dealership that sells new recreational vehicles and travel trailers. A customer works with a salesperson to negotiate a vehicle purchase. A sales invoice is completed by the salesperson when a purchase has been agreed upon. The invoice includes full customer information, information on the trade-in vehicle (if any), the trade-in allowance, information on the purchased vehicle, the final negotiated price, plus any applicable taxes and license fees. If the customer requests dealer-installed...
Lab 2 – Classes include the header files for the classes Overview The purpose of this assignment is to give you some experience writing classes in C++, including utilizing accessors and constructors to organize data properly. Description This program will represent a hypothetical car production line, which consists of a chassis (body of a vehicle) and wheels. These two components will be used to make fully functioning vehicles (just use your imagination). To that end, there are three classes you...
Zipcar: “It’s Not About Cars—It’s About Urban Life” Imagine a world in which no one owns a car. Cars would still exist, but rather than owning cars, people would just share them. Sounds crazy, right? But Scott Griffith, CEO of Zipcar, the world’s largest car-share company, paints a picture of just such an imaginary world. And he has nearly 800,000 passionate customers—or Zipsters, as they are called—who will back him up. Zipcar specializes in renting out cars by the hour...
Fraud at Berry, CPA’s BERRY, CERTIFIED PUBLIC ACCOUNTANTS Brief History of the Firm In 1999, John Berry graduated from college with an accounting degree. After 10 years at an international accounting firm, John decided to start his firm, Berry, CPA’s. The firm, located in Oakwood, caters to local clients; specifically, John and his staff of four professionals specialize in non-public companies. The majority of the services provided by Berry, CPA’s are tax planning and preparation; however, the firm also performs...
Only need help with question 5 2 CASE The Human Resource Function of Harrison Brothers Corporation COMPANY HISTORY Harrison Brothers Corporation n was founded in upstate New York on September 15, 1898, by Aubrey and William Harrison. Harrison Brothers is a multi-line traditional department store tha t cares mainly men's, wome expanded to include household furnishings and other items for the home. The long-term goal of the company is to become the leading chain of department stores in the Northeast,...
David’s Story “Life is difficult.” I once read these three trivial words in a book, but never knew how true to life and impactful they would be until one fateful fall evening. Before I begin, let me back up and tell you more about who I am and how I got here. I am a Caucasian male raised in a small conservative town in Maine by hard-working middle-class parents. My compassionate mother juggled raising three rambunctious children, me being the...