day2_C++
- 代码题
- 思维导图
代码题
#include
using namespace std;
#define MAX 50
struct StuData
{
private:
int scoreArr[MAX];
int num;
public:
void setNum(int num);
void input();
void sort();
void show();
int getnum();
};
void StuData::setNum(int num){
this->num = num;
}
void StuData::input(){
int count = num;
for(int i = 0;i<count;i++){
cin>>scoreArr[i];
}
cout<<"成绩录入成功"<<endl;
}
void StuData::sort(){
int temp = 0;
for(int i = 0;i<num-1;i++){
for(int j = 0;j<num-1-i;j++){
if(scoreArr[j] > scoreArr[j+1]){
temp = scoreArr[j];
scoreArr[j] = scoreArr[j+1];
scoreArr[j+1] = temp;
}
}
}
}
void StuData::show(){
for(int i = 0;i<num;i++){
cout<<scoreArr[i]<<" ";
}
cout<<endl;
}
int main()
{
struct StuData data;
cout<<"请输入学生的个数:";
int n = 0;
cin>>n;
data.setNum(n);
data.input();
data.sort();
data.show();
return 0;
}