高分求搞定一个C++的问题 搞定后追加1000分
一、定义学生(student)类,其中至少包括姓名、性别、学号、班级和两门功课的成绩。二、实现下面的功能
1、设计菜单实现功能选择;
2、输入功能:输入学生信息,并保存到文件中;
3、计算每个学生的总分与平均分并排序
4、能根据学号修改学生信息
5、能根据学号删除学生信息
6、查询功能:
1)能够根据学号查询学生信息;
2)能够根据姓名、班级查询学生信息
3)统计学生成绩,按照班级和科目计算平均分。
答案:只实现了一部分, 输入信息并存储到文件中,根据学号查找, 根据学号删除,计算平局分和总分。没有全部实现完。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Student
{
public:
string m_Name;
string m_Gender;
int m_ID;
int m_Class;
int m_Score1;
int m_Score2;
double m_Sum;
double m_Avg;
public:
Student();
~Student(){};
public:
void InitStuInfo();
void Display();
};
Student::Student()
: m_Name("")
, m_Gender("")
, m_ID(0)
, m_Class(0)
, m_Score1(0)
, m_Score2(0)
, m_Sum(0.0)
, m_Avg(0.0)
{
}
// 录入学生信息
void Student::InitStuInfo()
{
cout << "姓名:"; cin >> m_Name;
cout << "性别:"; cin >> m_Gender;
cout << "学号:"; cin >> m_ID;
cout << "班级:"; cin >> m_Class;
cout << "课程1成绩:"; cin >> m_Score1;
cout << "课程2成绩:"; cin >> m_Score2;
m_Sum = m_Score1 + m_Score2;
m_Avg = m_Sum / 2;
}
void Student::Display()
{
cout << "姓名:"; cout << m_Name << endl;
cout << "性别:"; cout << m_Gender << endl;
cout << "学号:"; cout << m_ID << endl;
cout << "班级:"; cout << m_Class << endl;
cout << "课程1成绩:"; cout << m_Score1 << endl;
cout << "课程2成绩:"; cout << m_Score2 << endl;
cout << "总成绩:", cout << m_Sum << endl;
cout << "平均分:", cout << m_Avg << endl;
cout << endl << endl;
}
// 存储所有学生的信息链表
vector<Student*> g_StuList;
// 添加新的学生
void AddNewStudent()
{
cout << "录入学生信息..." << endl;
Student* pStu = new Student;
pStu->InitStuInfo();
g_StuList.push_back(pStu);
cout << endl << endl;
}
// 将信息存储到文件中
void SaveStuInfo()
{
FILE* pFile = NULL;
Student* pStu = NULL;
string fName;
cout << "输入文件名:";
cin >> fName;
pFile = fopen(fName.data(), "wt");
for (int i = 0; i < g_StuList.size(); i++)
{
pStu = g_StuList.at(i);
fprintf(pFile, "姓名:%s\n", pStu->m_Name.data());
fprintf(pFile, "性别:%s\n", pStu->m_Gender.data());
fprintf(pFile, "学号:%d\n", pStu->m_ID);
fprintf(pFile, "班级:%d\n", pStu->m_Class);
fprintf(pFile, "课程1成绩:%d\n", pStu->m_Score1);
fprintf(pFile, "课程2成绩:%d\n", pStu->m_Score2);
fprintf(pFile, "总成绩:%.2f\n", pStu->m_Sum);
fprintf(pFile, "平均分:%.2f\n", pStu->m_Avg);
}
fclose(pFile);
}
// 查询学生
void FindStudent()
{
int ID;
cout << "输入要查询的ID:";
cin >> ID;
int i;
for (i = 0; i < g_StuList.size(); i++)
{
if (g_StuList.at(i)->m_ID == ID)
{
g_StuList.at(i)->Display();
break;
}
}
if (i == g_StuList.size())
{
cout << "没有找到!!" << endl;
}
}
// 删除学生
void DeleteStudent()
{
int ID;
cout << "输入要删除的ID:";
cin >> ID;
vector<Student*>::iterator iter;
for (iter = g_StuList.begin(); iter != g_StuList.end(); iter++)
{
if ((*iter)->m_ID == ID)
{
cout << "要删除的学生信息:" << endl;
(*iter)->Display();
delete((*iter));
g_StuList.erase(iter);
break;
}
}
if (iter == g_StuList.end())
{
cout << "没有找到!!" << endl;
}
}
// 释放空间
void ReleaseMemory()
{
while (g_StuList.empty())
{
delete(g_StuList.back());
g_StuList.pop_back();
}
}
int main(int argc, char* argv[])
{
for (int i = 0; i < 2; i++)
{
AddNewStudent();
}
SaveStuInfo();
return(0);
}你去网上找个档案管理好拉,我还以为是很特别呢,现在网上一搜就有学到什么程度,标志着C++基础已经学完
下一个:VB删除控件代码