-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexam 11.cpp
More file actions
71 lines (60 loc) · 1.57 KB
/
exam 11.cpp
File metadata and controls
71 lines (60 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Write a class name building which has three data members: height, number
// of floors and price. You have to find which building is taller,
// has the highest number of floors and is more expensive. You have
// to solve the problem using the polymorphism concept. Implement the class.
#include <iostream>
using namespace std;
class building
{
public :
int height;
int floors;
int price;
void f(int a, int b, int c)
{
height = a;
floors = b;
price = c;
}
void f(double s, double p, double r)
{
height = s;
floors = p;
price = r;
}
void comp(building s,building y)
{
if(s.height>y.height)
cout<<"Building 1 is taller"<<endl;
else
{
cout <<"Building 2 is taller." << endl;
}
if(s.floors>y.floors)
cout<<"Building 1 has the highest floors"<<endl;
else
{
cout << "Building 2 has the highest floors." << endl;
}
if(s.price>y.price)
cout<<"Building 1 has the highest price. "<<endl;
else
{
cout << "Building 2 has the highest price." << endl;
}
}
};
int main ()
{
int x1,x2,y1,y2,z1,z2;
cout<<"Enter Building 1 & 2 Heights : ";
cin>>x1>>x2;
cout<<"Enter Building 1 & 2 floors : ";
cin>>y1>>y2;
cout<<"Enter Building 1 & 2 price : ";
cin>>z1>>z2;
building ob,ob1;//-
ob.f(x1,y1,z1);
ob1.f(x2,y2,z2);
ob.comp(ob,ob1);
}