解题思路:
使用类的思想,其他的就不说了别的地方都有写。
注意事项:
参考代码:
#include<iostream>
using namespace std;
class Student {
private:
string name;
int age;
float score;
static int N;
public:
Student(string n = "name", int a = 0, float s = 0)
{
name = n;
age = a;
score = s;
}
void getdata(string n, int a, float s)
{
name = n;
age = a;
score = s;
}
void show()
{
cout << "name:" << name;
cout << " age:" << age;
cout << " score:" << score << endl;
}
static void show(Student* stus)
{
Student* p = stus;
for (int i = 0; i < N; i++,p++)
{
cout << p->name << " " << p->age <<
" " << p->score << endl;
}
}
static void swap(Student* q, Student* p)
{
Student tem;
tem = *q; //cout << 1 << endl;
*q = *p; //cout << 2 << endl;
*p = tem; //cout << 3 << endl;
}
static void setN(int n)
{
N = n;
}
static void sort(Student* p)
{
for (int i = 0; i < N-1; i++)
{
for (int j = 0; j < N - 1 - i; j++)
{
if ((p + j)->score > (p + j + 1)->score ||
(p + j)->score == (p + j + 1)->score &&
(p+j)->name > (p+j+1)->name ||
(p + j)->score == (p + j + 1)->score &&
(p + j)->name == (p + j + 1)->name && (p+j)->age > (p+j+1)->age)
{
swap((p + j), (p + j + 1));
}
}
}
}
};
int Student::N = 0;
int test(int n)
{
Student::setN(n);
Student* stus, * p;
stus = new Student[n];
p = stus;
for (int i = 0; i < n; p++, i++)
{
string n;
int a;
float s;
cin >> n >> a >> s;
p->getdata(n, a, s);
}
p = stus;
Student::sort(p);
Student::show(stus);
delete []stus;
return 0;
}
int main()
{
int n;
while (cin >> n)
{
test(n);
}
return 0;
}
0.0分
0 人评分
The 3n + 1 problem (C语言代码)浏览:718 |
【计算两点间的距离】 (C语言代码)浏览:1126 |
C语言训练-委派任务* (C语言代码)..................竟然是第一个浏览:2177 |
点我有惊喜!你懂得!浏览:1069 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:578 |
母牛的故事 (C语言代码)浏览:671 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:688 |
C语言训练-排序问题<1> (C++代码)浏览:598 |
九宫重排 (C++代码)浏览:1333 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:596 |