#include<iostream>
#include<string.h>
using namespace std;
class Car
{
private:
char model[20], owner[20] ;
int gearcount, currentgear, currentspeed, maxspeed;
public:
static int k;
/*Car()
{
strcpy(model,"N/S");
strcpy(owner,"N/S");
gearcount = -1;
maxspeed = -1;
currentgear = -1;
currentspeed = -1;
}*/
Car()
{
cout<<"Enter car owner and car model:";
cin>>owner>>model;
cout<<"Enter gear count and max speed:";
cin>>gearcount >>maxspeed;
}
Car(char m[20], char n[20], int gc, int cg, int ms, int cs)
{
setdetails(m,n,gc,cg,ms,cs);
}
void setdetails(char m[20], char n[20], int gc, int cg, int ms, int cs)
{
strcpy(model, m);
strcpy(owner, n);
gearcount = gc;
currentgear = cg;
maxspeed = ms;
currentspeed = cs;
}
void setgear(int cg) ;
void printdetails()
{
cout<<"\nCar Model: "<< model
<<"\nCar Owner: "<< owner
<<"\nCurrent Speed: "<< currentspeed
<<"\nCurrent gear: "<<currentgear
<<"\nK: "<<k;
}
};
int Car::k = 100;
void Car::setgear(int cg)
{
currentgear = cg;
}
int main()
{
Car c1, c2("Alto","Sumit",5,3,110,45);
c2.printdetails();
c1.printdetails();
c1.k=20;
c2.printdetails();
c1.printdetails();
}
#include<string.h>
using namespace std;
class Car
{
private:
char model[20], owner[20] ;
int gearcount, currentgear, currentspeed, maxspeed;
public:
static int k;
/*Car()
{
strcpy(model,"N/S");
strcpy(owner,"N/S");
gearcount = -1;
maxspeed = -1;
currentgear = -1;
currentspeed = -1;
}*/
Car()
{
cout<<"Enter car owner and car model:";
cin>>owner>>model;
cout<<"Enter gear count and max speed:";
cin>>gearcount >>maxspeed;
}
Car(char m[20], char n[20], int gc, int cg, int ms, int cs)
{
setdetails(m,n,gc,cg,ms,cs);
}
void setdetails(char m[20], char n[20], int gc, int cg, int ms, int cs)
{
strcpy(model, m);
strcpy(owner, n);
gearcount = gc;
currentgear = cg;
maxspeed = ms;
currentspeed = cs;
}
void setgear(int cg) ;
void printdetails()
{
cout<<"\nCar Model: "<< model
<<"\nCar Owner: "<< owner
<<"\nCurrent Speed: "<< currentspeed
<<"\nCurrent gear: "<<currentgear
<<"\nK: "<<k;
}
};
int Car::k = 100;
void Car::setgear(int cg)
{
currentgear = cg;
}
int main()
{
Car c1, c2("Alto","Sumit",5,3,110,45);
c2.printdetails();
c1.printdetails();
c1.k=20;
c2.printdetails();
c1.printdetails();
}
car example
Reviewed by Shobhit Goel
on
August 10, 2015
Rating:
No comments:
Post a Comment