⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 我大一时候做的C++课程设计
💻 CPP
字号:
#include<iostream.h>
#include<string.h>
class student							//学生类的定义,私有成员字符串型学号,各门成绩和总分,									
{
private:								//带默认形参的构造函数和不带形参的构造函数									
										//外部接口有设置学生信息,输出学生信息,返回总分
	char num[11];
	int math, phi, phy, eng, che, com, sum;
public:
	student();
	student(char *n, int ma, int pi, int py, int eg, int ce, int cm);
	void set_inf(char *n, int ma, int pi, int py, int eg, int ce, int cm);
	int get_sum();
	void get_inf();
};

//学生类公有成员函数的实现

student::student()
{
	strcpy(num, "00000");
	math=0; phi=0; phy=0; eng=0; che=0; com=0;
	sum=math+phi+phy+eng+che+com;
}
void student::set_inf(char *n, int ma, int pi, int py, int eg, int ce, int cm)
{
	strcpy(num, n);
	math=ma; phi=pi; phy=py; eng=eg; che=ce; com=cm;
	sum=math+phi+phy+eng+che+com;
}

int student::get_sum() { return sum;}
void student::get_inf()
{
	cout << "├───┼───┼───┼───┼───┼───┼───┼───┼───┤" << endl;
	cout << "│" << num << "\t│  "<<math << "\t│  "<<phi<< "\t│  "<<phy << "\t│  "<<eng 
		<< "\t│  "<<che << "\t│ "<<com << "\t│ "<<sum <<"\t│";
	
}



////////////////
//////////////////////////主函数////////////////////////////////////
void main()
{
	const int temp_total=30;
	int total=30;
	int ma=0, pi=0, py=0, eg=0, ce=0, cm=0;
	char n[20]="00000";
	student s[temp_total];

	//设置30个学生信息
	s[1].set_inf("93001",89,81,70,80,77,81);
	s[2].set_inf("93002",76,87,90,81,82,73);
	s[3].set_inf("93003",60,55,75,81,74,67);
	s[4].set_inf("93004",81,85,86,81,90,89);
	s[5].set_inf("93005",89,97,91,88,85,94);
	s[6].set_inf("93006",96,92,84,93,98,89);
	s[7].set_inf("93007",56,60,64,68,70,59);
	s[8].set_inf("93008",87,62,69,78,92,65);
	s[9].set_inf("93009",78,65,74,80,81,74);
	s[10].set_inf("93010",74,56,45,61,70,79);
	s[11].set_inf("93011",70,0,56,67,71,80);
	s[12].set_inf("93012",88,78,80,76,90,77);
	s[13].set_inf("93013",89,81,70,80,77,81);
	s[14].set_inf("93014",45,50,56,60,55,61);
	s[15].set_inf("93015",92,98,91,98,93,100);
	s[16].set_inf("93016",80,79,68,74,80,84);
	s[17].set_inf("93017",56,80,75,80,84,81);
	s[18].set_inf("93018",81,86,87,79,80,90);
	s[19].set_inf("93019",79,65,45,80,76,72);
	s[20].set_inf("93020",76,74,80,72,69,80);
	s[21].set_inf("93021",72,81,82,84,89,78);
	s[22].set_inf("93022",81,87,89,90,92,89);
	s[23].set_inf("93023",69,80,78,60,65,89);
	s[24].set_inf("93024",73,91,80,78,67,90);
	s[25].set_inf("93025",65,10,72,55,70,60);
	s[26].set_inf("93026",100,80,78,89,90,0);
	s[27].set_inf("93027",75,86,88,80,83,70);
	s[28].set_inf("93028",76,85,80,81,66,72);
	s[29].set_inf("93029",74,82,70,79,82,71);
	s[0].set_inf("93030",61,55,75,81,74,68);


	int max, j;
	for(int i=0; i<total; i++)			//排序的实现
	{
		max=i;							//max记录总分最大者的在数组中的下标
		for(j=i+1; j<total; j++)
		{
			if(s[j].get_sum()>s[max].get_sum())
				max=j;
		}
		student temp;
		temp=s[i];				//交换学生的所有数据!!
		s[i]=s[max];
		s[max]=temp;
	}

	//输出

	cout << "               ***********学生成绩排名***********           " <<  endl << endl;
	cout << "┌───┬───┬───┬───┬───┬───┬───┬───┬───┐"<< endl;
	cout << "│ 学号 │ 数学 │ 哲学 │ 物理 │ 外语 │ 化学 │计算机│ 总分 │ 名次 │"<<endl;
	for(i=0; i<total; i++)
	{
		s[i].get_inf();
		cout <<"  "<<i+1 <<"\t│" << endl;//名次,必须+1
	}
	cout << "└───┴───┴───┴───┴───┴───┴───┴───┴───┘"<< endl;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -