-
Notifications
You must be signed in to change notification settings - Fork 0
/
04.Array in Class.BAK
108 lines (86 loc) · 1.48 KB
/
04.Array in Class.BAK
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//program to illustrate array within a class
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
class item
{
int icode[5];
float price[5];
public:
void initial()
{
for(int i=0;i<5;i++)
{
cout<<"\n For Item No. "<<i+1;
cout<<"\n Item Code: ";
cin>>icode[i];
cout<<"\n Item Price: ";
cin>>price[i];
cout<<"\n";
}
}
void large()
{
float lar=price[0];
int it=0;
for(int i=0;i<5;i++)
{
if(lar<price[i])
{
lar=price[i];
it=icode[i];
}
}
cout<<"Largest Price: "<<lar;
cout<<"\n Item Code: "<<it;
}
void sum()
{
float sum=0;
for(int i=0;i<5;i++)
{
sum+=price[i];
}
cout<<"Sum of prices: "<<sum;
}
void disp()
{
for(int i=0;i<5;i++)
{
cout<<"\n For Item No. "<<i+1;
cout<<"\n Item Code: "<<icode[i];
cout<<"\n Item Price: "<<price[i];
cout<<"\n";
}
}
};
void main()
{
clrscr();
int c;
item i;
i.initial();
clrscr();
do
{
cout<<"\n\t MAIN MENU \n\n";
cout<<"\t 1.Display largest Price";
cout<<"\n 2.Display Sum of Price";
cout<<"\n 3.Display all items";
cout<<"\n\n Enter your choice: ";
cin>>c;
switch(c)
{
case 1:
i.large();
break;
case 2:
i.sum();
break;
case 3: i.disp();
break;
default: cout<<"Wrong choice";
break;
}
}while(c!=4);
}