[C/C++]结课作业-学生管理系统
- ?个人主页:北·海
- ?CSDN新晋作者
- ?欢迎 ?点赞✍评论⭐收藏
- ✨收录专栏:C/C++
- ?希望作者的文章能对你有所帮助,有不足的地方请在评论区留言指正,大家一起学习交流!?
#ifndef OOP_PROJECT_STUDENT_H
#define OOP_PROJECT_STUDENT_H
#define NAME_MAX 20
#define STU_MAX 100
#include<iostream>
using namespace std;
class Student {
public:
static int numStudent;
void Input(Student stu[]); //输入学生成绩
void Statistic(Student stu[]); //统计数据
void Lookup(Student stu[]); //查找学生成绩
void Modify(Student stu[]); //修改学生成绩
void Delete(Student stu[]); //删除学生成绩
void Output(Student stu[]); //显示全部学生成绩
void Sort(Student stu[]);//排序
void Sling(Student stu[]); //查找挂科
private:
int num; //学号
char name[NAME_MAX]; //姓名
char class_0[NAME_MAX]; //班级
float elec; //电子成绩
float c_program; //C++成绩
float english; //英语成绩
float math; //高等数学成绩
float physics; //物理成绩
float sport; //体育
float polity; //政治
float average; //平均分
bool CheckScore(float score);
};
#endif //OOP_PROJECT_STUDENT_H
student.cpp
#include <cstring>
#include "Student.h"
int Student::numStudent = 0;
//输入学生信息
void Student::Input(Student *stu) {
char sign = 0;
int c = 0;
cout << endl << "======>> 请输入学生成绩 <<======" << endl;
while (sign != 'n' && sign != 'N') {
cout << "班级:";
cin >> stu[Student::numStudent].class_0;
loop: //循环
cout << "学号:";
cin >> stu[Student::numStudent].num;
for(int k = 0;k<numStudent;k++){
if (stu[Student::numStudent].num == stu[k].num){
cout << "您输入的学号已存在!请重新输入。" << endl;
goto loop; //继续执行循环
}
}
cout << "姓名:";
cin >> stu[Student::numStudent].name;
cout << "电子技术成绩:";
cin >> stu[Student::numStudent].elec;
while (!CheckScore(stu[Student::numStudent].elec)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "电子技术成绩:";
cin >> stu[Student::numStudent].elec;
}
cout << "大学英语成绩:";
cin >> stu[Student::numStudent].english;
while (!CheckScore(stu[Student::numStudent].english)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "大学英语成绩:";
cin >> stu[Student::numStudent].english;
}
cout << "C++程序设计成绩:";
cin >> stu[Student::numStudent].c_program;
while (!CheckScore(stu[Student::numStudent].c_program)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "C++程序设计成绩:";
cin >> stu[Student::numStudent].c_program;
}
cout << "政治成绩:";
cin >> stu[Student::numStudent].polity;
while (!CheckScore(stu[Student::numStudent].polity)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "政治成绩:";
cin >> stu[Student::numStudent].polity;
}
cout << "大学体育成绩:";
cin >> stu[Student::numStudent].sport;
while (!CheckScore(stu[Student::numStudent].sport)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "大学体育成绩:";
cin >> stu[Student::numStudent].sport;
}
cout << "高等数学成绩:";
cin >> stu[Student::numStudent].math;
while (!CheckScore(stu[Student::numStudent].math)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "高等数学成绩:";
cin >> stu[Student::numStudent].math;
}
cout << "物理成绩:";
cin >> stu[Student::numStudent].physics;
while (!CheckScore(stu[Student::numStudent].physics)){
cout << " 对不起,请输入1-100之间的数字!!\n";
cout << "物理成绩:";
cin >> stu[Student::numStudent].physics;
}
stu[Student::numStudent].average = (stu[Student::numStudent].elec + stu[Student::numStudent].c_program + stu[Student::numStudent].physics + stu[Student::numStudent].english + stu[Student::numStudent].math +
stu[Student::numStudent].sport + stu[Student::numStudent].polity) / 7;
cout << " 平均分为:" << stu[Student::numStudent].average << endl;
cout << "提示:是否继续写入学生成绩 ?(y/n)";
cin >> sign;
Student::numStudent++;
}
}
统计信息
void Student::Statistic(Student *stu) {
cout << endl << "\t\t================>> \t 输出学生统计数据 \t <<===================\t\n" << endl;
cout << "-------------------------------------------------------------------------------------------------------" << endl;
cout << "班级" << "\t\t" << "学号" << "\t" << "姓名" << "\t\t" << "电子" << "\t" << "C++" << "\t" << "物理" << "\t"
<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"<< "政治" << "\t" << "平均分" << endl;
cout << "--------------------------------------------------------------------------------------------------------" << endl;
for (int i = 0; i < Student::numStudent; i++)
{
cout << "----------------------------------------------------------------------------------------------------" << endl;
cout << stu[i].class_0 << "\t\t" << stu[i].num << "\t" << stu[i].name << "\t\t"
<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].physics << "\t"
<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
<< stu[i].polity << "\t" << stu[i].average << endl;
}
}
//查询学生信息
void Student::Lookup(Student *stu) {
int s;
cout << endl << "======>> 查找学生成绩 <<======" << endl;
cout << "请输入要查找学生的学号:";
cin>>s;
for(int i = 0 ;i<Student::numStudent;i++){
if(stu[i].num == s){
cout << "----------------------------" << endl;
cout << "班级:" << stu[i].class_0 << endl;
cout << "学号:" << stu[i].num << endl;
cout << "姓名:" << stu[i].name << endl;
cout << "电子技术:" << stu[i].elec << endl;
cout << "C++程序设计:" << stu[i].c_program << endl;
cout << "物理:" << stu[i].physics << endl;
cout << "大学英语:" << stu[i].english << endl;
cout << "高等数学:" << stu[i].math << endl;
cout << "大学体育:" << stu[i].sport << endl;
cout << "政治:" << stu[i].polity << endl;
cout << "平均分:" << stu[i].average << endl;
return;
}
}
cout<<"未找到该学生信息!"<<endl;
}
//修改学生信息
void Student::Modify(Student *stu) {
int s;
cout << endl << "======>> 修改学生成绩 <<======" << endl;
cout << "请输入要修改成绩学生的学号:";
cin >> s;
cout<<(stu[1]).math<<endl;
for(int i = 0 ;i<Student::numStudent;i++){
if((stu[i]).num == s){
cout<<"找到该学生了,请重新输入该学生成绩:"<<endl;
cout<<"学生学号不能被修改!"<<endl;
cout << "学生班级:";
cin >> (stu[i]).class_0;
cout << "姓名:";
cin >> (stu[i]).name;
cout << "电子技术成绩:";
cin >> (stu[i]).elec;
cout << "C++成绩:";
cin >> (stu[i]).c_program;
cout << "物理成绩:";
cin >> (stu[i]).physics;
cout << "大学英语成绩:";
cin >> (stu[i]).english;
cout << "高等数学成绩:";
cin >> (stu[i]).math;
cout << "大学体育成绩:";
cin >> (stu[i]).sport;
cout << "政治:";
cin >> (stu[i]).polity;
(stu[i]).average = ((stu[i]).elec + (stu[i]).c_program + (stu[i]).physics +
(stu[i]).english + (stu[i]).math + (stu[i]).sport + (stu[i]).polity) / 7;
cout<<"修改成功"<<endl;
}
}
}
//删除学生信息
void Student::Delete(Student *stu) {
int s,j;
char c = 0;
cout << endl << "======>> 删除学生成绩 <<======" << endl;
cout << "请输入要删除的学生的学号:";
cin >> s;
for(int i = 0 ;i<Student::numStudent;i++){
if(stu[i].num == s){
cout<<"学生已找到,是否删除(y/n):";
cin>>c;
if(c == 'y'||c =='Y'){
for (j = i; j < Student::numStudent - 1; j++)
{
stu[j] = stu[j+1];//调用默认拷贝构造函数
}
cout << "======>> 提示:已成功删除!" << endl;
Student::numStudent--;
return;
}
}
}
}
//输出所有学生信息
void Student::Output(Student *stu) {
cout << endl << "======>> 显示全部学生成绩 <<======" << endl;
if (Student::numStudent == 0) {
cout << "没有记录"<<endl;
}
else {
cout << "------------------------------------------------------------------------------------" << endl;
cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
<< "电子" << "\t" << "C++" << "\t" << "物理" << "\t"
<< "英语" << "\t" << "数学" << "\t" << "体育" << "\t"
<< "政治" << "\t" << "平均分" << endl;
cout << "------------------------------------------------------------------------------------" << endl;
for (int i = 0; i < Student::numStudent; i++) {
cout << stu[i].class_0 << "\t" << stu[i].num << "\t" << stu[i].name << "\t"
<< stu[i].elec << "\t" << stu[i].c_program << "\t" << stu[i].physics << "\t"
<< stu[i].english << "\t" << stu[i].math << "\t" << stu[i].sport << "\t"
<< stu[i].polity << "\t" << stu[i].average << endl;
}
cout << "------------------------------------------------------------------------------------" << endl;
}
}
//排序管理界面
int page()
{
int c;
do {
cout << "******************************************************" << endl;
cout << "----------------欢迎查看各科成绩排名----------------" << endl;
cout << "***************************************************" << endl;
cout << " * 【1】电子技术成绩排名 * " << endl;
cout << " * 【2】C++成绩排名 * " << endl;
cout << " * 【3】物理成绩排名 * " << endl;
cout << " * 【4】英语成绩排名 * " << endl;
cout << " * 【5】高等数学成绩排名 * " << endl;
cout << " * 【6】体育成绩排名 * " << endl;
cout << " * 【7】政治成绩排名 * " << endl;
cout << " * 【8】平均分排名 * " << endl;
cout << " * 【0】退出 * " << endl;
cout << "***************************************************" << endl;
cout << "请选择您的操作 (0-8):" << endl;
cin>>c;
} while (c<0||c>9);
return c;
}
//主页面
int menu() {
int c;
do {
cout << "******************************************************" << endl;
cout << "------------欢迎使用高校学生成绩信息管理系统-----------" << endl;
cout << "******************************************************" << endl;
cout << "----------------欢迎使用学生成绩管理系统---------------" << endl;
cout << " * 【1】输入学生成绩 * " << endl;
cout << " * 【2】显示统计数据 * " << endl;
cout << " * 【3】查找学生成绩 * " << endl;
cout << " * 【4】修改学生成绩 * " << endl;
cout << " * 【5】删除学生成绩 * " << endl;
cout << " * 【6】按各科成绩排列 * " << endl;
cout << " * 【7】显示学生成绩 * " << endl;
cout << " * 【8】显示学生挂科情况 * " << endl;
cout << " * 【0】退出管理系统 * " << endl;
cout << "******************************************************" << endl;
cout << "请选择您的操作 (0-8):" << endl;
cin>>c;
} while (c<0||c>=9);
return c;
}
//排序
void Student::Sort(Student *stu) {
//按学科成绩排
int res;
while(1)
{
res = page(); //调用page()函数
switch (res)
{
case 1:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].elec < stu[j + 1].elec) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
Output(stu);
break;
case 2:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].c_program < stu[j + 1].c_program) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 3:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].physics < stu[j + 1].physics) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 4:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].english < stu[j + 1].english) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 5:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].math < stu[j + 1].math) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 6:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].sport < stu[j + 1].sport) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 7:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].polity < stu[j + 1].polity) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 8:
for (int i = 0; i < Student::numStudent - 1; i++)
for (int j = 0; j < Student::numStudent - 1; j++)
if (stu[j].average < stu[j + 1].average) {
Student temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] =temp;
}
Output(stu);
break;
case 0:
cout << endl << "=============正在返回上一级==========\n" << endl;
menu();
return;
}
}
}
//检测成绩输入范围
bool Student::CheckScore(float score) {
if(score>-1 && score<=100)
return true;
else
return false;
}
//挂科情况
void Student::Sling(Student *stu) {
int i, j, k,count ;
cout << " " << endl;
cout << "**********************学生挂科情况*********************" << endl;
cout << " " << endl;
for (i = 0; i < Student::numStudent; i++)
{
for (j = 0; j < 6; j++)
{
count = 0;
if (stu[i].elec < 60) count++;
if (stu[i].c_program < 60) count++;
if (stu[i].physics < 60) count++;
if (stu[i].english < 60) count++;
if (stu[i].math < 60) count++;
if (stu[i].sport < 60) count++;
if (stu[i].polity < 60) count++;
}
cout << stu[i].name << " " << "有" << count << "门课挂科" << endl;
cout << "--------------------------------------------------------" << endl;
}
}
int main(){
Student* stu = new Student[STU_MAX];
Student StartUp;
while (1) //无限循环
{
int res = menu();
switch (res) //调用menu()函数
{
case 1:
StartUp.Input(stu);
break;
case 2:
StartUp.Statistic(stu);
break;
case 3:
StartUp.Lookup(stu);
break;
case 4:
StartUp.Modify(stu);
break;
case 5:
StartUp.Delete(stu);
break;
case 6:
StartUp.Sort(stu);
break;
case 7:
StartUp.Output(stu);
break;
case 8:
StartUp.Sling(stu);
break;
case 0:
cout << endl << "================感谢您使用学生成绩管理系统==============\n" << endl;
exit(0);
}
}
return 0;
}
开发环境:Windows
编辑器:clion
还没有评论,来说两句吧...