Code:
#include<iostream>
#include<cstring>
using namespace std;
ofstream out;
//class vehicle definition
class vehicle
{
private:
//data members declaration
char Mname[5][15];
char Mbrand[5][15];
char Mprice[5][15];
char Mfacname[5][15];
char Mfacdate[5][15];
char Mfachistory[5][15];
char Ebrand[5][15];
char horsepower[5][15];
char Eprice[5][15];
char size[5][15];
char Wbrand[5][15];
char Wprice[5][15];
int Myear,Eyear,Wyear;
public:
//definition of the functions
void model(char newMname[][15],char newMprice[][15],int i)
{
out<<"Name of the model is "<<newMname[i][15]<<"."<<endl;
out<<"Price of the model is Rm "<<newMprice[i][15]<<"."<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////
void model(char newMname[][15],char newMprice[][15],char newMbrand[][15],int i)
{
out<<"Name of the model is "<<newMname[i][15]<<"."<<endl;
out<<"Brand of the model is "<<newMbrand[i][15]<<"."<<endl;
out<<"Price of the model is Rm "<<newMprice[i][15]<<"."<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////
void manufacturer(char newMfacname[][15],char newMfacdate[][15],int i)
{
out<<"The name of the manufacturer is "<<newMfacname[i][15]<<"."<<endl;
out<<"The manufactured date is "<<newMfacdate[i][15]<<"."<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////
void manufacturer(char newMfacname[][15],char newMfacdate[][15],char newMfachistory[][15],int i)
{
out<<"The name of the manufacturer is "<<newMfacname[i][15]<<"."<<endl;
out<<"The manufactured date is "<<newMfacdate[i][15]<<"."<<endl;
out<<"The manufacturer has "<<newMfachistory[i][15]<<" years experience in this field."<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////
void engine(char newEbrand[][15],char newhorsepower[][15],int i)
{
out<<"The brand of the engine is "<<newEbrand[i][15]<<"."<<endl;
out<<"The horsepower of the engine is "<<newhorsepower[i][15]<<" cc."<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////
void engine(char newEbrand[][15],char newhorsepower[][15],char newEprice[][15],int i)
{
out<<"The brand of the engine is "<<newEbrand[i][15]<<"."<<endl;
out<<"The horsepower of the engine is "<<newhorsepower[i][15]<<" cc."<<endl;
out<<"The price of the engine is Rm "<<newEprice[i][15]<<"."<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////
void wheel(char newWbrand[][15],char newWprice[][15],int i)
{
out<<"The brand of the wheel is "<<newWbrand[i][15]<<"."<<endl;
out<<"The price of the wheel is Rm "<<newWprice[i][15]<<"."<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////
void wheel(char newsize[][15],char newWbrand[][15],char newWprice[][15],int i)
{
out<<"The size of the wheel is "<<newsize[i][15]<<" inches."<<endl;
out<<"The brand of the wheel is "<<newWbrand[i][15]<<"."<<endl;
out<<"The price of the wheel is Rm "<<newWprice[i][15]<<"."<<endl;
};
///////////////////////////////////////////////////////////////////////////////////////
void input()//function to input and store string into array accordingly
{
for(int i=0;i<5;i++)
{
cout<<"_________________________________________________________"<<endl;
cout<<" Enter the details of the vehicle no. "<<i+1<<endl;
cout<<"---------------------------------------------------------"<<endl;
cout<<"Please enter vehicle model: ";
fflush(stdin);
cin.getline(Mname[i],15);
cout<<"Please enter the brand of the vehicle: ";
cin.getline(Mbrand[i],15);
cout<<"Please enter the price of the model: ";
cin.getline(Mprice[i],15);
cout<<"Please enter the name of the manufacturer: ";
cin.getline(Mfacname[i],15);
cout<<"Please enter the date of the vehicle manufactured: ";
cin.getline(Mfacdate[i],15);
cout<<"Please enter the experience of the manufacturer: ";
cin.getline(Mfachistory[i],15);
cout<<"Please enter the brand of the engine: ";
cin.getline(Ebrand[i],15);
cout<<"Please enter the horsepower of the engine: ";
cin.getline(horsepower[i],15);
cout<<"Please enter the price of the engine: ";
cin.getline(Eprice[i],15);
cout<<"Please enter the wheel size: ";
cin.getline(size[i],15);
cout<<"Please enter the brand of the wheel: ";
cin.getline(Wbrand[i],15);
cout<<"Please enter the price of the wheel: ";
cin.getline(Wprice[i],15);
cout<<endl;
system("cls");
};
}
/////////////////////////////////////////////////////////////////////////////////////////
void output()//function to print out string stored in the array accordingly
{
int option;
do
{
cout<<"============================================================="<<endl;
cout<<"Choose 1 option to show the details of the vehicle from below"<<endl;
cout<<"============================================================="<<endl;
cout<<"(1)name and price of the model,"<<endl;
cout<<" name and the manufactured date,"<<endl;
cout<<" brand and horsepower of the engine,"<<endl;
cout<<" brand and price of the wheel."<<endl;
cout<<"(2)name,brand and price of the model,"<<endl;
cout<<" name,the manufactured date and manufacturer experience,"<<endl;
cout<<" brand,horsepower and price of the engine,"<<endl;
cout<<" size,brand and price of the wheel."<<endl;
cout<<"(3)name,brand and price of the model,"<<endl;
cout<<" name and the manufactured date,"<<endl;
cout<<" brand,horsepower and price of the engine,"<<endl;
cout<<" brand and price of the wheel."<<endl;
cout<<"Option has been selected is ";
cin>>option;
cout<<endl;
switch(option)
{
case 1:for(int i=0;i<5;i++)
{
out<<"________________________________________________"<<endl;
out<<" Details of vehicle no."<<i+1<<" as below:"<<endl;
out<<"------------------------------------------------"<<endl;
model(Mname,Mprice,i);
manufacturer(Mfacname,Mfacdate,i);
engine(Ebrand,horsepower,i);
wheel(Wbrand,Wprice,i);
out<<endl;
};
break;
case 2:for(int i=0;i<5;i++)
{
out<<"________________________________________________"<<endl;
out<<" Details of vehicle no."<<i+1<<" as below:"<<endl;
out<<"------------------------------------------------"<<endl;
model(Mname,Mprice,Mbrand,i);
manufacturer(Mfacname,Mfacdate,Mfachistory,i);
engine(Ebrand,horsepower,Eprice,i);
wheel(size,Wbrand,Wprice,i);
out<<endl;
};
break;
case 3:for(int i=0;i<5;i++)
{
out<<"________________________________________________"<<endl;
out<<" Details of vehicle no."<<i+1<<" as below:"<<endl;
out<<"------------------------------------------------"<<endl;
model(Mname,Mprice,Mbrand,i);
manufacturer(Mfacname,Mfacdate,i);
engine(Ebrand,horsepower,Eprice,i);
wheel(Wbrand,Wprice,i);
out<<endl;
};
break;
default:cout<<"Invalid option."<<endl;
cout<<"Please choose an option again."<<endl;
break;
}
system("cls");
}while(option!=1&&option!=2&&option!=3);
}
///////////////////////////////////////////////////////////////////////
void check_model(int year)
{
if(year<1980)
out<<"This model is extremely outdated and can be assumed that it is not exist anymore."<<endl;
if(year>1980&&year<2001)
out<<"This model is very old."<<endl;
if(year>2000&&year<2009)
out<<"This model is new and can be seen everywhere."<<endl;
if(year>2008)
out<<"This car not yet exist."<<endl;
}
////////////////////////////////////////////////////////////////////////
void check_engine (int year)
{
if(year>1995&&year<2009)
out<<"The car is safe to drive on road."<<endl;
else if(year>1900&&year<1996)
out<<"This car may have many problem and unlawful to drive it on road."<<endl;
else
out<<"The year of manufacturing is not valid. Please check your engine again."<<endl;
}
/////////////////////////////////////////////////////////////////////////
void check_wheel(int year)
{
if(year<1995)
out<<"The wheel should be changed as it might be broken anytime."<<endl;
if(year>1995&&year<2009)
out<<"The wheel is in good condition and it is safe for driving long distance."<<endl;
if(year>2009)
out<<"The wheel not yet exist."<<endl;
}
/////////////////////////////////////////////////////////////////////////
void checking_vehicle()
{
cout<<"*********************************************************"<<endl;
cout<<" CHECKING THE VEHICLE CONDITION "<<endl;
cout<<"*********************************************************"<<endl;
for(int i=1;i<=5;i++)
{
out<<"#############"<<endl;
out<<"VEHICLE NO. "<<i<<" "<<endl;
out<<"#############"<<endl;
cout<<"Please enter the year of the model of vehicle no. "<<i<<" :";
cin>>Myear;
check_model(Myear);
out<<endl;
cout<<"Please enter the year of the engine of vehicle no. "<<i<<" :";
cin>>Eyear;
check_engine(Eyear);
out<<endl;
cout<<"Please enter the year of the wheel of the vehicle no. "<<i<<" :";
cin>>Wyear;
check_wheel(Wyear);
out<<endl;
cout<<endl;
system("cls");
};
}
};
#include<iostream>
#include<cstring>
#include<fstream>
#include"vehicle.h"
//function for input and output
using namespace std;
int main()
{
int x;
char Z;
vehicle car;//create object car
vehicle motobike;//create object motobike
out.open("output.txt");
do
{
cout<<"====================================================="<<endl;
cout<<"Details of 5 different cars and 5 different motobikes"<<endl;
cout<<"====================================================="<<endl;
do
{
cout<<"Choose 1 option from below:"<<endl;
cout<<"(1)car"<<endl;
cout<<"(2)motobike"<<endl;
cout<<"(3)quit"<<endl;
cout<<endl;
cout<<"Option chose by the user is ";
cin>>x;
cout<<endl;
switch(x)
{
case 1:cout<<"Key-in the inputs for 5 different cars as below:"<<endl;
car.input();
car.output();
car.checking_vehicle();
break;
case 2:cout<<"Key-in the inputs for 5 different motobikes as below:"<<endl;
motobike.input();
motobike.output();
motobike.checking_vehicle();
break;
case 3:return 0;
default:cout<<"Invalid option."<<endl;
cout<<"Please choose an option again."<<endl;
cout<<endl;
break;
}
}while(x!=1&&x!=2&&x!=3);
cout<<"Press Y or y to continue: ";
cin>>Z;
system("cls");
}while(Z=='Y'||Z=='y');//ask users permission whether to continue the program
system("pause");
return 0;
}