碇真嗣


私信TA

用户名:dotcpp0690000

访问量:141

签 名:

"HelloWorld"

等  级
排  名 2325
经  验 2281
参赛次数 0
文章发表 3
年  龄 18
在职情况 学生
学  校 新疆财经大学
专  业 计算机科学与技术

  自我简介:

解题思路:
使用类的思想,其他的就不说了别的地方都有写。
注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区