-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patharray_of_objects.cpp
59 lines (44 loc) · 1020 Bytes
/
array_of_objects.cpp
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
// program using array of objects
#include<iostream.h>
#include<conio.h>
class distance
{
private:
int feet;
float inches;
public:
void getdistance();
void showdistance();
};
void distance::getdistance()
{
cout<<"\t Enter feet = ";
cin>>feet;
cout<<"\t Enter inches = ";
cin>>inches;
}
void distance::showdistance()
{
cout<<"\n\t Total distance is "<<feet<<"\' "<<inches<<'"'<<endl;
}
void main()
{
clrscr();
distance obj[25];
char ans;
int n=0;
do
{
cout<<"\n Enter the distance number = "<<n+1<<endl;
obj[n++].getdistance();
cout<<"\n Enter another (y/n)?";
cin>>ans;
}
while(ans!='n');
for(int i=0;i<n;i++)
{
cout<<"\n Distance number "<<i+1<<" is :";
obj[i].showdistance();
}
getch();
}