Wednesday, December 17, 2014

C++ using Hierarchical Program



Hierarchical

#include
#include
class person
{
char name[12];
int age;
public:
void getperson()
{
cout<<"\n Enter ur name and age";
cin>>name>>age;
}
void dispersion()
{
cout<<"\n Name   : "<
cout<<"\n Age      : "<
}
};
class student : public person
{
int mark;
public:
void getmark()
{
cout<<"\n Enter ur mark";
cin>>mark;
}
void dismark()
{
cout<<"\nMark: "<
}
};
class employee : public person
{
long sal;
public:
void getsal()
{
cout<<"1. Student \n 2. Employee \n Enter ur choice\n";
cin>>choice;
if(choice==1)
{
student s;
s.getperson();
s.getmark();
s.disperson();
s.dismark();
}
else if (choice ==2)
{
employee e;
e.getperson();
e.getsal();
e.disperson();
e.dissal();
}
else
{
cout<<"Invalid choice\n";
}
getch();
}

Output

1.     Student
2.     Employee
Enter your choice
1
Enter your Name and Age
Raja
25
Enter your mark
99
Name :         Raja
Age   :         25
Mark :         90

Hierarchical Building Program

#include
#include
template
class building
{
public:
int fl,ro,sq;
void getdata()
{
cout<<"\n Enter the no.of floor in the building";
cin>>fl;
cout<<"\n Enter the no.of. room in the building";
cin>>ro;
cout<<"\n Enter the no.of square feet in the building";
cin>>sq;
}
void display()
{
cout<<"\n Total no. of floor in the building:"<
cout<<\n Total no.of room in the building: "<
cout<<"\n Total no. of square feet in the building""<
}
};
class home: public building
{
public:
int br,bat;
void getdata()
{
cout<<"\n\n Home";
building::getdata();
cout<<"\n Enter the no . of bedrooms";
cin>>br;
cout<<"\n Enter the no .of bathrooms";
cin>>bat;
}
void display()
{
building::display();
cout<<"\n Total no. of bedrooms: "<
cout<<"\n Total no .of bathrooms: "<
}
};
class office: public building
{
public:
int fe,te;
void getdata()
{
cout<<"\n\n\t Office";
building::getdata();
cout<<" \n Enter the no.of fire extinguisers";
cin>>fe;
cout<<"\n Enter the no.of telephones";
cin>>te;
}
void display()
{
building::display();
cout<<"\n Total noof fire extinguishers: "<
cout<<"\n Total no.of telephones:"<
}
};
void main()
{
clrscr();
int ch;
cout<<"\n 1. Home \n 2. Office \n Enter ur choice";
cin>>ch;
if(ch==1)
{
home h;
h.getdata();
h.display();
}
else if(ch==2)
{
office o;
o.getdata();
o.display();
}
else
{
cout<<" Invalid choice\n";
}
getch();
}

Output

1.     Home
2.     Office
Enter your choice
1.
                   Home
---------------------------------------------------------------------------
Enter the no.of floors in the building          :         6
Enter no.of rooms in the building     :         4
Enter the no.of sq.ft in the building  :         500
Enter the no.of bed rooms                :         5
Enter the no.of bathrooms                :         3

Total no.of floors           :         6
Total no.of rooms                   :         4
Total                              :         500
Total no.of bed rooms   :         5

No comments:

Post a Comment