班级成绩管理系统

 

这个系统共4部分组成:

 1.CClass.app部分

#include "CClass.h"

int Class::ClassCount = 0;

Class::Class()
{
	ClassID = "";
	ClassName = "";
}

Class::Class(string id, string name)
{
	ClassID = id;
	ClassName = name;
}

void Class::FillStudent(vector <Student> studentvector)
{
	int i;

	for (i = 0; i < studentvector.size(); i++)
	{
		StudentVector.insert(StudentVector.end(), studentvector[i]);
	}
}

string Class::GetPassword()
{
	return Password;
}

/*计算累加和*/
void Class::ClearRecord()
{
	StudentVector.clear();
}

/*计算累加和*/
void Class::AddSum()
{
	int i, j;
	int StudentItems, CourseItems;
	float sumVal;

	StudentItems = StudentVector.size();
	CourseItems = StudentVector[0].GetCourseCount();

	for (i = 0; i < StudentItems; i++)
	{
		sumVal=0;
		for (j = 0; j < CourseItems; j++)
		{
			sumVal += StudentVector[i].GetCourse (j).GetCourseMark() ;
		}
		StudentVector[i].SetSum(sumVal);
		StudentVector[i].SetAver(sumVal/ CourseItems);
	}
}

/*通过学号返回数组下标*/
int Class::SearchByID(string id)
{
	int i;
	int StudentItems;

	StudentItems = StudentVector.size();

	for (i = 0; i <StudentItems; i++)
	{
		if (id == StudentVector[i].GetStudentID())
		{
			return i;
		}
	}
	return -1;
}

/*通过姓名返回数组下标*/
int Class::SearchByName(string name)
{
	int i;
	int StudentItems;

	StudentItems = StudentVector.size();

	for (i = 0; i <StudentItems; i++)
	{
		if (name == StudentVector[i].GetStudentName())
		{
			return i;
		}
	}
	return -1;
}

/*成绩录入*/
void Class::InforInset()	//成绩录入
{
	int i, j, h;
	int StudentItems, CourseItems;
	char returnFlag[5];

	while (1)
	{
		cout << "请输入需要录入的学生数量:";
		cin >> StudentItems;
		Class::SetStudentCount(StudentItems);

		cout << "请输入课程数量:";
		cin >> CourseItems;
		Class::SetCourseCount(CourseItems);

		vector <Student> MyStudentVector(StudentItems);
		vector <Course> MyCourseVector(CourseItems);

		cout << "请输入课程名称:";
		for (i = 0; i < CourseItems; i++)
		{
			string CourseName;
			cin >> CourseName;
			MyCourseVector[i].SetCourse(std::to_string(i), CourseName, 0);
		}

		for (i = 0; i < StudentItems; i++)
		{
			string id, name,sex;
			int age;
			cout << "请输入学号:";
			cin >> id;
			cout << "请输入姓名:";
			cin >> name;
			cout << "请输入年龄:";
			cin >> age;
			cout << "请输入性别:";
			cin >> sex;
			MyStudentVector[i].SetStudent(id, name,age,sex);

			cout << "请分别输入";
			for (h = 0; h < CourseItems - 1; h++)
			{
				cout << MyCourseVector[h].GetCourseName()<< ",";
			}
			cout << MyCourseVector[CourseItems - 1].GetCourseName() << "的成绩:";

			for (j = 0; j < CourseItems; j++)
			{
				float val;
				cin >> val;
				MyCourseVector[j].SetCourseMark(val);
			}
			MyStudentVector[i].FillCourse(MyCourseVector);
		}
		FillStudent(MyStudentVector);
		cout << "成绩录入完毕,请记得先保存数据再继续操作哦~\n是否继续录入学生成绩?(y/n):";
		cin >> returnFlag;
		if (returnFlag[0] == 'y' || returnFlag[0] == 'Y')
		{
			continue;
		}
		else
		{
			break;
		}
	}
}


/*成绩显示*/
void Class::ScoreShow()
{
	int i, j;
	int StudentItems, CourseItems;

	StudentItems = StudentVector.size();
	CourseItems = StudentVector[0].GetCourseCount();

	printf("----------------------------------------------------------------------\n");
	cout << setw(10) << right << "学号" << setw(10) << right << "姓名"<<setw(10)<<right<<"年龄" << setw(10) << right << "性别";

	for (i = 0; i < CourseItems; i++)
	{
		cout << setw(10) << StudentVector[0].GetCourse(i).GetCourseName();
	}
	cout << setw(10) << right << "平均分" << setw(10) << right << "总分";
	cout << endl;
	printf("----------------------------------------------------------------------\n");

	AddSum();
	for (i = 0; i < StudentItems; i++)
	{
		cout << setw(10) << right << StudentVector[i].GetStudentID() << setw(10) << right << StudentVector[i].GetStudentName() << setw(10) << right << StudentVector[i].GetStudentAge() << setw(10) << right << StudentVector[i].GetStudentSex();
		for (j = 0; j < CourseItems; j++)
		{
			cout << setw(10) << setprecision(1) << fixed << right << StudentVector[i].GetCourse(j).GetCourseMark();
		}
		cout << setw(10) << right << StudentVector[i].GetAver() << setw(10) << right << StudentVector[i].GetSum();
		cout << endl;
	}
}

/*成绩修改*/
void Class::Modify()
{
	string xh, xm,xb, pass, Password;
	int nl, CourseItems,returnnum, h, j, flag;
	float val;

	flag = 3;
	
	CourseItems = StudentVector[0].GetCourseCount();
	Password = GetPassword();
	cout << "请输入密码:";
	while (1)
	{
		cin >> pass;
		if (pass == Password)
		{
			cout << "密码正确!请输入你要修改的学生学号:";
			cin >> xh;
			returnnum = SearchByID(xh);
			if (returnnum == -1)
			{
				cout << "学生不存在!" << endl;
			}
			else
			{
				cout << "请重新输入学生信息:" << endl;

				cout << "请输入学号:";
				cin >> xh;
				cout << "请输入姓名:";
				cin >> xm;
				cout << "请输入年龄:";
				cin >> nl;
				cout << "请输入性别:";
				cin >> xb;
				StudentVector[returnnum].SetStudent(xh, xm, nl,xb);

				cout << "请分别输入";
				for (h = 0; h < CourseItems - 1; h++)
				{
					cout << StudentVector[0].GetCourse(h).GetCourseName() << ",";
				}
				cout << StudentVector[0].GetCourse(CourseItems - 1).GetCourseName() << "的成绩:";

				for (j = 0; j < CourseItems; j++)
				{
					cin >> val;
					StudentVector[returnnum].SetCourseMark(j,val);
				}
			}
			cout << "修改完后记得保存读出数据哦!" << endl;
			break;
		}
		else
		{
			flag--;
			if (flag > 0)
			{
				cout << "密码错误,你还有" << flag << "次机会,请重新输入密码:";
				continue;
			}
			else
			{
				break;
			}

		}
	}
}

/*成绩删除*/
void Class::deleteRecord()
{
	string xh, pass;
	int StudentItems,CourseItems,returnnum, i, flag;

	flag = 3;

	StudentItems = StudentVector.size();
	CourseItems = StudentVector[0].GetCourseCount();
	Password = GetPassword();

	cout << "请输入密码:";
	while (1)
	{
		cin >> pass;
		if (pass == Password)
		{
			cout << "密码正确!请输入你要删除的学生学号:";
			cin >> xh;
			returnnum = SearchByID(xh);
			if (returnnum == -1)
			{
				cout << "学生不存在!" << endl;
			}
			else
			{
				cout << "开始删除!\n";
				for (i = returnnum; i < StudentItems - 1; i++)
				{
					StudentVector[i] = StudentVector[i + 1];
				}
				StudentVector.pop_back();
			}
			cout << "删除完后记得保存读出数据哦!" << endl;
			break;
		}
		else
		{
			flag--;
			if (flag > 0)
			{
				cout << "密码错误,你还有" << flag << "次机会,请重新输入密码:";
				continue;
			}
			else
			{
				break;
			}
		}
	}
}

/*成绩统计*/
void Class::Statis()
{
	int i, j, flag, flag1, flag2;
	float sum;
	float max, min;

	int StudentItems = StudentVector.size();
	int CourseItems = StudentVector[0].GetCourseCount();

	cout << "*****************************************************************" << endl;
	cout << "                     各课程最高成绩学生统计                       " << endl;	//统计最低成绩
	cout << "*****************************************************************" << endl;
	cout << setw(15) << right << "课程";
	cout << setw(15) << right << "学号";
	cout << setw(15) << right << "姓名";
	cout << setw(15) << right << "成绩" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		max = -1;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark() > max)
			{
				max = StudentVector[j].GetCourse(i).GetCourseMark();
				flag = j;
				flag1 = i;
			}
		}
		cout << setw(15) << right << StudentVector[0].GetCourse(i).GetCourseName();
		cout << setw(15) << right << StudentVector[flag].GetStudentID();
		cout << setw(15) << right << StudentVector[flag].GetStudentName();
		cout << setw(15) << right << StudentVector[flag].GetCourse(flag1).GetCourseMark() << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                     各课程最低成绩学生统计                       " << endl;	//统计最低成绩
	cout << "*****************************************************************" << endl;
	cout << setw(15) << right << "课程";
	cout << setw(15) << right << "学号";
	cout << setw(15) << right << "姓名";
	cout << setw(15) << right << "成绩" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		min = 10000;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark() <min)
			{
				min = StudentVector[j].GetCourse(i).GetCourseMark();
				flag = j;
				flag1 = i;
			}
		}
		cout << setw(15) << right << StudentVector[0].GetCourse(i).GetCourseName();
		cout << setw(15) << right << StudentVector[flag].GetStudentID();
		cout << setw(15) << right << StudentVector[flag].GetStudentName();
		cout << setw(15) << right << StudentVector[flag].GetCourse(flag1).GetCourseMark() << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                          各课程平均成绩                         " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(25) << right << "课程";
	cout << setw(25) << right << "平均成绩" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		sum = 0;
		for (j = 0; j < StudentItems; j++)
		{
			sum += StudentVector[j].GetCourse(i).GetCourseMark();
		}
		StudentVector[i].Setaver (sum / (StudentItems));
		cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();
		cout << setw(25) << right << StudentVector[i].Getaver() << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                         超过平均成绩人数                        " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(25) << right << "课程";
	cout << setw(25) << right << "人数(个)" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		flag2 = 0;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark() > StudentVector[i].Getaver())
			{
				flag2++;
			}
		}
		cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();
		cout << setw(25) << right << flag2 << endl;
	}							
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                         高于平均成绩名册                        " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(15) << right << "课程";
	cout << setw(15) << right << "ID" << setw(15) << right << "姓名" << setw(15) << right << "成绩" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		flag2 = 0;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark() > StudentVector[i].Getaver())
			{
				cout << setw(15) << right << StudentVector[0].GetCourse(i).GetCourseName() << setw(15) << right << StudentVector[j].GetStudentID() << setw(15) << right << StudentVector[j].GetStudentName() << setw(15) << right << StudentVector[j].GetCourse(i).GetCourseMark() << endl;
				//flag2++;
			}
		}
		//cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();
		//cout << setw(25) << right << flag2 << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                         不及格成绩人数                          " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(25) << right << "课程";
	cout << setw(25) << right << "人数(个)" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		flag2 = 0;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark()<60)
			{
				flag2++;
			}
		}
		cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();
		cout << setw(25) << right << flag2 << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                         不及格名册                            " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(15) << right << "课程";
	cout << setw(15) << right << "ID" << setw(15) << right << "姓名" << setw(15) << right << "成绩" << endl;
	for (i = 0; i < CourseItems; i++)
	{
		flag2 = 0;
		for (j = 0; j < StudentItems; j++)
		{
			if (StudentVector[j].GetCourse(i).GetCourseMark() < 60)
			{
				cout << setw(15) << right << StudentVector[0].GetCourse(i).GetCourseName() << setw(15) << right << StudentVector[j].GetStudentID() << setw(15) << right << StudentVector[j].GetStudentName() << setw(15) << right << StudentVector[j].GetCourse(i).GetCourseMark() << endl;
				//cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName()<< setw(25) << right << StudentVector[0].GetStudentName();
			}
		}
		//cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();
		//cout << setw(25) << right << flag2 << endl;
	}
	cout << endl;

	cout << "*****************************************************************" << endl;
	cout << "                     成绩位于60-80区段人数                       " << endl;
	cout << "*****************************************************************" << endl;
	cout << setw(25) << right << "课程";
	cout << setw(25) << right << "人数(个)" << endl;
	for (i = 0; i < CourseItems; i++)//
	{
		flag2 = 0;
		for (j = 0; j < StudentItems; j++)//
		{
			if ((StudentVector[j].GetCourse(i).GetCourseMark()< 80) && (StudentVector[j].GetCourse(i).GetCourseMark()>=60))//
//			if (60<(StudentVector[j].GetCourse(i).GetCourseMark())< 80)			//
			{
				flag2++;
			}
		}
		
		cout << setw(25) << right << StudentVector[0].GetCourse(i).GetCourseName();//
		cout << setw(25) << right << flag2 << endl;
	}
	cout << endl;
}

/*成绩排序*/
void Class::InforSort()
{
	int i, j;
	Student temp;

	int StudentItems = StudentVector.size();

	AddSum();
	for (i = 0; i < StudentItems - 1; i++)
	{
		for (j = 0; j < StudentItems - 1 - i; j++)
		{
			if (StudentVector[j].GetSum() > StudentVector[j+1].GetSum())
			{
				temp = StudentVector[j];
				StudentVector[j] = StudentVector[j+1];
				StudentVector[j+1] = temp;
			}
		}
	}
	ScoreShow();
}

/*成绩逆排序*/
void Class::Inforsort()
{
	int i, j;
	Student temp;

	int StudentItems = StudentVector.size();

	AddSum();
	for (i = 0; i < StudentItems - 1; i++)
	{
		for (j = 0; j < StudentItems - 1 - i; j++)
		{
			if (StudentVector[j].GetSum() < StudentVector[j + 1].GetSum())
			{
				temp = StudentVector[j];
				StudentVector[j] = StudentVector[j + 1];
				StudentVector[j + 1] = temp;
			}
		}
	}
	ScoreShow();
}

/*成绩排序(第一门课)*/
void Class::inforsort()
{
	int i, j;
	Student temp;

	int StudentItems = StudentVector.size();

	AddSum();
	for (i = 0; i < StudentItems - 1; i++)
	{
		for (j = 0; j < StudentItems - 1 - i; j++)
		{
			if (StudentVector[j].GetCourse(0).GetCourseMark() > StudentVector[j+1].GetCourse(0).GetCourseMark())
			{
				temp = StudentVector[j];
				StudentVector[j] = StudentVector[j + 1];
				StudentVector[j + 1] = temp;
			}
		}
	}
	ScoreShow();
}

/*输出文件数据*/
void Class::SavaDate()
{
	int i, j;
	ofstream outfile("班级成绩管理系统.txt", ios::out);
	if (!outfile)
	{
		cerr << "open error!" << endl;
		exit(1);
	}
	outfile << "----------------------------------------------------------------------\n";
	outfile << "学号" << '\t' << "姓名" << '\t' << "年龄" << '\t' << "性别" << '\t';

	int StudentItems = StudentVector.size();
	int CourseItems = StudentVector[0].GetCourseCount();

	for (i = 0; i < CourseItems; i++)
	{
		outfile << StudentVector[0].GetCourse(i).GetCourseName() << '\t';
	}
	outfile << '\n';
	outfile << "----------------------------------------------------------------------\n";
	for (i = 0; i < StudentItems; i++)
	{		
		outfile << StudentVector[i].GetStudentID() << '\t' << StudentVector[i].GetStudentName() << '\t' << StudentVector[i].GetStudentAge() << '\t' << StudentVector[i].GetStudentSex() << '\t';
		for (j = 0; j < CourseItems; j++)
		{		
			outfile << StudentVector[i].GetCourse(j).GetCourseMark() << '\t';
		}
		outfile << '\n';
	}

	cout << "文件导出完成!" << endl;
	outfile.close();
}

/*文件读取数据*/
void Class::InforRead()
{
	int flag, h;
	char buf[1000];
	string s;

	vector <Student> MyStudentVector;
	vector <Course> MyCourseVector;
	Student MyStudent;
	Course MyCourse;

	int StudentItems = 0;
	int CourseItems = 0;

	ifstream infile("班级成绩管理系统.txt", ios::in);
	if (!infile)
	{
		cerr << "文件不存在,请输入新的数据!" << endl;
	}
	else
	{
		MyStudent.SetStudent("","",0,"");
		MyStudentVector.push_back(MyStudent);

		infile.getline(buf, 1000);
		flag = 0;
		while (infile >> s)
		{
			flag++;
			if (s == "----------------------------------------------------------------------")
			{
				break;
			}
			if (flag > 4)
			{
				MyCourse.SetCourse(std::to_string(CourseItems), s, 0);
				MyCourseVector.push_back(MyCourse);
				CourseItems++;
			}
		}

		MyStudentVector[0].FillCourse(MyCourseVector);
		StudentItems = 0;
		while (!infile.eof())
		{
			string id, name,sex;
			int age;
			float val;

			infile >> id >> name>>age>>sex;
			if (id == "") 			//数据结束,不再增加
				break;
			if (StudentItems > 0)		//增加后续项
			{
				MyStudentVector.push_back(MyStudent);
				MyStudentVector[StudentItems].FillCourse(MyCourseVector);
			}

			MyStudentVector[StudentItems].SetStudent(id, name,age,sex);
			for (h = 0; h < CourseItems; h++)
			{
				infile >> val;
				MyStudentVector[StudentItems].SetCourseMark(h, val);
			}
			
			StudentItems++;
		}
		cout << "数据导入完成!" << endl;
		infile.close();
	}
	FillStudent(MyStudentVector);
	Class::SetCourseCount(CourseItems);
	AddSum();
}

/*指定学生成绩显示*/
void Class::ShowByID()
{
	int i, j, returnnum;
	int CourseItems;
	string xh;

	CourseItems = StudentVector[0].GetCourseCount();

	cout << "请输入你要显示的学生学号:";
	cin >> xh;
	returnnum = SearchByID(xh);
	if (returnnum == -1)
	{
		cout << "学生不存在!" << endl;
	}
	else
	{
		printf("----------------------------------------------------------------------\n");
		cout << setw(10) << right << "学号" << setw(10) << right << "姓名"<<setw(10)<<right<<"年龄" << setw(10) << right << "性别";

		for (i = 0; i < CourseItems; i++)
		{
			cout << setw(10) << StudentVector[0].GetCourse(i).GetCourseName();
		}
		cout << setw(10) << right << "平均分" << setw(10) << right << "总分";
		cout << endl;
		printf("----------------------------------------------------------------------\n");

		AddSum();

		cout << setw(10) << right << StudentVector[returnnum].GetStudentID() << setw(10) << right << StudentVector[returnnum].GetStudentName() << setw(10) << right << StudentVector[returnnum].GetStudentAge() << setw(10) << right << StudentVector[returnnum].GetStudentSex();
		for (j = 0; j < CourseItems; j++)
		{
			cout << setw(10) << setprecision(1) << fixed << right << StudentVector[returnnum].GetCourse(j).GetCourseMark();
		}
		cout << setw(10) << right << StudentVector[returnnum].GetAver() << setw(10) << right << StudentVector[returnnum].GetSum();
		cout << endl;
	}

}

/*指定学生姓名成绩显示*/
void Class::ShowByName()
{
	int i, j, returnnum;
	int CourseItems;
	string xm;
	int StudentItems;
	StudentItems = StudentVector.size();

	CourseItems = StudentVector[0].GetCourseCount();

	cout << "请输入你要显示的学生姓名:";
	cin >> xm;
	returnnum = SearchByName(xm);
	if (returnnum == -1)
	{
		cout << "学生不存在!" << endl;
	}
	printf("----------------------------------------------------------------------\n");
	cout << setw(10) << right << "学号" << setw(10) << right << "姓名" << setw(10) << right << "年龄" << setw(10) << right << "性别";
	for (int k = 0; k < CourseItems; k++)
	{
		cout << setw(10) << StudentVector[0].GetCourse(k).GetCourseName();
	}
	cout << setw(10) << right << "平均分" << setw(10) << right << "总分";
	cout << endl;
	printf("----------------------------------------------------------------------\n");
	for (i = 0; i < StudentItems; i++)
	{
		if (xm == StudentVector[i].GetStudentName())
		{
			AddSum();

			cout << setw(10) << right << StudentVector[i].GetStudentID() << setw(10) << right << StudentVector[i].GetStudentName() << setw(10) << right << StudentVector[i].GetStudentAge() << setw(10) << right << StudentVector[i].GetStudentSex();
			for (j = 0; j < CourseItems; j++)
			{
				cout << setw(10) << setprecision(1) << fixed << right << StudentVector[i].GetCourse(j).GetCourseMark();
			}
			cout << setw(10) << right << StudentVector[i].GetAver() << setw(10) << right << StudentVector[i].GetSum();
			cout << endl;
		}
	}
}

void Class::showbysex()
{
	int i, j,p=0;
	int CourseItems;
	string xb;
	int StudentItems;
	StudentItems = StudentVector.size();
    CourseItems = StudentVector[0].GetCourseCount();

	cout << "请输入你要显示的学生性别:";
	cin >> xb;
	printf("----------------------------------------------------------------------\n");
	cout << setw(10) << right << "学号" << setw(10) << right << "姓名" << setw(10) << right << "年龄" << setw(10) << right << "性别";
	for (int k = 0; k < CourseItems; k++)
	{
		cout << setw(10) << StudentVector[0].GetCourse(k).GetCourseName();
	}
	cout << setw(10) << right << "平均分" << setw(10) << right << "总分";
	cout << endl;
	printf("----------------------------------------------------------------------\n");
	for (i = 0; i < StudentItems; i++)
	{

		if (xb == StudentVector[i].GetStudentSex())
		{
			p++;
			AddSum();

			cout << setw(10) << right << StudentVector[i].GetStudentID() << setw(10) << right << StudentVector[i].GetStudentName() << setw(10) << right << StudentVector[i].GetStudentAge() << setw(10) << right << StudentVector[i].GetStudentSex();
			for (j = 0; j < CourseItems; j++)
			{
				cout << setw(10) << setprecision(1) << fixed << right << StudentVector[i].GetCourse(j).GetCourseMark();
			}
			cout << setw(10) << right << StudentVector[i].GetAver() << setw(10) << right << StudentVector[i].GetSum();
			cout << endl;
		}
		
	}
	if(p==0)
	{
		cout << "无此性别的学生" << endl;
	}
}

void Class::showbyage()
{
	int i, j,p=0;
	int CourseItems;
	int nl1,nl2;
	int StudentItems;
	StudentItems = StudentVector.size();
	CourseItems = StudentVector[0].GetCourseCount();

	cout << "请输入你要显示的学生年龄段:";
	cin >> nl1>> nl2;
	printf("----------------------------------------------------------------------\n");
	cout << setw(10) << right << "学号" << setw(10) << right << "姓名" << setw(10) << right << "年龄" << setw(10) << right << "性别";
	for (int k = 0; k < CourseItems; k++)
	{
		cout << setw(10) << StudentVector[0].GetCourse(k).GetCourseName();
	}
	cout << setw(10) << right << "平均分" << setw(10) << right << "总分";
	cout << endl;
	printf("----------------------------------------------------------------------\n");
	for (i = 0; i < StudentItems; i++)
	{

		if (nl1<=StudentVector[i].GetStudentAge() && StudentVector[i].GetStudentAge()<=nl2)
		{
			p++;
			AddSum();

			cout << setw(10) << right << StudentVector[i].GetStudentID() << setw(10) << right << StudentVector[i].GetStudentName() << setw(10) << right << StudentVector[i].GetStudentAge() << setw(10) << right << StudentVector[i].GetStudentSex();
			for (j = 0; j < CourseItems; j++)
			{
				cout << setw(10) << setprecision(1) << fixed << right << StudentVector[i].GetCourse(j).GetCourseMark();
			}
			cout << setw(10) << right << StudentVector[i].GetAver() << setw(10) << right << StudentVector[i].GetSum();
			cout << endl;
		}
		
	}
	if(p==0)
	{
		cout << "无此年龄段的学生" << endl;
	}
}

2.CCourse.app部分

#include "CCourse.h"

int Course::CourseCount = 0;

Course::Course()
{
	CourseID = "";
	CourseName = "";
	CourseMark = 0;
}

Course::Course(string id, string name, float mark)
{
	CourseID = id;
	CourseName = name;
	CourseMark = mark;
}

void Course::SetCourse(string id, string name, float mark)
{
	CourseID = id;
	CourseName = name;
	CourseMark = mark;
}

void Course::SetCourseMark(float mark)
{
	CourseMark = mark;
}

void Course::SetCourseID(string id)
{
	CourseID = id;
}

void Course::SetCourseName(string name)
{
	CourseName = name;
}

string Course::GetCourseID()
{
	return CourseID;
}

string Course::GetCourseName()
{
	return CourseName;
}

float Course::GetCourseMark()
{
	return CourseMark;
}

void Course::Course_Disp()
{
	cout << "ID=" << CourseID << "," << "Name=" << CourseName << ",""<<Mark=" << CourseMark << endl;
}

void Course::SetCourseCount(int val)
{
	CourseCount = val;
}

int Course::GetCourseCount()
{
	return CourseCount;
}

3.CStudent.app部分

#include "CStudent.h"

int Student::StudentCount = 0;

Student::Student()
{

}

Student::Student(string id, string name,int age,string sex)
{
	StudentID = id;
	StudentName = name;
	this->age = age;
	this->sex = sex;
}

void Student::SetStudent(string id, string name,int age,string sex)
{
	StudentID = id;
	StudentName = name;
	this->age = age;//this 指针
	this->sex = sex;
}

void Student::FillCourse(vector <Course> coursevector)
{
	int i;

	for (i = 0; i < coursevector.size(); i++)
	{
		CourseVector.insert(CourseVector.end(), coursevector[i]);
	}
}

string Student::GetStudentName()
{
	return StudentName;

}
string Student::GetStudentID()
{
	return StudentID;
}
int Student::GetStudentAge()
{
	return age;
}
string Student::GetStudentSex()
{
	return sex;
}
void Student::SetStudentCount(int val)
{
	StudentCount = val;
}

int Student::GetStudentCount()
{
	return StudentCount;
}

Course Student::GetCourse(int i)
{
	return CourseVector[i];
}

void Student::SetCourseMark(int i,float val)
{
	CourseVector[i].SetCourseMark(val);
}

void Student::SetCourseName(int i, string name)
{
	CourseVector[i].SetCourseName(name);
}

float Student::GetSum()
{
	return sum;
}

void Student::SetSum(float val)
{
	sum = val;
}

float Student::GetAver()
{
	return Aver;
}

void Student::SetAver(float val)
{
	Aver = val;
}

float Student::Getaver()
{
	return aver;
}

void Student::Setaver(float val)
{
	aver = val;
}

4.main.app部分

#include "CClass.h"

using namespace std;

void displayIndex();

/*主程序*/
int main()
{
	int fun;
	char returnFlag[5];
	Class MyClass;

	MyClass.InforRead();
	while(1)		//error:输入a,b,c...导致显示紊乱
	{
		displayIndex();
		cout <<  "请输入选项:";
		cin >> fun;
		switch (fun)
		{
		case 1 :
//			stu.InforInset(st);	
			MyClass.ClearRecord();
			MyClass.InforInset();
			break;
		case 2:
//			stu.ScoreShow(st);
			MyClass.ScoreShow();
			break;
		case 3:
//			stu.SavaDate(st);
			MyClass.SavaDate();
			break;
		case 4:
//			stu.InforRead (st);
			MyClass.ClearRecord();
			MyClass.InforRead();
			break;
		case 5 :
//			stu.InforSort(st);
			MyClass.InforSort();
			break;
		case 6:
//			stu.Modify(st);
			MyClass.Modify();
			break;
		case 7:
//			stu.deleteRecord(st);
			MyClass.deleteRecord();
			break;
		case 8:
//			stu.Statis(st);
			MyClass.Statis();
			break;
		case 9:
			system("cls");
			break;
		case 10:  
			cout <<" 确认退出系统?(y/n)";
			cin >> returnFlag;
			if(returnFlag[0] == 'y' || returnFlag[0] == 'Y')
			{
				exit(0);  
			}
			else
			{
				continue;
			}			
			break; 			

		case 11:
			MyClass.ShowByID();
			break;
		case 12:
			MyClass.ShowByName();
			break;

		case 21:
			//			stu.InforSort(st);
			MyClass.Inforsort();
			break;

		case 22:
			//			stu.InforSort(st);
			MyClass.inforsort();
			break;
		
		case 31:
			//			stu.InforSort(st);
			MyClass.showbysex();
			break;

		case 32:
			//			stu.InforSort(st);
			MyClass.showbyage();
			break;
		}		
	}
	return 0;
}

/*显示台*/
void displayIndex()
{
	printf("╔═══════班级成绩管理系统════════╗\n");
	printf("║              1.成绩录入;                     ║\n");
	printf("║              2.成绩显示;                     ║\n");
	printf("║              3.导出成绩;                     ║\n");
	printf("║              4.导入成绩;                     ║\n");
	printf("║              5.成绩排序;                     ║\n");
	printf("║              6.成绩修改;                     ║\n");
	printf("║              7.成绩删除;                     ║\n");
	printf("║              8.成绩统计;                     ║\n");
	printf("║              9.清屏;                         ║\n");
	printf("║              10.安全退出系统;                ║\n");
	printf("║                                              ║\n");
	printf("║              11.显示指定学号学生成绩         ║\n");
	printf("║              12.显示指定姓名学生成绩         ║\n");
	printf("║              21.成绩排序(逆排序)             ║\n");
	printf("║              22.成绩排序(按第一门课)         ║\n");
	printf("║              31.指定性别                     ║\n");
	printf("║              32.指定年龄                     ║\n");
	printf("║                                              ║\n");
	printf("║                      Made By zzz             ║\n");
	printf("╚═══════════════════════╝\n");
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值