学生成绩管理系统V4.0

某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入)。参考学生成绩管理系统V3.0,用二维数组作函数参数编程实现如下菜单驱动的学生成绩管理系统:

1)录入每个学生的学号、姓名和各科考试成绩;

2)计算每门课程的总分和平均分;

3)计算每个学生的总分和平均分;

4)按每个学生的总分由高到低排出名次表;

5)按每个学生的总分由低到高排出名次表;

6)按学号由小到大排出成绩表;

7)按姓名的字典顺序排出成绩表;

8)按学号查询学生排名及其各科考试成绩;

9)按姓名查询学生排名及其各科考试成绩;

10)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~595个类别,对每门课程分别统计每个类别的人数以及所占的百分比;

11)输出每个学生的学号、姓名、各科考试成绩、总分、平均分,以及每门课程的总分和平均分

代码如下:代码中还有许多问题有待改进,但基本算法就这样了。

#include 
#include 
#include 
using namespace std;
void input(int xvehao[], int course[][7],string name[], int n);
void caculate_score(int xvehao[], int course[][7], string name[], int n);
void caculate_student(int xvehao[], int course[][7], string name[], int n);
void sort_in_descending_order_by_score(int xvehao[], int course[][7], string name[], int n);
void sort_in_ascending_order_by_score(int xvehao[], int course[][7], string name[], int n);
void sort_in_ascending_order_by_number(int xvehao[], int course[][7], string name[], int n);
void sort_in_dictionary_order_by_name(int xvehao[], int course[][7], string name[], int n);
void search_by_number(int xvehao[], int course[][7], string name[], int n);
void search_by_name(int xvehao[], int course[][7], string name[], int n);
void statistic(int xvehao[], int course[][7], string name[], int n);
int main()
{
	int n;
	cout << "Input student number(n<30):";
	cin >> n;
	int choice;
	int course[30][7] = { 0 };
	int xvehao[30];
	string name[30];
	while (1)
	{
		cout << endl;
		cout << "Management for Students' scores" << endl;
		cout << "1.Input record" << endl;
		cout << "2.Caculate total and average score of every course" << endl;
		cout << "3.Caculate total and average score of every student" << endl;
		cout << "4.Sort in descending order by score" << endl;
		cout << "5.Sort in ascending order by score" << endl;
		cout << "6.Sort in ascending order by number" << endl;
		cout << "7.Sort in dictionary order by name" << endl;
		cout << "8.Search by number" << endl;
		cout << "9.Search by name" << endl;
		cout << "10.Statistic analysis" << endl;
		cout << "11.List record" << endl;
		cout << "0.Exit" << endl;
		cout << "Please Input your choice:";
		cin >> choice;

		if (choice == 1)input(xvehao,course ,name,n);
		else if (choice == 2)caculate_score(xvehao, course, name, n);
		else if (choice == 3)caculate_student(xvehao, course, name, n);
		else if (choice == 4)sort_in_descending_order_by_score(xvehao, course, name, n);
		else if (choice == 5)sort_in_ascending_order_by_score(xvehao, course, name, n);
		else if (choice == 6)sort_in_ascending_order_by_number(xvehao, course, name, n);
		else if (choice == 7)sort_in_dictionary_order_by_name(xvehao, course, name, n);
		else if (choice == 8)search_by_number(xvehao, course, name, n);
		else if (choice == 9)search_by_name(xvehao, course, name, n);
		else if (choice == 10)statistic(xvehao, course, name, n);
		else if (choice == 11)sort_in_ascending_order_by_number(xvehao, course, name, n);
		else if (choice == 0) 
		{
			cout << "End of program!";
			break;
		}
		else
		{
			cout << "Input error!" << endl;
			cout << "Please input any number from 0 to 11!"<> subject;
	int i,j;
	cout << "Input student's ID, name and score:" << endl;
	for (i = 1; i <= n; i++)
	{
		cin >> xvehao[i];
		cin >> name[i];
		for (j = 1; j <= subject; j++)
		{
			cin >> course[i][j];
		}
	}
}

void caculate_score(int xvehao[], int course[][7], string name[], int n)
{
	float sum,aver;
	int i,j;
	for (i = 1; i <= 6; i++)
	{
		if (course[1][i] != 0)
		{
			sum = 0; aver = 0;
			for (j = 1; j <= n; j++)
			{
				sum += course[j][i];
			}
			aver = sum / n;
			cout << "course " << i << ":sum=" << sum << ",aver=" < SUM[j])k = j;
		}
		change1 = xvehao[i];
		xvehao[i] = xvehao[k];
		xvehao[k] = change1;
		change2 = name[i];
		name[i] = name[k];
		name[k] = change2;
		for (int t = 1; t <= 6; t++)
		{
			change1 = course[i][t];
			course[i][t] = course[k][t];
			course[k][t] = change1;
		}
		change1 = SUM[i];
		SUM[i] = SUM[k];
		SUM[k] = change1;
	}
	for (i = 1; i <= n; i++)
	{
		cout << xvehao[i] << " " << name[i] << " ";
		for (j = 1; j <= 6; j++)
		{
			if (course[i][j] != 0)
				cout << course[i][j] << " ";
			else break;
		}
		cout << endl;
	}
}

void sort_in_ascending_order_by_number(int xvehao[], int course[][7], string name[], int n)
{
	int i, j, k;
	int change1;
	string change2;
	for (i = 1; i <= n; i++)
	{
		k = i;
		for (j = i + 1; j <= n; j++)
		{
			if (xvehao[k] > xvehao[j])k = j;
		}
		change1 = xvehao[i];
		xvehao[i] = xvehao[k];
		xvehao[k] = change1;
		change2 = name[i];
		name[i] = name[k];
		name[k] = change2;
		for (int t = 1; t <= 6; t++)
		{
			change1 = course[i][t];
			course[i][t] = course[k][t];
			course[k][t] = change1;
		}
	}
	for (i = 1; i <= n; i++)
	{
		cout << xvehao[i] << " " << name[i] << " ";
		for (j = 1; j <= 6; j++)
		{
			if (course[i][j] != 0)
				cout << course[i][j] << " ";
			else break;
		}
		cout << endl;
	}
}

void sort_in_dictionary_order_by_name(int xvehao[], int course[][7], string name[], int n)
{
	int i, j, k,t;
	int change1;
	string change2;
	for (i = 1; i <= n; i++)
	{
		k = i;
		for (j = i + 1; j <= n; j++)
		{
			for (t = 0; t < name[i].size(); t++)
			{
				if (name[k][t] > name[j][t])
				{
					k = j; break;
				}
				else if (name[k][t] == name[j][t])continue;
				else break;
			}
		}
		change1 = xvehao[i];
		xvehao[i] = xvehao[k];
		xvehao[k] = change1;
		change2 = name[i];
		name[i] = name[k];
		name[k] = change2;
		for (t = 1; t <= 6; t++)
		{
			change1 = course[i][t];
			course[i][t] = course[k][t];
			course[k][t] = change1;
		}
	}
	for (i = 1; i <= n; i++)
	{
		cout << xvehao[i] << " " << name[i] << " ";
		for (j = 1; j <= 6; j++)
		{
			if (course[i][j] != 0)
				cout << course[i][j] << " ";
			else break;
		}
		cout << endl;
	}
}

void search_by_number(int xvehao[], int course[][7], string name[], int n)
{	
	int i,j,k;
	int number;
	cin>> number;
	for (i = 1; i <= n; i++)
	{
		if (xvehao[i] == number)
		{
			cout << xvehao[i] << " " << name[i] << " ";
			for (j = 1; j <= 6; j++)
			{
				if (course[i][j] != 0)
					cout << course[i][j] << " ";
				else break;
			}
			cout << endl;
			k = 1;
			break;
		}
		else k = 0;
	}
	if (k == 0)cout << "Not found!" << endl;
}
void search_by_name(int xvehao[], int course[][7], string name[], int n)
{
	string Name;
	cin >> Name;
	int i,j,k;
	for (i = 1; i <= n; i++)
	{
		for (j = 0; j < Name.size(); j++)
		{
			if (name[i][j] == Name[j])k = 1;
			else { k = 0; break; }
		}
		if (k==1)
		{
			cout << xvehao[i] << " " << name[i] << " ";
			for (j = 1; j <= 6; j++)
			{
				if (course[i][j] != 0)
					cout << course[i][j] << " ";
				else break;
			}
			cout << endl;
			break;
		}
	}
	if (k == 0)cout << "Not found!" << endl;
}

void statistic(int xvehao[], int course[][7], string name[], int n)
{
	int i, j;
	int A, B, C, D, E, F;
	for (i = 1; i <= 6; i++)
	{
		A = 0, B = 0, C = 0, D = 0, E = 0, F = 0;
		if (course[1][i] != 0)
		{
			for (j = 1; j <= n; j++)
			{
				if (course[j][i] == 100)A++;
				else if (course[j][i] >= 90 && course[j][i] <= 99)B++;
				else if (course[j][i] >= 80 && course[j][i] <= 89)C++;
				else if (course[j][i] >= 70 && course[j][i] <= 79)D++;
				else if (course[j][i] >= 60 && course[j][i] <= 69)E++;
				else F++;
			}
		}
		else break;
		cout << "For course " << i << endl;
		cout << "<60  " << F <<"  "<< fixed<

你可能感兴趣的:(ACM作业,c++,算法)