templates and exception handling

+4 Jaque Ressel · December 9, 2014
code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
class monthlybook;
class tour
{
protected:
int fkm;
char start[20];
char stop[30];
unsigned int fcharge;
int ekm;
unsigned int total;
public :
       virtual void display()
{

}
};


class monthlybook :public tour
{
protected :
int nomonth;
public:
void setdata()
{
cout<<"\nenter number of month you want to book a cab\n";
cin>>nomonth;

cout<<"\nenter tour start location\n";
cin>>start;

cout<<"\nenter tour end location\n";
cin>>stop;

fkm = 2000;
fcharge = 10000*nomonth;
}
void setextra()
{
cout<<"\nenter extra km\n";
cin>>ekm;
}
void settotal()
{
total = fcharge + ekm*7;
}
void display();

};
void monthlybook::display()
{
cout<<"\ntour from "<<start<<" to "<<stop;
cout<<"\ncab used for = "<<nomonth<<" months";
cout<<"\nTotal fixed km = "<<fkm;
cout<<"\nTotal fixed charge = "<<fcharge;
cout<<"\nTotal extra km = "<<ekm;
cout<<"\nTotal cost = "<<total;
}
class dailybook : public tour
{
protected :

int nodays;
public:
void setdata()
{
cout<<"\nenter number of days you want to book a cab\n";
cin>>nodays;

cout<<"\nenter tour start location\n";
cin>>start;

cout<<"\nenter tour end location\n";
cin>>stop;

fkm = 200;
fcharge = 500*nodays;
}
void setextra()
{
cout<<"\nenter extra km\n";
cin>>ekm;
}
void settotal()
{
total = fcharge + ekm*7;
}
void display();
};
void  dailybook::display()
{
cout<<"\ntour from "<<start<<" to "<<stop;
cout<<"\ncab used for = "<<nodays<<" days";
cout<<"\nTotal fixed km = "<<fkm;
cout<<"\nTotal fixed charge = "<<fcharge;
cout<<"\nTotal extra km = "<<ekm;
cout<<"\nTotal cost = "<<total;
}

  monthlybook m1;
  dailybook d1;


class customer
{
protected :
int cid;
public :
void getcid(int a)
{
cid = a;
}
void putcid()
{
cout<<"\ncustomer id = "<<cid;
}
};

class userinfo : virtual public customer
{
protected:
char customername[30];
long int phone;
int age;
char address[40];
public :
void setinfo()
{

cout<<"\nenter customer name\n";
cin>>customername;

cout<<"\nenter customer phone number\n";
cin>>phone;

cout<<"\nenter customer age\n";
cin>>age;

cout<<"\nenter customer address\n";
cin>>address;
}
void showdata()
{


cout<<"\n customer name = "<<customername;
cout<<"\n customer phone number = "<<phone;
cout<<"\n customer age = "<<age;
cout<<"\nenter customer address = "<<address;
}
char * getname()
{
return customername;
}
};
class booktype : virtual public customer
{
protected:
tour *tr;
int ch;
public :

void setchoice()
{

cout<<"\nenter 1 for monthly cab 2 for daily bab\n";
cin>>ch;

if(ch==1)
{
m1.setdata();
m1.setextra();
m1.settotal();
tr = &m1;

}
else
{

d1.setdata();
d1.setextra();
d1.settotal();
tr = &d1;

}

}


void show()
{


tr->display();
}
};





class booking : public userinfo,public booktype
{
int bid;
public:
void setdetail()
{
setinfo();
setchoice();
}
void getdetail()
{
showdata();

show();
}
};



void main()
{
clrscr();
try
{
booking b1;
b1.setdetail();
b1.getdetail();
if()
throw "Feilds can't be null";
}
catch(const char* Message)
{
cout<<"Error:"<<Message<<endl;
}
getch();

}








class car;
class regno
{
       int  rnum;
       public:
regno()
{}
      regno(int a)
      {
rnum=a;

}
      int getregno()
      {
      return rnum;
      }
};
class engine
{
int eno;
regno * reg;
car * ca;
public:
engine()
{}
engine(int a,regno *g,car *c)
{
ca=c;
eno=a;
reg=g;
}
int geteno()
{
return eno;
}
int getreg()
{
return reg->getregno();
}
};
class car
{
char cnum[30];
int sold;
int book;
engine * eng;
public:
car()
{}
car(char a[],int b,int c,int d)
{
   regno * r;
strcpy(cnum,a);
sold=d;
book=0;
r=new regno(c);
eng=new engine(b,r,this);
}
char * getcnum()
{
return cnum;
}
int geteng()
{
return eng->geteno();
}
int getregis()
{
return eng->getreg();
}
int getsold()
{
return sold;
}
void show()
{
cout<<"\nCar number = "<<cnum;
cout<<"\nCar engine number = "<<eng->geteno();
cout<<"\nCar Registration number = "<<eng->getreg();
if(book==0)
cout<<"\nCab is available \n";
else
cout<<"\ncab is on rent\n";

}

};
class cabprovider
{
char name[20];
car * carlist[10];
int index;
public:
       cabprovider()
       {}
       cabprovider(char a[])
       {
strcpy(name,a);
index=0;
       }
       void  addcar()
       {
car * c1;
       int b,c,d;
       char a[30];
 cout<<"\nenter car number\n";
 cin>>a;

 cout<<"\nenter engine number\n";
 cin>>b;

 cout<<"\nenter registration number\n";
 cin>>c;

 cout<<"\nenter no of times car is sold\n";
 cin>>d;

 c1=new car(a,b,c,d);

if(index<10)
{
 carlist[index]=c1;
 index++;
 }
else
{
cout<<"\nNew Car can not be added\n";
}
       }
void display()
{
int i;
for(i=0;i<index;i++)
{
carlist->show();
}
}


int getindex()
{
return index;
}
       void find();

};
void cabprovider:: find()
       {
int i,j=0,k;
for(i=0;i<index;i++)
{
      if(j<carlist->getsold())
      {
j=carlist->getsold();
k=i;
      }
}
 cout<<"\nRegistration = "<<carlist[k]->getregis();
       }


class admin
{
cabprovider c;
booking b[10];
int carc;
int bookc;
admin()
{
char pass[]="1234";
char a[30];
cout<<"\nenter cab provider name\n";
cin>>a;
c=cabprovider(a);






void main()
{
       cabprovider  cab;
       car * c1;
       int i,j,a,b,c,d;
       char n[20];
       clrscr();
       cout<<"\nenter the name of cab provider\n";
       cin>>n;
       cab = cabprovider(n);

      cout<<"\nenter number of car \n";
      cin>>i;

      for(j=0;j<i;j++)
      {
 cab.addcar();
      }

      cab.find();
getch();
}

Post a Reply

Replies

Oldest  Newest  Rating
+3 Jaque Ressel · December 9, 2014
can anybody suggest templates for the above code....
0 Homer Simpson · December 10, 2014
@kayler lmfao!! That was priceless! :)
+2 Jaque Ressel · December 10, 2014
@Kayler I have written the whole code by myself and highlighted the the error by bold letter ......
so, now can you help me in that.....
And I understand that people are not free to do others homework .....   and I never asked to do so......
0 Daniel Collier · December 10, 2014

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
class monthlybook;
class tour
{
protected:
int fkm;
char start[20];
char stop[30];
unsigned int fcharge;
int ekm;
unsigned int total;
public :
virtual void display()
{

}
};


class monthlybook :public tour
{
protected :
int nomonth;
public:
void setdata()
{
cout<<"\nenter number of month you want to book a cab\n";
cin>>nomonth;

cout<<"\nenter tour start location\n";
cin>>start;

cout<<"\nenter tour end location\n";
cin>>stop;

fkm = 2000;
fcharge = 10000*nomonth;
}
void setextra()
{
cout<<"\nenter extra km\n";
cin>>ekm;
}
void settotal()
{
total = fcharge + ekm*7;
}
void display();

};
void monthlybook::display()
{
cout<<"\ntour from "<<start<<" to "<<stop;
cout<<"\ncab used for = "<<nomonth<<" months";
cout<<"\nTotal fixed km = "<<fkm;
cout<<"\nTotal fixed charge = "<<fcharge;
cout<<"\nTotal extra km = "<<ekm;
cout<<"\nTotal cost = "<<total;
}
class dailybook : public tour
{
protected :

int nodays;
public:
void setdata()
{
cout<<"\nenter number of days you want to book a cab\n";
cin>>nodays;

cout<<"\nenter tour start location\n";
cin>>start;

cout<<"\nenter tour end location\n";
cin>>stop;

fkm = 200;
fcharge = 500*nodays;
}
void setextra()
{
cout<<"\nenter extra km\n";
cin>>ekm;
}
void settotal()
{
total = fcharge + ekm*7;
}
void display();
};
void dailybook::display()
{
cout<<"\ntour from "<<start<<" to "<<stop;
cout<<"\ncab used for = "<<nodays<<" days";
cout<<"\nTotal fixed km = "<<fkm;
cout<<"\nTotal fixed charge = "<<fcharge;
cout<<"\nTotal extra km = "<<ekm;
cout<<"\nTotal cost = "<<total;
}

monthlybook m1;
dailybook d1;


class customer
{
protected :
int cid;
public :
void getcid(int a)
{
cid = a;
}
void putcid()
{
cout<<"\ncustomer id = "<<cid;
}
};

class userinfo : virtual public customer
{
protected:
char customername[30];
long int phone;
int age;
char address[40];
public :
void setinfo()
{

cout<<"\nenter customer name\n";
cin>>customername;

cout<<"\nenter customer phone number\n";
cin>>phone;

cout<<"\nenter customer age\n";
cin>>age;

cout<<"\nenter customer address\n";
cin>>address;
}
void showdata()
{


cout<<"\n customer name = "<<customername;
cout<<"\n customer phone number = "<<phone;
cout<<"\n customer age = "<<age;
cout<<"\nenter customer address = "<<address;
}
char * getname()
{
return customername;
}
};
class booktype : virtual public customer
{
protected:
tour *tr;
int ch;
public :

void setchoice()
{

cout<<"\nenter 1 for monthly cab 2 for daily bab\n";
cin>>ch;

if(ch==1)
{
m1.setdata();
m1.setextra();
m1.settotal();
tr = &m1;

}
else
{

d1.setdata();
d1.setextra();
d1.settotal();
tr = &d1;

}

}


void show()
{


tr->display();
}
};





class booking : public userinfo,public booktype
{
int bid;
public:
void setdetail()
{
setinfo();
setchoice();
}
void getdetail()
{
showdata();

show();
}
};



void main()
{
clrscr();
try
{
booking b1;
b1.setdetail();
b1.getdetail();
if()
throw "Feilds can't be null";
}
catch(const char* Message)
{
cout<<"Error:"<<Message<<endl;
}
getch();

}







class car;
class regno
{
int rnum;
public:
regno()
{}
regno(int a)
{
rnum=a;

}
int getregno()
{
return rnum;
}
};
class engine
{
int eno;
regno * reg;
car * ca;
public:
engine()
{}
engine(int a,regno *g,car *c)
{
ca=c;
eno=a;
reg=g;
}
int geteno()
{
return eno;
}
int getreg()
{
return reg->getregno();
}
};
class car
{
char cnum[30];
int sold;
int book;
engine * eng;
public:
car()
{}
car(char a[],int b,int c,int d)
{
regno * r;
strcpy(cnum,a);
sold=d;
book=0;
r=new regno(c);
eng=new engine(b,r,this);
}
char * getcnum()
{
return cnum;
}
int geteng()
{
return eng->geteno();
}
int getregis()
{
return eng->getreg();
}
int getsold()
{
return sold;
}
void show()
{
cout<<"\nCar number = "<<cnum;
cout<<"\nCar engine number = "<<eng->geteno();
cout<<"\nCar Registration number = "<<eng->getreg();
if(book==0)
cout<<"\nCab is available \n";
else
cout<<"\ncab is on rent\n";

}

};
class cabprovider
{
char name[20];
car * carlist[10];
int index;
public:
cabprovider()
{}
cabprovider(char a[])
{
strcpy(name,a);
index=0;
}
void addcar()
{
car * c1;
int b,c,d;
char a[30];
cout<<"\nenter car number\n";
cin>>a;

cout<<"\nenter engine number\n";
cin>>b;

cout<<"\nenter registration number\n";
cin>>c;

cout<<"\nenter no of times car is sold\n";
cin>>d;

c1=new car(a,b,c,d);

if(index<10)
{
carlist[index]=c1;
index++;
}
else
{
cout<<"\nNew Car can not be added\n";
}
}
void display()
{
int i;
for(i=0;i<index;i++)
{
carlist->show();
}
}


int getindex()
{
return index;
}
void find();

};
void cabprovider:: find()
{
int i,j=0,k;
for(i=0;i<index;i++)
{
if(j<carlist->getsold())
{
j=carlist->getsold();
k=i;
}
}
cout<<"\nRegistration = "<<carlist[k]->getregis();
}


class admin
{
cabprovider c;
booking b[10];
int carc;
int bookc;
admin()
{
char pass[]="1234";
char a[30];
cout<<"\nenter cab provider name\n";
cin>>a;
c=cabprovider(a);






void main()
{
cabprovider cab;
car * c1;
int i,j,a,b,c,d;
char n[20];
clrscr();
cout<<"\nenter the name of cab provider\n";
cin>>n;
cab = cabprovider(n);

cout<<"\nenter number of car \n";
cin>>i;

for(j=0;j<i;j++)
{
cab.addcar();
}

cab.find();
getch();
}

please use code tags
  • 1

C++

103,638 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator