Monday, November 7, 2011

Manage Car model Using C++


Using this program you can have basic knowledge of Constructor, enum, basic class construction, meber function details.

#include<iostream.h>
 #include<conio.h>
 enum COLOR{red,blue,green,black,white};
 typedef char * String;
 class car
 {
private:
COLOR color;
float price;
String company;
public:
car();
car(COLOR,float,String);
void showvalue() const;
 };
 car::car():
color(white),
price(0.0),
company("")
{}
 car::car(COLOR c,float p,String com)
 {
this->color=c;
this->price=p;
company=com;
 }
 void car::showvalue() const
 {
cout<<"This "<<color<<" of "
<<company<<" is for "<<price<<" Rs."<<endl;
 }
 class complex
 {
private:
int real;
int com;
public:
complex(int,int);
complex();
void showvalue() const;
//void operator++ ();
complex operator++ ();
complex operator++ (int);
complex operator+(const complex c);
 };
 complex::complex():
real(0),com(0){}
 void complex::showvalue() const
 {
cout<<real<<"+"<<com<<"i"<<endl;
 }
 complex::complex(int a,int b):
real(a),com(b){}
 complex complex::operator++()
 {
complex c(0,0);
real++;
c.real=real;
return c;
 }
 complex complex::operator+(const complex c)
 {
complex a;
a.real=real+c.real;
a.com=com+c.com;
return a;
 }
 complex complex::operator++(int)
 {
complex c;
c=*this;
real++;
return c;
 }
 void main()
 {
complex c1(1,2),c2(2,3);
clrscr();
c1.showvalue();
++c1;
c1.showvalue();
complex c3=c1++;
c3.showvalue();
c1.showvalue();
complex c4;
c4=c1+c2;
cout<<endl<<endl;
c1.showvalue();
c2.showvalue();
c4.showvalue();
getch();
 }

0 comments:

Post a Comment

You are most welcome for making comments here. I will consider your view and will reply you soon.