Project 3
To : Abhinaya mam
Ans:
Here, first i created the class for vehicle, in that i initialises the variable like make , model, type, and some enum type for type of vehicels , year and odometer reading.
then i created functions to get values and set values with the virtual type.
here i choose virtual because i have almost 8 sub-functions to print. and these functions are not dependent on each other and i want to get the output.
Then i expand the functions outside the class, using scope resolution operator.
here, they mentioned in the question that, if odometer reaches 50000km, tire rotaion needs to be done, so i use if conndition inside the putodometer(), it will check whetehr tire rotation needs to be done or not.
Then menu dispaly(), inside it i printed 3 menues,where i can choose them using switch case.
next is display services(), in that i printed the services offered.
next in the main program, i initialise a variable names userchoice, then i use the keyword beginning, in that i give menudisplay, this is because, for everytime, when a menu in the display, i.e., a task completed
i wanted to print menudisplay(). for that i use goto keyword, so wherever i use goto beginnning keyword, menudisply will appear.
next i ask for custome choice, for that i use switch case,
for case o: it will quit the program
for case 1: it will display the program
for case 2: in this we add the vehicle.
since we use virtual funnctions, we can use pointers easily using new operator,
we can allocate the memory, and call the value along with address in one go.
then we created pointer variable for class, i.e., vehicle *pv = new vehicle.... here with the help of new we allocate the memory.
then then by using pointer pv-> we call the functions setmake(), putmake()etc, then go to beginning.
this is the continuous program until we quit the program.
Code:
#include
using namespace std;
#define size 2
#define MAXKM 50000
class vehicle
{
public:
string make, model, type;
enum TYPE
{ GAS, ELECTRIC, DIESEL };
int year;
float odometer;
virtual void setmake ();
virtual void putmake ();
virtual void setmodel ();
virtual void putmodel ();
virtual void setyear ();
virtual void putyear ();
virtual void setodometer ();
virtual void putodometer ();
};
void vehicle::setmake ()
{
cout << "Enter make of the vehicle" << endl>
cin >> make;
}
void vehicle::putmake ()
{
cout << "\t" << make>
}
void vehicle::setmodel ()
{
cout << "\n Enter model of the vehicle" << endl>
cin >> model;
}
void vehicle::putmodel ()
{
cout << "\t" << model>
}
void vehicle::setyear ()
{
cout << "\n Enter manufactured year of the vehicle" << endl>
cin >> year;
}
void vehicle::putyear ()
{
cout << "\t" << year>
}
void vehicle::setodometer ()
{
cout << "\n Enter the Odometer Reading" << endl>
cin >> odometer;
}
void vehicle::putodometer ()
{
cout << "\t" << odometer>
if (odometer >= MAXKM)
cout << "\n Tyre Rotation to be done " << endl>
else
cout <<
" \n Less than 50000 KMS -Tyre rotation can be done in next visit." <<
endl;
}
void menudisplay ()
{
cout << " 0. Quit.\n";
cout << " 1. displayservices.\n";
cout << " 2. Add vehicle.\n";
}
void displayservices ()
{
cout << "\n oil change or replace oil filter, replace air filter" << endl>
cout << "replace fuel filter, tire rotations, infotainment debug" << endl>
cout << "replace spark plugs, replace the cabin filter, check the level" < cout << " refill clutch fluid" << endl>
cout << "brake fluid, examine belts, wipers, hoses" << endl>
cout << "check the tire conditions, check the charging systems, battery" < } int main () { int user_choice; beginning:menudisplay (); cout << "Enter your choice in no" << endl>
cin >> user_choice; switch (user_choice) { case 0: cout << "Exiting the program "; break; case 1: displayservices (); goto beginning; case 2: vehicle * pv = new vehicle (); pv->setmake (); pv->setmodel (); pv->setyear (); pv->setodometer (); pv->putmake (); pv->putmodel (); pv->putyear (); pv->putodometer (); goto beginning; } } Result: