学生成绩管理系统
- 一、前言
- 二、系统介绍
- 头文件(CStudent.h)
- 2.源文件(实现函数)
- 3.源文件(测试函数)
- 4.运行截图
- 三、总结
一、前言
学生成绩管理系统的设计,可以更好地帮助学习c++的初学者掌握基础知识。因此,小编将带领大家一起使用c++实现学生成绩管理系统,本文就介绍了一些相关的代码。
二、系统介绍
学生类CStudent,该类有以下几个私有成员变量:学生姓名、学号和性别和三门课的成绩。有实现下述功能的成员函数:
1)初始化学生姓名、学号、性别和年龄;
2)输入四门课的成绩,并计算平均成绩和总成绩;
3)输出学生信息。
以CStudent类为基础设计开发一个学生成绩管理系统。具有以下功能:
(1)运行程序后显示以下操作信息:
1、Display all information
2、Add a student
3、Delete a student
4、Quit
(2)按1后输出所有学生的所有信息,输出的信息包括: 姓名、学号、性别、和三门课的成绩、平均成绩和总成绩;并在最后计算每一门课程的平均成绩。
(3)按2选择增加学生信息。姓名、学号、性别、和三门课的成绩(在程序中可以事先初始化几个学生信息)。
(4)按3删除学生信息,根据输入学号删除对应的学生信息,学号从0依次往后排,当删除中间的学生信息后,将该序号后的学生信息依次往前移。
(5)每次处理完之后继续显示操作信息,可以再次按键进行操作。
(6)按4退出程序。
头文件(CStudent.h)
#include <string>
using namespace std;
class CStudent
{
private:
string name = "Null";
char sex = 'N';
int all = 0;
double averge = 0.0;
public:
int num = 0;
int chinese = 0;
int math = 0;
int english = 0;
void ShowStudent();
void CountAll();
void CountAverge();
void SetStudent();
CStudent(string name, int num, char sex, int chinese, int math, int english);
CStudent() {};
};
2.源文件(实现函数)
#include <string>
#include"CStudent.h"
#include <iostream>
using namespace std;
void CStudent::ShowStudent()
{
cout << "姓名:" << name << " 学号:" << num << " 性别:" << sex << " 语文:" << chinese << " 数学:" << math << " 英语:" << english << " 总分:" << all << " 平均分:" << averge << endl;
}
void CStudent::CountAll()
{
all = chinese + math + english;
}
void CStudent::CountAverge()
{
averge = all / 3;
}
void CStudent::SetStudent()
{
cout << "请依次输入学生的姓名、学号、性别、语文成绩、数学成绩和英语成绩" << endl;
cin >> name >> num >> sex >> chinese >> math >> english;
CountAll(); CountAverge();
}
CStudent(string name, int num, char sex, int chinese, int math, int english)
{
this->name = name;
this->num = num;
this->sex = sex;
this->chinese = chinese;
this->math = math;
this->english = english;
}
3.源文件(测试函数)
#include <string>
#include"CStudent.h"
#include <iostream>
using namespace std;
int main()
{
CStudent stu[10];
stu[0] = { "LiMing",356,'m',85,78,63 };
stu[1] = { "Marry",357,'w',98,99,87 };
stu[2] = { "Whister",358,'w',56,98,56 };
stu[0].CountAll(); stu[0].CountAverge();
stu[0].CountAll(); stu[0].CountAverge();
stu[0].CountAll(); stu[2].CountAverge();
int sum = 3;
for (int i = 0; i < 10000; i++)
{
cout << "1、Display all information" << endl
<< "2、Add a student" << endl
<< "3、Delete a student" << endl
<< "4、Quit" << endl;
cout << "请输入你想要运行的功能:";
int n;
cin >> n;
if (n == 1)
{
cout << "学生信息如下" << endl;
for(int j = 0;j < sum;j++)
{
stu[j].ShowStudent();
}
int CAll = 0;
int MAll = 0;
int EAll = 0;
for (int f = 0; f < sum; f++)
{
CAll += stu[f].chinese;
MAll += stu[f].math;
EAll += stu[f].english;
}
double CAverge = CAll / sum;
double MAverge = MAll / sum;
double EAverge = EAll / sum;
cout << "语文平均分: " << CAverge << " 数学平均分: " << MAverge << " 英语平均分: " << EAverge << endl;
cout << "返回主菜单请按'*',按任意键退出程序" << endl;
char g;
cin >> g;
if (g == '*')
continue;
else
break;
}
if (n == 2)
{
stu[sum].SetStudent();
sum++;
cout << "添加成功!" << endl;
cout << "返回主菜单请按'*', 按任意键退出程序" << endl;
char f;
cin >> f;
if (f == '*')
continue;
else
break;
}
if (n == 3)
{
cout << "请输入你想要删除的学生学号:";
int s;
cin >> s;
int z = -1;
for (int w = 0; w < sum; w++)
{
if (s == stu[w].num)
{
z = w;
break;
}
else
continue;
}
if (z == -1)
{
cout << "学生不存在!" << endl;
}
else
{
for (int k = z; k < sum; k++)
{
stu[k] = stu[k + 1];
}
sum--;
cout << "删除成功!" << endl;
}
cout << "返回主菜单请按'*',按任意键退出程序" << endl;
char r;
cin >> r;
if (r == '*')
continue;
else
break;
}
if (n == 4)
{
cout << "已退出" << endl;
break;
}
}
return 0;
}
4.运行截图
三、总结
以上就是今天要讲的内容,本文仅仅简单实现了学生管理系统,代码仅供大家参考,感谢!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)