-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPRA_24
65 lines (60 loc) · 1.08 KB
/
PRA_24
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
/* A program to demonstrate single inheritance by private derivation. */
#include<iostream>
using namespace std;
class Distance
{
float d;
public:
int getDistance()
{
cout << "Enter total Distance in meter :";
cin >> d;
cout << endl;
return d;
}
void putDistance()
{
cout << "Distance = " <<d<<endl;
}
};
class speed : private Distance
{
float t,s;
public:
void getTime()
{
cout << "Enter total Time in Seconds : ";
cin >>t;
s=t*getDistance();
}
void putSpeed()
{
cout << "Speed of Vehicle = "<<s<<" m/s"<<endl;
}
};
int main()
{
cout <<"For Car"<<endl;
speed car;
car.getTime();
car.putSpeed();
cout << endl<< "For Truck"<<endl;
speed truck;
truck.getTime();
truck.putSpeed();
return 0;
}
/*
Output:
For Car
Enter total Time in Seconds : 500
Enter total Distance in meter :40
Speed of Vehicle = 20000 m/s
For Truck
Enter total Time in Seconds : 666
Enter total Distance in meter :33
Speed of Vehicle = 21978 m/s
--------------------------------
Process exited after 25.92 seconds with return value 0
Press any key to continue . . .
*/