PROGRAM 9: Create a database regarding its indoor patients.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
struct DATE
{
int date;
int month;
int year;
};
class patient
{
protected:
char name[40];
DATE admit;
char disease[40];
DATE discharge;
public:
void enter()
{
char c;
int i;
cout<<"Enter information:"<<endl;
cout<<"Name:";
for(i=0;i<=38;i++)
{
cin>>c;
if(c=='\r')
break;
else
name[i]=c;
}
name[i]='\0';
//[Link](name,40);
//[Link](100,'\n');
cout<<"Date of admission:"<<endl;
cout<<" Date:";
cin>>[Link];
cout<<" Month:";
cin>>[Link];
cout<<" Year:";
cin>>[Link];
//[Link](100,'\n');
cout<<"Disease:";
for(i=0;i<=38;i++)
{
cin>>c;
if(c=='\r')
break; else
disease[i]=c;
}
disease[i]='\0';
//[Link](disease,40);
//[Link](100,'\n');
cout<<"Date of discharge:"<<endl;
cout<<" Date:";
cin>>[Link];
cout<<" Month:";
cin>>[Link];
cout<<" Year:";
cin>>[Link];
}
void display()
{
cout<<setw(14);
[Link](ios::left);
cout<<name<<setw(12);
[Link](ios::left);
cout<<[Link]<<'-'<<[Link]<<'-'<<[Link];
cout<<setw(17);
cout<<disease<<setw(13);
cout<<[Link]<<'-'<<[Link]<<'-'<<[Link];
}
};
class pat_age:public patient
{
int age;
public:
int get_age()
{
return age;
}
void enter()
{
patient::enter();
cout<<"Age:";
cin>>age;
}
void display()
{ patient::display();
cout<<setw(6)<<age;
}
};
PROGRAM 10: Find the total no of cars.
include<iostream.h>
#include<conio.h>
const char ESC=27;
const double TOLL=0.5;
class tollbooth
{
private:
unsigned int totalcars;
double totalcash;
public:
tollbooth()
{ totalcars=0;
totalcash=0;
}
void payingcar()
{ totalcars+=1;
totalcash+=TOLL;
}
void nopaycar()
{
totalcars+=1;
}
void display()
{
cout<<"\ncars="<<totalcars<<",cash="<<totalcash;
}
};
int main()
{
tollbooth booth1;
char ch;
clrscr();
cout<<"\npress 0 for each non-paying car,"
<<"\n 1 for each paying car,"
<<"\n Esc to exit the program.\n";
do
{ ch=getche()
; if(ch=='0')
[Link]();
if(ch=='1')
[Link]();
}while(ch!=ESC);
[Link]();
getch();
return 0;
}
OUTPUT:
press 0 for each non-paying car,
1 for each paying car, Esc
to exit the program.
←222
cars=1,cash=0.5
PROGRAM 11: Write a Program to reverse a string
#include<iostream.h>
#include<conio.h>
#include<string.h>
const int MAX=80;
void reversit(char[]);
int main()
{
char str[MAX];
clrscr();
cout<<"\nenter the string:";
[Link](str,MAX);
reversit(str); cout<<"reversed
string is:"; cout<<str;
getch();
return 0;
}
void reversit(char s[])
{
int len=strlen(s);
for(int j=0;j<len/2;j++)
{
char temp=s[j];
s[j]=s[len-j-1];
s[len-j-1]=temp;
}
}
OUTPUT:
enter the string:sdhgd
reversed string is:dghds
PROGRAM 12: Create a base class called shape. Use this class to store two double type
values that could
#include<iostream.h>
#include<conio.h>
class shape
{ protected
: double x;
double y;
public:
shape()
{ x=0.
0;
y=0.0;
}
shape(double a,double b)
{ x=
a;
y=b;
}
void get_data()
{
cout<<"enter x:";
cin>>x;
cout<<"enter y:";
cin>>y;
}
virtual void display_area()=0;
};
class triangle:public shape
{ public:
triangle()
{}
triangle(double a,double b):shape(a,b)
{}
void display_area()
{
cout<<"Area of triangle:"<<(x*y)/2;
}
};
class rectangle:public shape
{
public:
rectangle()
{}
rectangle(double a,double b):shape(a,b)
{}
void display_area()
{
cout<<"Area of rectangle:"<<x*y;
}
};
int main()
{
int c;
clrscr();
while(1)
{
cout<<"\[Link] of triangle";
cout<<"\[Link] of rectangle";
cout<<"\[Link]"; cout<<"\nenter
your choice:"; cin>>c;
switch(c)
{
case 1:triangle t;
t.get_data();
t.display_area();
break;
case 2:rectangle r;
r.get_data();
r.display_area();
break;
case 3:return 0;
default:cout<<"invalid choice";
}
}
}
OUTPUT:
[Link] of triangle
[Link] of rectangle
[Link]
enter your choice:2
enter x:2
enter y:5
Area of rectangle:10
[Link] of triangle
[Link] of rectangle
[Link]
enter your choice:3
.
PROGRAM 13: . Create some objects of the string class, and put them in a Deque-some at the
head of the. Deque and some at the tail.
#include<iostream.h>
#include<conio.h>
#include<strng.h>
#include<deque.h>
void actionfunc(Object&,void*);
int testfunc(const Object& obj,void*);
int main()
{
Deque deq;
String s1("Rajtilak");
String s2("Deepak");
String s3("Lakshay");
String s4("Rishi");
String s5("Amit");
clrscr();
[Link](s1);
[Link](s2);
[Link](s3);
[Link](s4);
[Link](s5);
cout<<"\n\nIterate through deque:";
[Link](actionfunc,0);
String& temp=(String&)[Link](testfunc,0);
if(temp!=NOOBJECT)
{
cout<<"\n\nMatch with:";
[Link](cout);
}
else
cout<<"\n\nNo match.";
cout<<"\n\nDisplay and remove items from deque:";
while(![Link]())
{
String& temp=(String&)[Link]();
cout<<endl;
[Link](cout);
}
cout<<"\nContents of empty deque:";
[Link](cout);
getch();
return 0;
}
void actionfunc(Object& obj,void*)
{ cout<<endl;
[Link](cout);
}
int testfunc(const Object& obj,void*)
{
String& temp=(String&)obj;
String test("Deepak");
if([Link](test))
return 1;
else
return 0;
}
PROGRAM 14: . Make a class Employee with a name and salary
#include<iostream.h>
#include<conio.h>
#include<strng.h>
class employee
{
protected:
char name[40];
unsigned int salary;
};
class manager:public employee
{
String department;
public:
manager(char n[],unsigned int s,String d)
{ strcpy(name,n);
salary=s;
department=d;
}
void tostring()
{
cout<<"Name:"<<name<<endl<<"Deptt:"<<department<<endl<<"Salary:"<<"Rs."
<<salary<<endl;
}
};
class executive:public manager
{
public:
executive(char n[],unsigned int s,String d):manager(n,s,d)
{
}
void tostring()
{
String s("Executive");
[Link](cout);
cout<<endl;
manager::tostring();
}
};
int main()
{
String d1("Information Technology");
String d2("Mechanical");
manager m("Rajtilak Bhatt",15000,d1);
executive e("Deepak Bhatt",21000,d2);
clrscr();
cout<<"\n\n*****************************CALL BY MANAGER
OBJECT*************\
****************\n\n";
[Link]();
cout<<"\n\n******************CALL BY EXECUTIVE OBJECT DERIVED FROM
MANAGER*\
****************\n\n"; [Link]();
cout<<"\n\n=======================================================
=========\
================";
getch();
return 0;
}