冒泡排序实现对考生成绩的查找排序(C++)

			查找与排序
			1、问题描述

假设某公司招工n名,报考者的政审、体检已通过,现在要根据报考者的考试成绩择优录取。考试课程有:政治、语文、数学、英语四门。考试成绩分为四类:第一类为四门都及格;第二类为一门成绩不及格;第三类为两门成绩不及格;其余为第四类。录取方法是按类次并在每一类中按总分从高到低录取。
试设计一个成绩处理程序,要求打印输出n份录取通知书,列出录取者四门课程的成绩及总分,最后查找并输出在第一类中英语成绩最好者的纪录。(假设第i名和第i+1名一定不会同类且总分相等。)
2、说明
(1)输入数据:输入每个考生的姓名及各门课程的考试成绩。
(2)输出数据:按照择优录取的次序打印出n份录取通知书如下图:
在这里插入图片描述

#include<iostream>
#define MAX 99
using namespace std;
typedef struct
{
	char name;
	int po, ch, ma, en,sum, level;
}student;
typedef struct {
	student * stu;
	int num;
}STU;
void chushihua(STU&M)
{
	M.stu = new student[MAX];
	M.num = 0;
}
void input(STU&M)
{
	cout << "请输入考生总数:" << endl;;
	cin >> M.num;
	for (int i = 1; i <= M.num; i++)
	{
		int k = 1;
		cout<<"请依次输入学生的姓名 政治 语文 数学 英语成绩"<<endl;
		cin >>M.stu[i].name >>M.stu[i].po>>M.stu[i].ch>>M.stu[i].en >>M.stu[i].ma;
		M.stu[i].sum= M.stu[i].po+M.stu[i].ch+ M.stu[i].en+M.stu[i].ma;
		if (M.stu[i].po< 60) k++;if (M.stu[i].ch< 60) k++;if (M.stu[i].en< 60) k++;if (M.stu[i].ma< 60) k++;
		if (k > 4) { k = 4; };
		M.stu[i].level = k;
	}
}
void output(STU&M)
{
	for (int i = 1; i <= M.num; i++)
	{
		cout << "ADMISSION NOTICE"<< endl;
		cout << "Name:"<<M.stu[i].name << endl;
		cout << "You have been admitted"<< endl;
		cout << "Your score:" << endl;
		cout << "Politics:"<< M.stu[i].po<< endl;
		cout << "Chinese:"<< M.stu[i].ch<< endl;
		cout << "Math:"<< M.stu[i].en<< endl;
		cout << "English:"<< M.stu[i].ma<< endl;
		cout << "Total:" << M.stu[i].sum<< endl;
		cout << "科院COMPANY"<< endl;
		cout << " " << endl;
	}
}
void maopao(STU&M)
{
	for (int i = M.num-1; i>= 1; i--)
	{
		for (int j = 1; j <= i; j++)
		{
			if (M.stu[j].level > M.stu[j + 1].level) 
			{
				swap(M.stu[j],M.stu[j + 1]);
			}
			else if (M.stu[j].level==M.stu[j + 1].level) 
			{
				if (M.stu[j].sum < M.stu[j + 1].sum) 
				{
					swap(M.stu[j],M.stu[j + 1]);
				}
			}
		}
	}

}
void Print(student stu)
{
	cout << "第一类英语成绩最高为" << endl;
	cout << "ADMISSION NOTICE" << endl;
	cout << "Name:"<<stu.name <<endl;
	cout << "You have been admitted" << endl;
	cout << "Your score:"<< endl;
	cout << "Politics:"<< stu.po<< endl;
	cout << "Chinese:"<<stu.ch << endl;
	cout << "English:"<<stu.en << endl;
	cout << "Math:"<< stu.ma << endl;
	cout << "Total:"<<stu.sum << endl;
	cout << "科院COMPANY"<< endl;
	cout << " " << endl;
}

void enmax(STU&M)
{
	if (M.stu[1].level!= 1) {
		cout << "没有第一类学生" << endl;
		return;
	}
	else {
		student enmax = M.stu[1];
		for (int i = 2; i <= M.num && M.stu[i].level == 1; i++)
		{
			if (M.stu[i].en > enmax.en) {
				enmax = M.stu[i];
			}
		}
		Print(enmax);
	}
}
int main()
{
	STU M;
	chushihua(M);
	input(M);
	maopao(M);
	output(M);
	enmax(M);
	return 0;
}

在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值