0% found this document useful (0 votes)
134 views

Program 9: Create A Database Regarding Its Indoor Patients

The document describes creating classes to model employees in a company. An Employee class is created with name and salary attributes. A Manager class inherits from Employee and adds a department attribute. An Executive class inherits from Manager without adding new attributes. Objects of the Manager and Executive classes are created and their toString methods called to display employee details.

Uploaded by

Neeraj Falwariya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Program 9: Create A Database Regarding Its Indoor Patients

The document describes creating classes to model employees in a company. An Employee class is created with name and salary attributes. A Manager class inherits from Employee and adds a department attribute. An Executive class inherits from Manager without adding new attributes. Objects of the Manager and Executive classes are created and their toString methods called to display employee details.

Uploaded by

Neeraj Falwariya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

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';
//cin.getline(name,40);
//cin.ignore(100,'\n');
cout<<"Date of admission:"<<endl;
cout<<" Date:";
cin>>admit.date;
cout<<" Month:";
cin>>admit.month;
cout<<" Year:";
cin>>admit.year;
//cin.ignore(100,'\n');
cout<<"Disease:";
for(i=0;i<=38;i++)
{
cin>>c;
if(c=='\r')
break; else
disease[i]=c;
}
disease[i]='\0';
//cin.getline(disease,40);
//cin.ignore(100,'\n');
cout<<"Date of discharge:"<<endl;
cout<<" Date:";
cin>>discharge.date;
cout<<" Month:";
cin>>discharge.month;
cout<<" Year:";
cin>>discharge.year;
}
void display()
{
cout<<setw(14);
cout.setf(ios::left);
cout<<name<<setw(12);
cout.unsetf(ios::left);
cout<<admit.date<<'-'<<admit.month<<'-'<<admit.year;
cout<<setw(17);
cout<<disease<<setw(13);
cout<<discharge.date<<'-'<<discharge.month<<'-'<<discharge.year;
}
};
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')
booth1.nopaycar();
if(ch=='1')
booth1.payingcar();
}while(ch!=ESC);
booth1.display();
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:";
cin.get(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<<"\n1.area of triangle";
cout<<"\n2.area of rectangle";
cout<<"\n3.exit"; 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:

1.area of triangle
2.area of rectangle
3.exit
enter your choice:2
enter x:2
enter y:5
Area of rectangle:10
1.area of triangle
2.area of rectangle
3.exit
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();
deq.putLeft(s1);
deq.putLeft(s2);
deq.putLeft(s3);
deq.putRight(s4);
deq.putRight(s5);
cout<<"\n\nIterate through deque:";
deq.forEach(actionfunc,0);
String& temp=(String&)deq.firstThat(testfunc,0);
if(temp!=NOOBJECT)
{
cout<<"\n\nMatch with:";
temp.printOn(cout);
}
else
cout<<"\n\nNo match.";
cout<<"\n\nDisplay and remove items from deque:";
while(!deq.isEmpty())
{
String& temp=(String&)deq.getLeft();
cout<<endl;
temp.printOn(cout);
}
cout<<"\nContents of empty deque:";
deq.printOn(cout);
getch();
return 0;
}
void actionfunc(Object& obj,void*)
{ cout<<endl;
obj.printOn(cout);
}
int testfunc(const Object& obj,void*)
{
String& temp=(String&)obj;
String test("Deepak");
if(temp.isEqual(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");
s.printOn(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";
m.tostring();
cout<<"\n\n******************CALL BY EXECUTIVE OBJECT DERIVED FROM
MANAGER*\
****************\n\n"; e.tostring();
cout<<"\n\n=======================================================
=========\
================";
getch();
return 0;
}

You might also like