求大神指教 c++程序设计(学生评教系统)

//设计一个学生评教系统,系统主要处理学生评教的相关信息。

//其中,学生信息主要包括:学号、姓名、性别、联系电话等内容,

//教师信息主要包括:教师编号、教师名称、任教课程编号、任教课程名、评教成绩等内容,

//请按照以下的功能要求设计系统。

//【功能要求】

//(1)定义学生类、教师类、评教类;

//(2)输入:学生、教师、评教信息的录入;

//(3)输出:学生、教师、评教信息的输出;

//(4)编辑功能:可进对学生、教师、评教信息执行查询、修改、添加、删除等操作;

//(5)菜单功能:每种功能的操作都是在菜单中进行相应选择;

//(6)最好用文件保存信息数据。



#include<iostream>

#include<fstream>

#include<string.h>

#include<conio.h>              //用getch();

using namespace std;


//学生类

class student

{

public:

    char Id[20];

    char name[10];

    char sex[3];

long telephone;

student*Next;

//student(long xh,char nm[],char sx[],long tel)

//{

// xuehao=xh;

// strcpy(name, nm);

// strcpy(sex, sx);

// telephone = tel;

//}

void newstudent();

void input()

{

cout << "学号:"; cin >> Id;

cout << "姓名:"; cin >> name;

cout << "性别:"; cin >> sex;

cout << "电话:"; cin >> telephone;

}

void ReadFile(istream&in)

{

cin >> Id >> name >> sex >> telephone;

}

void show() const

{

cout << "学号" << Id;

cout << "姓名" << name;

cout << "性别" << sex;

cout << "电话" << telephone;

}

}newstudent;


//教师类

class teacher

{

public:

long teachernumber;

char name[10];

long classnumber;

char classname[10];

char commentperformance[100];


/*teacher(long tnum, char nm[], long cnum, char cnm[], char comper[])

{

teachernumber = tnum;

strcpy(name, nm);

classnumber = cnum;

strcpy(classname, cnm);

strcpy(commentperformance, comper);

}*/

void teacherinput()

{

cout << "教师编号:"; cin >> teachernumber;

cout << "教师名称:"; cin >> name;

cout << "任教课程编号:"; cin >> classnumber;

cout << "任教课程名:"; cin >> classname;

cout << "评教成绩:"; cin >> commentperformance;

}

void show() 

{

cout << "教师编号:"<< teachernumber;

cout << "教师名称:"<< name;

cout << "任教课程编号:"<<classnumber;

cout << "任教课程名:"<<classname;

cout << "评教成绩:"<<commentperformance;

}

};


//评教类

class commentsystem

{

public:

commentsystem();

~commentsystem();

void showmenu();

void showinformation();

void find();

void save();

void modifyinformation();

void removeinformation();

void swap(student*, student*);

void display()

{

for (student*p = Head->Next; p != End;p=p->Next)

p->show();

cout << "输入任意字符!继续……";

getch();

}

void addinformation()

{

End->input();

End->Next = newstudent();

End = End->Next;

cout << "添加成功!" << endl;

cout << "输入任意字符!继续……";

getch();

}

private:

student*Head, *End;

ifstream in;

ofstream out;

student*FindItem(char*name)

{

for (student*p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空

if (!strcmp(p->Next->name, name))return p;

return NULL;

}

student*FindID(char*Id)

{

for (student*p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空

if (!strcmp(p->Next->Id, Id))return p;

return NULL;

}

};


//构造函数

commentsystem::commentsystem()

{

Head = newstudent;

Head->Next = newstudent;

End = Head->Next;

in.open("D:/sort.txt");

if (!in)

cout << "这是一个新系统,无学生信息。请先输入。" << endl;

else

{

while (!in.eof())

{

End->ReadFile(in);

if (End->name[0] == '\0')break;

End->Next = newstudent;

End = End->Next;

}

in.close();

cout << "\t\t读取学生信息成功!" << endl;

}

}


//析构函数

commentsystem::~commentsystem()

{

save();

for (student*temp; Head->Next != End;)

{

temp = Head->Next;

Head->Next = Head->Next->Next;

delete temp;

}

delete Head, End;

}


//菜单

void commentsystem::showmenu()

{

cout << "^^^^^^^^^^学生评教系统^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^1.输入学生信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^2.输入教师信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^3.输入评教信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^4.查找信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^5.删除信息 ^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^6.修改信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^0.退出^^^^^^^^^^" << endl;

cout << "请选择:";

}


//查找函数

void commentsystem::find()

{

char name[20], Id[10];

int x;

student*p = NULL;

cout << "\n\t\t*********************************\n";

cout << "\t\t※1.按学生的姓名查找\n\t\t※2.按学生学号查找";

cout << "\n\t\t*********************************\n请选择:";

cin >> x;

switch (x)

{

case 1:{cout << "\t\t请输入要查找的学生的姓名:"; cin >> name;

if (p = FindItem(name))

{

p->Next->show();

cout << "输入任意字符!继续……";

getch();

}

else

{

cout << "\t\t没有找到该姓名的学生!" << '\n' << endl;

cout << "输入任意字符!继续……";

getch();

}

}break;

 case 2:

{

cout << "\t\t请输入要查找的学生的学号:"; cin >> Id;

if (p = FindID(Id))

{

p->Next->show();

cout << "输入任意字符!继续……";

getch();

}

else

{

cout << "\t\t没有找到该学好的学生!" << '\n' << endl;

cout << "输入任意字符!继续……";

getch();

}

}break;

default:cout << "输入有误";

}

}


//修改信息

void commentsystem::modifyinformation()//修改信息

{

char name[20];

student*p = NULL;

cout << "\t\t请输入要修改的人的姓名:"; cin >> name;

if (p = FindItem(name))

{

cout << "\t\t已找到学生的信息,请输入新的信息!" << endl;

p->Next->input();

cout << "修改成功!" << endl;

cout << "输入任意字符!继续……";

getch();

}

else

{

cout << "\t\t没有找到!" << endl;

cout << "输入任意字符!继续……";

getch();

}

}


//删除信息

void commentsystem::removeinformation()//删除信息

{

char name[20];

student*p = NULL, *temp = NULL;

cout << "\t\t请输入要删除的学生的姓名:" << endl; cin >> name;

if (p = FindItem(name))

{

temp = p->Next;

p->Next = p->Next->Next;

delete temp;

cout << "\t\t删除成功!" << endl;

cout << "输入任意字符!继续……";

getch();

}

else

{

cout << "\t\t没有找到!" << endl;

cout << "输入任意字符!继续……";

getch();

}

}


//保存函数

void commentsystem::save()

{

out.open("sort.txt");

for (student*p = Head->Next; p != End; p = p->Next)

out << p->name << "\t" << p->Id << "\t" << p->sex << "\t"

<< p->telephone << '\n';

out.close();

}


//主函数

int main()

{

int x, i = 0;

bool quit = false;

cout << "\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§" << endl;

for (i = 0; i<3; i++)

cout << "\t\t◎\t\t\t\t\t\t◎" << endl;

cout << "\t\t◎★★★★【欢迎进入学生成绩管理系统】★★★★◎" << endl;

for (i = 0; i<3; i++)

cout << "\t\t◎\t\t\t\t\t\t◎" << endl;

cout << "\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§\n" << endl;;

commentsystem Grade;

cout << "按任意键开始……";

getch();

while (!quit)

{

system("cls");

Grade.showmenu();

cin >> x;

switch (x)

{

case 0:quit = true; break;

case 1:Grade.addinformation(); break;

case 2:Grade.display(); break;

case 4:Grade.find(); break;

case 5:Grade.removeinformation(); break;

case 6:Grade.modifyinformation(); break;

default:cout << "输入有误";

}

}

return 0;

}


爱不凡
浏览 2969回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP