-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignement3.cpp
157 lines (108 loc) · 2.74 KB
/
assignement3.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<iostream>
using namespace std;
class weather_report
{
public:
int hightemp,lowtemp,amtrain,amtsnow; //member veriable
int DOM;
weather_report()
{ //constructor
int DOM=99;
int hightemp=999;
int lowtemp=999;
int amtrain=0;
amtsnow=0;
}
int getdata()
{
cout<<"\n enter the date of month:";
cin>>DOM;
cout<<"\n enter the high temprature:";
cin>>hightemp;
cout<<"\n enter the low temprature:";
cin>>lowtemp;
cout<<"\n enter the amount of rain:";
cin>>amtrain;
cout<<"\n enter the amount of snow:";
cin>>amtsnow;
}
int display()
{
cout<<"\n\t"<<DOM<<"\t\t"<<amtrain<<"\t\t"<<amtsnow<<"\t\t"<<hightemp<<"\t\t"<<lowtemp;
}
};
int main()
{
weather_report w[31];
int ch,i,j=0,k,n,x,pr=0, flag;
do
{
cout<<"\nmenu:";
cout<<"\n 1.getdata \n 2.putdata \ns 3.exit";
cout<<"\n enter the choice:";
cin>>ch;
switch(ch)
{
case 1:
{
int flag=0;
cout<<"enter the no. of days:";
cin>>n;
n=n+j;
for(i=j;i<n;i++)
{
flag=0;
w[i].getdata();
for(k=0;k<i;k++)
{
if(w[i].DOM==w[k].DOM)
{
cout<<"\n record is available:";
cout<<"Enter another day data:";
i--;
flag=1;
}
}
if(flag==0)
{
if(0<w[i].DOM && w[k].DOM<=31)
{
j++;
}
else
{
cout<<"\n invalid day....!!";
i--;
}
}
}
break;
}
case 2:
{
float avgrain,avgsnow,avghightemp,avglowtemp;
float sumrain=0,sumsnow=0,sumhightemp=0,sumlowtemp=0;
for(i=0;i<n;i++)
{
sumrain=sumrain+w[i].amtrain;
sumsnow=sumsnow+w[i].amtsnow;
sumhightemp=sumhightemp+w[i].hightemp;
sumlowtemp=sumlowtemp+w[i].lowtemp;
}
avgrain=sumrain/n;
avgsnow=sumsnow/n;
avghightemp=sumhightemp/n;
avglowtemp=sumlowtemp/n;
cout<<"\tDay\t"<<"\tamtrain\t"<<"\tamtsnow\t"<<"\thightemp\t"<<"\tlowtemp\t";
for(i=0;i<n;i++)
{
w[i].display();
cout<<endl<<endl;
}
cout<<endl<<endl;
cout<<"\tAvg\t\t"<<avgrain<<"\t\t"<<avgsnow<<"\t\t"<<avghightemp<<"\t\t"<<avglowtemp;
break;
}
}
}while(ch!=3);
}