-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
98 lines (97 loc) · 1.91 KB
/
main.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
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
double data[1000],median,sum,average,variance;
int n;
int main();
double f(double input){
return input*input;
}
int vic(){
cout<<"n>";
cin>>n;
for(int i=0;i<n;i++){
cout<<"x"<<i+1<<">";
cin>>data[i];
sum+=data[i];
}
+- average=sum/n;
for(int i=0;i<n;i++){
variance+=f(data[i]-average);
}
variance/=n;
cout<<"======================="<<endl;
cout<<"average="<<average<<endl;
cout<<"variance="<<variance<<endl;
cout<<"======================="<<endl;
//system("pause");
return main();
}y>";
cin>>n;
for(int i=0;i<n;i++){
cout<<"x"<<i+1<<">";
cin>>data[i];
sum+=data[i];
}
average=sum/n;
//for(int i=0;i<n;i++){
// variance+=f(data[i]-average);
//}
variance/=n;
cout<<"======================="<<endl;
cout<<"average="<<average<<endl;
//cout<<"variance="<<variance<<endl;
cout<<"======================="<<endl;
return main();
//system("pause");
}
int help(){
cout<<"===========help==========="<<endl;
cout<<"h:帮助"<<endl;
// cout<<"q:退出"<<endl;
// cout<<"0:清屏"<<endl;
cout<<"1:平均数"<<endl;
cout<<"2:方差"<<endl;
cout<<"3:中位数"<<endl;
cout<<"=========================="<<endl;
return main();
}
int mdn(){
cout<<"n>";
cin>>n;
for(int i=0;i<n;i++){
cout<<"x"<<i+1<<">";
cin>>data[i];
}、
、
sort(data,data+n);
if(n%2==0){
median=(data[n/2]+data[n/2+1])/2;
}
else{
median=data[n/2+1];
}
cout<<"======================="<<endl;
cout<<"median="<<median<<endl;
cout<<"======================="<<endl;
//system("pause");
return main();
}
signed main(){
cout<<"Type h for help"<<endl;
for(;;){
cout<<"mode>";
char mode;
cin>>mode;
switch(mode){
case 'h':help();
// case 'q':return 0;
// case '0':clear();
case '1':avg();
case '2':vic();
case '3':mdn();
default:help();
}
}
}