Q4: Create a Car class. Identify the attributes and functions of the class (with respect to driver and not engineer)
For Example:
Attribute: No. of Seats
Function: accelerate() or startCar()
#include <iostream>
using namespace std;
class Car{
public:
int seats;
char model[20];
void getDetails(){
cout<<"Enter car model: \n";
cin>>model;
cout<<"Enter number of seats: \n";
cin>>seats;
}
void dispalyDetails(){
cout<<"\nmodel\tseats";
cout<<"\n"<<model<<"\t"<<seats<<endl;
}
void startcar(){
cout<<"Car is on\n"<<endl;
}
void accelerate(){
cout<<"the car is accelerating\n"<<endl;
}
};
int main()
{
Car c;
c.getDetails();
c.dispalyDetails();
c.startcar();
c.accelerate();
return 0;
}
Comments
Leave a comment