-
Notifications
You must be signed in to change notification settings - Fork 8
/
lh.cpp
79 lines (73 loc) · 1.42 KB
/
lh.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
#include <stdio.h>
#include <iostream>
using namespace std;
// write your code here
// any code ...
class Myarray
{
protected:
int *alist;
int length;
public:
Myarray(int len)
{alist=new int[len];length=len;}
~Myarray()
{delete(alist);cout<<"x........"<<endl;}
void input()
{
int i;
for(i=0;i<length;i++)
{cout<<"输入数组的"<<i+1<<"个元素:"<<'\n';
cin>>alist[i];}
}
int getlen(){return length;}
void display()
{for(int i=0;i<length;i++)
cout<<alist[i]<<' ';
cout<<endl;
}
};
class averarray:virtual public Myarray
{
public:
averarray(int n):Myarray(n)
{}
float getaver()
{float aver;
int sum=0,i;
for(i=0;i<length;i++)
sum+=alist[i];
aver=(float)sum/length;
return aver;
}
};
class rearray:virtual public Myarray
{
public:
rearray(int n):Myarray(n)
{}
void turn()
{
int i,t,j=length-1;
for(i=0;i<length/2;i++,j--)
{t=alist[i];alist[i]=alist[j];alist[j]=t;}
}
};
class nawarray:public rearray,public averarray
{
public:
nawarray(int n):Myarray(n),rearray(n),averarray(n)
{}
};
void LH()
{
nawarray A(5);
A.input();
A.display();
cout<<"输出平均成绩:"<<endl;
cout<<A.getaver()<<endl;
cout<<"倒置:"<<endl;
A.turn();
A.display();
printf("LH\n");
}