"Couse.h"
#ifndef COURSE_H
#define COURSE_H
#include
<string>
#include
<iostream>
#include
<iomanip>
#include
<fstream>
#include
<vector>
using namespace std;
class Course{
private:
string courseName;
double score;
bool isBixiu;

public:

Course
*next;
//构造函数
Course(string nameVal,double scoreVal,bool isVal,Course *nextVal = NULL);
Course(Course
* nextVal = NULL);

void setCourseName(string );
void setScore(double );
void setIsBixiu(bool);
bool getIsBixiu();
string getCourseName();
double getScore();
};
#endif

 

//"deleteStudent.cpp"
#include"record.h"

bool VerifyDelete();

void Record::deleteStudent(){
/*system("cls");
char search_string[20];
current_ptr = head_ptr;
if(current_ptr ==NULL){
cout<<"没有要删除的记录"<<endl;
return;
}
cin.getline(search_string,20);
int flag = 0;
cout<<"\n输入您要删除的名字:";
cin.getline(search_string,20);
while(current_ptr!=NULL&&flag == 0){
if(current_ptr->getName()==search_string){

if(flag==0)cout<<"找到记录 !"<<endl;
cout<<current_ptr->getName()<<"\t\t"<<current_ptr->getID()<<endl;
flag = 1;
if(VerifyDelete()){
cout<<current_ptr->getName()<<"\t"<<current_ptr->getID()<<"\t记录已经删除\n";
DeleteNode();
getPause();
}
else
cout<<current_ptr->getName()<<"\t"<<current_ptr->getID()<<"\t该记录未删除"<<endl;
getPause();
}
else//如果删除该记录,current_ptr会自动向下跳一格
current_ptr = current_ptr->next;
}
if(flag == 0)
cout<<"该记录不存在,请核实后继续操作 !"<<endl;
*/
system(
"cls");
cout
<<endl<<" -----------删除学生信息---------"<<endl<<endl;
cout
<<" ****************************"<<endl;
cout
<<" ******* 1_按姓名查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 2_按学号查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 3_返回主菜单 *******"<<endl;
cout
<<" ****************************"<<endl;
cout
<<"\n 请选择:";
string choice;
cin
>>choice;
if(choice=="1")this->searchByName();
else if(choice=="2")this->searchByID();
else if(choice=="3")this->mainPage();
else {
error();
return ;
}
if(VerifyDelete())
DeleteNode();
cout
<<"\n信息已经成功删除。"<<endl;
getPause();
}
bool VerifyDelete(){
string yesno;
cout
<<"\n是否要删除 ?(y/n)";
cin
>>yesno;
if(yesno == "y" )
return 1;
else if(yesno =="n")
return 0;
else {
char pause;
cout
<<"\n输入有误。"<<endl;
cout
<<"\n按任意键继续..."<<endl;
cin.
get(pause);
cin.ignore(
1,pause);
system(
"cls");
return 0;
}
}

void Record::DeleteNode(){
if(current_ptr == head_ptr)
DeleteNodeAtHead();
//在表头删除
else{
if(current_ptr->next == NULL)
DeleteNodeAtEnd();
//在表尾删除
else
DeleteNodeAtMiddle();
//在链表中部删除
}
}

void Record::DeleteNodeAtHead(){
if(head_ptr->next ==NULL){//如果只有头结点
delete head_ptr;
head_ptr
= tail_ptr = current_ptr = NULL;
return;
}
head_ptr
= head_ptr->next;
head_ptr
->prior = NULL;
delete current_ptr;
current_ptr
= head_ptr;
return;
}
void Record::DeleteNodeAtEnd(){
tail_ptr
= tail_ptr->prior;
tail_ptr
->next = NULL;
delete current_ptr;
current_ptr
= NULL;
return;
}
void Record::DeleteNodeAtMiddle(){
Student
*temp_ptr;
temp_ptr
= current_ptr;
current_ptr
= current_ptr->next;//删除完自动跳到下一结点
temp_ptr->prior->next = current_ptr;
current_ptr
->prior = temp_ptr ->prior;
delete temp_ptr;
return;
}

 

 

//“Student.h 文件”
#ifndef STUDENT_H
#define STUDENT_H
#include
"course.h"
class Student{
private:
string name;
string ID;

public:
//文档信息
string sex;
string phone;
string birthday;
string reword;
string punishment;
string activity;
string hobby;

//统计信息成员变量(暂且定义为public,简化代码。)
double total;
double ave;
int unpassed;
int courseNum;
bool needUpdate;

Course
* head;
Course
* tail;
Course
* fence;//使用教材中的定义
//学生条目的存储使用双向链表实现
Student* next;//指向上一个学生
Student* prior;//指向后一个学生
Student();//构造函数
void setName(string valName);
void setID(string setID);
string getName();
string getID();

//与课程添加删除相关的函数声明
//课程信息用单向量表实现
void clear();//清空学生的所有课程信息
void setStart();//指针置前
void setEnd();
void nextItem();
bool getValue(string& name,double& score,bool& is);
bool insert(string name,double score,bool is);
bool remove(string &name,double &score,bool& is);
void pre();
bool setPos(string name);
void print();
bool find(string name);

};
#endif

 

//"main.cpp"
#include"record.h"
Record myrecord;
int main(){

myrecord.head_ptr
= NULL;
myrecord.tail_ptr
= NULL;

myrecord.loadCourse();
//将该班级的必修课程科目载入数组Bixiu[string] 中,之后有用
if(myrecord.loadFile())
myrecord.mainPage();
else {
cout
<<"\n没有导入文件,退出。"<<endl;
myrecord.getPause();
}
return 0;
}

void Record::mainPage(){
string choice;
do{
system(
"cls");
cout
<<" ***************欢迎使用《学生管理系统1.0》**************"<<endl<<endl;
cout
<<" --------------------------------------------------------"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | 1_增加学生信息 | 6_屏幕显示 |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | 2_删除学生信息 | 7_搜索信息 |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | 3_增加课程信息 | 8_打印输出 |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | 4_删除课程信息 | 9_信息修改 |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | 5_计算统计信息 | 0_退出程序 |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" | | |"<<endl;
cout
<<" --------------------------------------------------------"<<endl;
cout
<<"\n 请进行选择:";
cin
>>choice;
myrecord.userChoice(choice);
//处理选择
}while(choice!="0");
}
"Record.h 文件"
#ifndef RECORD_H
#define RECORD_H
#include
"student.h"
class Record{
public:
Student
* head_ptr;
Student
* tail_ptr;
Student
* current_ptr;
vector
<string>Bixiu; //暂存的必修课程名称
char pause;
string className;

void userChoice(string choice);//用户选择函数
void insertStudent(); //插入学生信息函数
void deleteStudent(); //删除学生信息
void insertCourse(); //添加课程
void deleteCourse(); //删除课程
void inputScore(); //输入课程分数
void calculate(); //计算统计
void list(); //列表显示
bool search(); //信息搜索
void sort(); //信息排序
bool loadFile(); //文件载入
void saveFile(); //文件存储
void modify(); //信息修改
void outputTXT(); //txt文档输出



void insertNode(Student *); //插入结点子函数声明
void InsertNodeAtHead(Student* new_ptr);//插入表头的子函数声明
void InsertNodeAtEnd(Student* new_ptr); //插入表尾的子函数声明

void DeleteNode(); //删除链表结点
void DeleteNodeAtHead(); //在表头删除
void DeleteNodeAtEnd(); //在表尾删除
void DeleteNodeAtMiddle(); //在链表中部删除

//查找辅助子函数
bool searchByName();
bool searchByID();

//插入辅助子函数
void insertXuanxiu();
void insertBixiu();
void insertSingleBixiu();

//删除辅助子函数
void deleteXuanxiu();
void deleteBixiu();

//显示辅助子函数
void comuCOUT();
void studentCOUT();
void courseCOUT();
void error();
void listOUT();
void getPause();
bool requireList();
void listSingle();

//文档输出辅助子函数
void comuTXT();
void paperTXT();
void courseTXT();
void docTXT();
void listTXT();

//统计计算辅助子函数
void calForEach();//每一名学生的成绩信息统计
void calForCourse();

//控制辅助子函数
void mainPage();
bool onlyNumber(string PhoneNumber);
bool onlySex(string sex);
void fileInput();

//修改辅助函数
void modifyDetail();
void modifyDoc();
void modifyCourse();

//初始化辅助函数
void loadCourse();//将该班级的必修课程科目载入数组Bixiu[string] 中

void fileOutput();

void zero();//成绩统计清零
};
#endif

//"calculate.cpp "
#include"record.h"
void Record::calculate(){
string choice;
system(
"cls");
cout
<<endl<<" ----------------计算统计信息-----------------"<<endl<<endl;
cout
<<" *********************************************"<<endl;
cout
<<" ****** 1_对某个学生成绩信息进行计算统计******"<<endl;
cout
<<" ****** ******"<<endl;
cout
<<" ****** 2_对某门课程成绩信息进行计算统计******"<<endl;
cout
<<" ****** ******"<<endl;
cout
<<" ****** 3_返回主界面 ******"<<endl;
cout
<<" *********************************************"<<endl;
cout
<<"\n 请输入选择:";
cin
>>choice;
if(choice == "1"){
system(
"cls");
cout
<<" ----对某个学生成绩信息进行计算统计----"<<endl;
cout
<<" **************************"<<endl;
cout
<<" *****1_按学生姓名查找*****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" *****2_按学生学号查找*****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" *****3_返回上一界面 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" *****4_返回主界面 *****"<<endl;
cout
<<" **************************"<<endl;
cout
<<"\n 请选择:";
string choice;
cin
>>choice;
if(choice=="1"){
if(searchByName()){
system(
"cls");
this->calForEach();
cout
<<"**************************************************************"<<endl<<endl;
//cout<<left<<setw(20)<<current_ptr->getName()<<setw(20)<<current_ptr->getID()<<endl;
cout<<"姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl;
cout
<<endl<<" ---------------该同学的课程信息如下------------"<<endl;
current_ptr
->print();
cout
<<endl<<" 该学生所修科目总数:"<<current_ptr->courseNum<<" 不及格总数:"<<current_ptr->unpassed<<endl;
cout
<<"\n 该学生的总成绩为:"<<current_ptr->total<<" 平均成绩为:"<<current_ptr->ave<<endl;
cout
<<endl<<endl;
}
}
else if(choice == "2"){
if(searchByID()){
system(
"cls");
this->calForEach();
cout
<<"**************************************************************"<<endl<<endl;
//cout<<left<<setw(20)<<current_ptr->getName()<<setw(20)<<current_ptr->getID()<<endl;
cout<<"姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl;
cout
<<endl<<" ---------------该同学的课程信息如下------------"<<endl;
current_ptr
->print();
cout
<<endl<<" 该学生所修科目总数:"<<current_ptr->courseNum<<" 不及格总数:"<<current_ptr->unpassed<<endl;
cout
<<"\n 该学生的总成绩为:"<<current_ptr->total<<" 平均成绩为:"<<current_ptr->ave<<endl;
cout
<<endl<<endl;
}
}
else if(choice=="3") calculate();
else if(choice=="4") mainPage();
else {
error();
return;
}
}
else if(choice =="2"){
calForCourse();
}
else if(choice=="3")mainPage();
else {
error();
return;
}
}
void Record::calForCourse(){
string tempName;
cout
<<"\n输入进行成绩查询的课程名称:";
cin
>>tempName;

int studentNum = 0;
double total = 0;
double max = 0;
double min = 100;
double ave = 0;
int unpassed = 0;
bool isVal=false;
double rate = 0.0;
bool isHasStudent = false;

current_ptr
=head_ptr;
while(current_ptr!=NULL){
if(current_ptr->find(tempName)){
isHasStudent
= true;
cout
<<endl<<"********"<<current_ptr->getName()<<" "<<current_ptr->fence->next->getScore()<<"********"<<endl;
isVal
= current_ptr->fence->next->getIsBixiu();
studentNum
++;//选课人数统计
double tempScore = current_ptr->fence->next->getScore();
if(tempScore<60)unpassed++;//不及格人数统计
total+=tempScore;//总分数统计
if(tempScore<min)min = tempScore;//最低成绩统计
if(tempScore>max)max = tempScore;//最高成绩统计
ave = total/(double)studentNum;//平均成绩统计
rate = (double)(studentNum-unpassed)/studentNum;//及格率计算

}
current_ptr
= current_ptr->next;
}
if(isHasStudent){
cout
<<"\n 课程名称:"<<tempName<<" 课程属性:";
if(isVal)cout<<"必修课"<<endl;
else cout<<"选修课"<<endl;
cout
<<"\n选课人数:"<<studentNum<<" 未通过人数:"<<unpassed<<" 及格率:"<<rate*100<<"%"<<endl;
cout
<<"\n最高分数为:"<<max<<" 最低分数为:"<<min<<" 平均分数为:"<<ave<<endl;

getPause();
}
else {
cout
<<"\n该班级没有一个人选择该课程。"<<endl;
getPause();
}

}
void Record::calForEach(){
zero();
current_ptr
->fence = current_ptr->head;
while(current_ptr->fence->next != NULL){
current_ptr
->courseNum++; //课程总数统计
current_ptr->total+=current_ptr->fence->next->getScore(); //总分相加
if(current_ptr->fence->next->getScore()<60) //不及格科目统计
current_ptr->unpassed++;
current_ptr
->fence = current_ptr->fence->next;
}
current_ptr
->ave = current_ptr->total/(double)current_ptr->courseNum;//平均分统计

}
void Record::zero(){
current_ptr
->total = 0;
current_ptr
->courseNum = 0;
current_ptr
->unpassed = 0;
}

 

//"course.cpp"
#include"course.h"

Course::Course(
string nameVal,double scoreVal,bool isVal,Course* nextVal){
courseName
= nameVal;
score
= scoreVal;
isBixiu
= isVal;
next
= nextVal;
}
Course::Course(Course
* nextVal){
next
= nextVal;
}
void Course::setCourseName(string valName){
courseName
= valName;
}
void Course::setScore(double valScore){
score
= valScore;
}
string Course::getCourseName(){
return courseName;
}
double Course::getScore(){
return score;
}
void Course::setIsBixiu(bool isVal){
isBixiu
= isVal;
}
bool Course::getIsBixiu(){
return isBixiu;
}

 

//"deleteCourse.cpp"
#include"record.h"
void Record::deleteCourse(){
system(
"cls");
string choice;
system(
"cls");
cout
<<endl<<" -------------课程删除----------------"<<endl<<endl;
cout
<<" *************************************"<<endl;
cout
<<" *********** 1_删除必修课程 **********"<<endl;
cout
<<" *********** **********"<<endl;
cout
<<" *********** 2_删除选修课程 **********"<<endl;
cout
<<" *********** **********"<<endl;
cout
<<" *********** 3_返回主菜单 **********"<<endl;
cout
<<" *************************************"<<endl;
cout
<<" 请选择:";
cin
>>choice;
if(choice == "1") deleteBixiu();
else if(choice =="2") deleteXuanxiu();
else if(choice=="3")mainPage();
else {
error();
return;
}
}
void Record::deleteBixiu(){
string search_string;
cout
<<"\n请输入要删除的课程的名称:";
cin
>>search_string;
current_ptr
= head_ptr;
while(current_ptr!=NULL){
if(current_ptr->find(search_string)&&current_ptr->fence->next != NULL){
if(!current_ptr->fence->next->getIsBixiu()){//判断该课程是否为必修
cout<<"\n该课程为选修课程,请重新进行正确的选择。"<<endl;
return;
}
string tempName;
double tempScore;
bool tempIs;
current_ptr
->remove(tempName,tempScore,tempIs);
cout
<<"\n"<<current_ptr->getName()<<""<<tempName<<"课程已经删除 "<<endl;
}
current_ptr
= current_ptr->next;
}
getPause();

}
void Record::deleteXuanxiu(){
if(searchByName()){
string search_string;
cout
<<"\n请输入要删除的课程的名称:";
cin
>>search_string;
if(current_ptr->find(search_string)&&current_ptr->fence->next != NULL){
if(current_ptr->fence->next->getIsBixiu()){//判断该课程是否为选修
cout<<"\n该课程为必修课程,不能对给别学生进行课程删除操作。"<<endl;
getPause();
return;
}
string tempName;
double tempScore;
bool tempIs;
current_ptr
->remove(tempName,tempScore,tempIs);
cout
<<endl<<current_ptr->getName()<<""<<tempName<<"已经删除成功 "<<endl;
getPause();
return;
}
}
getPause();
return;

}

 

//"fileIO.cpp"
#include"record.h"

void Record::outputTXT(){
string choice;
system(
"cls");
cout
<<endl<<" ---------------打印输出------------------"<<endl<<endl;
cout
<<" *******************************************"<<endl;
cout
<<" ******* 1_全部学生基本信息文档输出 ********"<<endl;
cout
<<" ******* ********"<<endl;
cout
<<" ******* 2_全部学生通讯录文档输出 ********"<<endl;
cout
<<" ******* ********"<<endl;
cout
<<" ******* 3_单个学生成绩单文档输出 ********"<<endl;
cout
<<" ******* ********"<<endl;
cout
<<" ******* 4_单科成绩信息文档输出 ********"<<endl;
cout
<<" ******* ********"<<endl;
cout
<<" ******* 5_单个学生档案文件输出 ********"<<endl;
cout
<<" ******* ********"<<endl;
cout
<<" ******* 6_返回主菜单 ********"<<endl;
cout
<<" *******************************************"<<endl;
cout
<<" 请选择:";
cin
>>choice;
if(choice=="1")
listTXT();
else if(choice=="2")
comuTXT();
else if(choice=="3")
paperTXT();
else if(choice=="4")
courseTXT();
else if(choice=="5")
docTXT();
else if(choice=="6")
mainPage();
else
error();
}
void Record::listTXT(){
ofstream outfile;
string fileName;
fileName
= this->className+"班级基本信息表.txt";
outfile.open(fileName,ios::
out);
if(outfile){
current_ptr
= head_ptr;
if(head_ptr ==NULL){
cout
<<"记录为空,还未添加记录 !"<<endl;
return;
}
this->loadCourse();//将该班级的必修课程科目载入数组Bixiu[string] 中
//system("cls");
outfile<<"*********************全部学生基本信息列表**********************"<<endl<<endl;
outfile
<<"|"<<setw(8)<<"姓名"<<setw(4)<<"|"<<setw(8)<< "学号"<<setw(4)<<"|";
for(int i=0;i<Bixiu.size();i++)
outfile
<<setw(8)<<Bixiu[i]<<setw(4)<<"|";
outfile
<<endl<<endl;
do{
this->calForEach();//调用函数对该学生的成绩进行统计
outfile<<"|"<<setw(8)<<current_ptr->getName()<<setw(4)<<"|"<<setw(8)<<current_ptr->getID()<<setw(4)<<"|";
for(int i=0;i<Bixiu.size();i++){
current_ptr
->find(Bixiu[i]);
outfile
<<setw(8)<<current_ptr->fence->next->getScore()<<setw(4)<<"|";
}
outfile
<<endl;
current_ptr
=current_ptr->next;
}
while(current_ptr!=NULL);
cout
<<"\n文件生成成功。"<<endl;
getPause();
return;
}
else cout<<"\n文件生成失败。"<<endl;
}
void Record::comuTXT(){
ofstream outfile;
string fileName;
fileName
= this->className+"班级同学录.txt";
outfile.open(fileName,ios::
out);
if(outfile){
int i=1;
current_ptr
= head_ptr;
do{

outfile
<<endl<<""<<i<<"个同学"<<endl;
outfile
<<"**************************************************************"<<endl<<endl;
outfile
<<"姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl;

outfile
<<endl<<" ---------------该生的文档信息如下--------------"<<endl;
outfile
<<"\n性别:"<<current_ptr->sex<<" 电话号码:"<<current_ptr->phone<<" 爱好:"<<current_ptr->hobby<<endl;
outfile
<<"\n该生曾经参加过的活动:"<<current_ptr->activity<<endl;
outfile
<<"\n该生曾经获得过的奖励:"<<current_ptr->reword<<endl;
outfile
<<"\n该生曾经获得过的惩罚:"<<current_ptr->punishment<<endl;

current_ptr
= current_ptr->next;
i
++;
}
while(current_ptr!=NULL);
cout
<<"\n文件创建成功。"<<endl;
}
else{
cout
<<"\n文件创建失败,或者建立失败 !"<<endl;
return;
}

getPause();

}
void Record::paperTXT(){
if(searchByName()){
cout
<<"是否要生成该学生的成绩单文件?(y/n)"<<endl;
cout
<<"请输入:";
string x;
cin
>>x;
if(x == "n"){
getPause();
return ;
}
else if(x =="y"){
ofstream outfile;
string fileName;
fileName
= current_ptr->getName()+"成绩单文件.txt";
outfile.open(fileName,ios::
out);
if(outfile){
outfile
<<endl<<" ---------------该同学的课程信息如下------------"<<endl;
outfile
<<endl<<" 姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl<<endl;
current_ptr
->fence = current_ptr->head;
if(current_ptr->fence->next == NULL) outfile<<"该同学目前还未选择任何课程 !"<<endl;

else while(current_ptr->fence->next != NULL){
outfile
<<" "<<left<<setw(20)<<current_ptr->fence->next->getCourseName()<<setw(20)
<<current_ptr->fence->next->getScore();
if(current_ptr->fence->next->getIsBixiu())outfile<<setw(20)<<"必修课"<<endl;
else outfile<<setw(20)<<"选修课"<<endl;
current_ptr
->fence = current_ptr->fence->next;
}
outfile
<<endl<<"\n 该学生所修科目总数:"<<current_ptr->courseNum<<" 不及格总数:"<<current_ptr->unpassed<<endl;
outfile
<<"\n 该学生的总成绩为:"<<current_ptr->total<<" 平均成绩为:"<<current_ptr->ave<<endl;
outfile
<<endl<<endl;
}
else{
cout
<<"\n文件创建失败,或者建立失败 !"<<endl;
getPause();
return;
}

}
else {
error();
return ;
}
}
cout
<<"文档建立成功。"<<endl;
getPause();
}

void Record::courseTXT(){string tempName;
cout
<<"\n输入进行成绩查询的课程名称:";
cin
>>tempName;
ofstream outfile;
string fileName;
fileName
= className+tempName+"成绩单文件.txt";
outfile.open(fileName,ios::
out);
if(outfile){
int studentNum = 0;
double total = 0;
double max = 0;
double min = 100;
double ave = 0;
int unpassed = 0;
bool isVal;
double rate;


outfile
<<"*************"<<tempName<<"成绩单************"<<endl;
current_ptr
=head_ptr;
while(current_ptr!=NULL){
if(current_ptr->find(tempName)){
outfile
<<current_ptr->getName()<<" "<<current_ptr->fence->next->getScore()<<endl;
isVal
= current_ptr->fence->next->getIsBixiu();
studentNum
++;//选课人数统计
double tempScore = current_ptr->fence->next->getScore();
if(tempScore<60)unpassed++;//不及格人数统计
total+=tempScore;//总分数统计
if(tempScore<min)min = tempScore;//最低成绩统计
if(tempScore>max)max = tempScore;//最高成绩统计
ave = total/(double)studentNum;//平均成绩统计
rate = (double)(studentNum-unpassed)/studentNum;//及格率计算
}
current_ptr
= current_ptr->next;
}
outfile
<<"\n课程属性:";
if(isVal)outfile<<"必修课"<<endl;
else outfile<<"选修课"<<endl;
outfile
<<"\n选课人数:"<<studentNum<<" 未通过人数:"<<unpassed<<" 及格率:"<<rate<<endl;
outfile
<<"\n最高分数为:"<<max<<" 最低分数为:"<<min<<" 平均分数为:"<<ave<<endl;
cout
<<"\n单科成绩单文件输出成功。"<<endl;
getPause();
return ;
}
else
cout
<<"\n文件创建失败,或者建立失败 !"<<endl;
getPause();
}
void Record::docTXT(){
if(searchByName()){
cout
<<"\n是否要生成该学生的档案文件?(y/n)"<<endl;
cout
<<"\n请输入:";
string x;
cin
>>x;
if(x == "n"){
getPause();
return ;
}
else if(x =="y"){
ofstream outfile;
string fileName;
fileName
= current_ptr->getName()+"档案文件.txt";
outfile.open(fileName,ios::
out);
if(outfile){
outfile
<<"**************************************************************"<<endl<<endl;
outfile
<<"姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl;

outfile
<<endl<<"---------------该生的文档信息如下--------------"<<endl<<endl;
outfile
<<"\n性别:"<<current_ptr->sex<<" 电话号码:"<<current_ptr->phone<<" 爱好:"<<current_ptr->hobby<<endl;
outfile
<<"\n该生曾经参加过的活动:"<<current_ptr->activity<<endl;
outfile
<<"\n该生曾经获得过的奖励:"<<current_ptr->reword<<endl;
outfile
<<"\n该生曾经获得过的惩罚:"<<current_ptr->punishment<<endl;
}
else{
cout
<<"\n文件创建失败,或者建立失败 !"<<endl;
getPause();
return;
}
}
else {
error();
return ;
}
}
cout
<<"文档创建成功。"<<endl;
getPause();
return ;
}

void Record::fileOutput(){
cout
<<"\n性别:"<<current_ptr->sex<<" 电话号码:"<<current_ptr->phone<<" 爱好:"<<current_ptr->hobby<<endl;
cout
<<"\n该生曾经参加过的活动:"<<current_ptr->activity<<endl;
cout
<<"\n该生曾经获得过的奖励:"<<current_ptr->reword<<endl;
cout
<<"\n该生曾经获得过的惩罚:"<<current_ptr->punishment<<endl;
}

 

//"init.cpp"
#include"record.h"
void Record::loadCourse(){//将该班级的必修课程科目载入数组Bixiu[string] 中
this->Bixiu.clear();
if(head_ptr != NULL){
head_ptr
->fence = head_ptr->head;
while(head_ptr->fence->next != NULL){
if(head_ptr->fence->next->getIsBixiu())
this->Bixiu.push_back(head_ptr->fence->next->getCourseName());
head_ptr
->fence = head_ptr->fence->next;
}
}
}

bool Record::onlyNumber(string numbers){
bool isOnly = true;
for(int i=0;i<numbers.size();i++){
if(numbers[i]<'0'||numbers[i]>'9'){
isOnly
= false;
break;
}
}
return isOnly;
}

bool Record::onlySex(string sex){
if(sex==""||sex=="")
return true;
else
return false;
}

 

//"inputScore.cpp"
#include"record.h"
void Record::inputScore(){
double tempScore;
cout
<<"\n\n请输入"<<current_ptr->getName()<<"同学的"<<current_ptr->fence->next->getCourseName()<<"成绩:";
cin
>>tempScore;
current_ptr
->fence->next->setScore(tempScore);
/*cout<<endl<<"\n成绩输入完毕。"<<endl;
cout<<setw(20)<<current_ptr->fence->next->getCourseName()<<setw(20)<<current_ptr->fence->next->getScore();
if(current_ptr->fence->getIsBixiu())cout<<setw(20)<<"必修课"<<endl;
else cout<<setw(20)<<"选修课"<<endl<<endl;
*/
}

 

//"insertCourse.cpp"
#include"record.h"

void inputMes();
void Record::insertCourse(){
string choice;
system(
"cls");
cout
<<endl<<" ------------增加课程---------------"<<endl<<endl;
cout
<<" ***********************************"<<endl;
cout
<<" ********** 1_添加必修课程 *********"<<endl;
cout
<<" ********** *********"<<endl;
cout
<<" ********** 2_添加选修课程 *********"<<endl;
cout
<<" ********** *********"<<endl;
cout
<<" ********** 3_返回主菜单 *********"<<endl;
cout
<<" ***********************************"<<endl;
cout
<<" 请选择:";
cin
>>choice;
if(choice == "1") insertBixiu();
else if(choice =="2")insertXuanxiu();
else if(choice =="3") mainPage();
else error();

}
void Record::insertXuanxiu(){
if(searchByName()){
string newCourseName;
double newCourseScore;
cout
<<"\n添加的选修科目名称:";
cin
>>newCourseName;
cout
<<"\n该选修课程的成绩:";
cin
>>newCourseScore;
current_ptr
->insert(newCourseName,newCourseScore,false);
cout
<<"\n已经为该同学添加了"<<newCourseName<<"选修课程 。"<<endl;
}
getPause();

}
void Record::insertBixiu(){
string newCourseName;
cout
<<"添加的必修科目名称:";
cin
>>newCourseName;
current_ptr
= head_ptr;
while(current_ptr != NULL){
current_ptr
->insert(newCourseName,0,true);
this->inputScore();
zero();
current_ptr
= current_ptr->next;
}
cout
<<"\n已经为每一名同学添加了"<<newCourseName<<"必修课程 。"<<endl;
getPause();

}
void Record::insertSingleBixiu(){
this->loadCourse();
if(Bixiu.size() ==0){
cout
<<"\n该班级未有必修课程,无需添加必修课程"<<endl;
return;
}
cout
<<"\n\n该班级有必修课程:";
for(int i=0;i<Bixiu.size();i++)
cout
<<Bixiu[i]<<" ,";
cout
<<"\n请为该生添加每一门必修课程的成绩。"<<endl;
double tempScore;
for(int i=0;i<Bixiu.size();i++){
cout
<<"\n"<<Bixiu[i]<<"的成绩为:";
cin
>>tempScore;
current_ptr
->insert(Bixiu[i],tempScore,true);
}
}

 

//"insertNode.cpp"
#include"record.h"
void Record::insertNode(Student* new_ptr){
system(
"cls");
//friend_node *temp_ptr;
//情况一:双向链表为空
if(head_ptr==NULL){
new_ptr
->next = NULL;
new_ptr
->prior = NULL;
head_ptr
= new_ptr;
tail_ptr
= new_ptr;
current_ptr
= new_ptr;
return;
}
//情况二:如果链表中只有一个结点
if(head_ptr->next==NULL){
if(new_ptr->getName() < head_ptr->getName())
InsertNodeAtHead(new_ptr);
else
InsertNodeAtEnd(new_ptr);
return;
}
//情况三:链表中不为一个结点
if(head_ptr->next!=NULL){
current_ptr
= head_ptr;
while((current_ptr!=NULL)//这两个判断条件不能颠倒,否则会出现严重错误 !!!
&&(new_ptr->getName() > current_ptr->getName()))
current_ptr
= current_ptr->next;

if(current_ptr == head_ptr)
InsertNodeAtHead(new_ptr);
else if(current_ptr == NULL )
InsertNodeAtEnd(new_ptr);
else//如果没有查找完整个表,并且满足排序条件推出,
//欲插入结点应该插入current_ptr之前
{
new_ptr
->next = current_ptr;
new_ptr
->prior = current_ptr->prior;
current_ptr
->prior->next = new_ptr;
current_ptr
->prior = new_ptr;
}
return ;
}
}
//插入表头子函数实现
void Record::InsertNodeAtHead(Student* new_ptr){
new_ptr
->next = head_ptr;
new_ptr
->prior = NULL;
head_ptr
->prior = new_ptr;
head_ptr
= new_ptr;
}
//插入表尾子函数实现
void Record::InsertNodeAtEnd(Student* new_ptr){
new_ptr
->prior = tail_ptr;
new_ptr
->next = NULL;
tail_ptr
->next = new_ptr;
tail_ptr
= new_ptr;

}

 

//"insertStudent.cpp"
#include"record.h"
#include
<iostream>
using namespace std;

Student
*new_ptr;
void inputMes();//基本信息输入的子函数

void Record::insertStudent(){
new_ptr
= new Student;
if(new_ptr!=NULL){

inputMes();
//调用子函数
//insertNode(new_ptr);
//输入文档信息 。。。
cout<<"\n是否需要输入文档信息?(y/n)";
string tempChar;
cin
>>tempChar;
if(tempChar == "y")
fileInput();
else if(tempChar == "n"){
cout
<<"\n如果以后需要添加该学生的文档信息,可以在主菜单里的“9_信息修改”中进行操作。"<<endl;
getPause();
}
else error();
//输入课程信息
this->current_ptr = new_ptr;
this->insertSingleBixiu();
cout
<<"\n是否需要继续添加选修课程?(y/n):";
cin
>>tempChar;
while(tempChar == "y"){
string newCourseName;
double newCourseScore;
cout
<<"\n添加的选修科目名称:";
cin
>>newCourseName;
cout
<<"\n该选修课程的成绩:";
cin
>>newCourseScore;
current_ptr
->insert(newCourseName,newCourseScore,false);
cout
<<"\n已经为该同学添加了"<<newCourseName<<"选修课程 。"<<endl;
cout
<<"\n是否需要继续添加选修课程?(y/n):";
cin
>>tempChar;
}
if(tempChar == "n"){
cout
<<"\n以后还可以在主界面中“3_添加课程信息”一栏中进行课程的添加。"<<endl;
getPause();
}
insertNode(new_ptr);
if(tempChar!="y"&&tempChar!="n")error();
}
else
cout
<<"\n警告,申请存储空间失败,不能创建新结点。"<<endl;
system(
"cls");
}
//基本信息输入的子函数的实现
void inputMes(){
system(
"cls");
cin.ignore(
20,'\n');
//输入名字
cout<<"名字:";
string tempName;
cin
>>tempName;
new_ptr
->setName(tempName);
//输入学号
cout<<"学号:";
string tempID;
cin
>>tempID;
new_ptr
->setID(tempID);


}
void Record::fileInput(){
string tempInput;
cout
<<"\n请输入性别:";
string temp;
cin
>>temp;
if(onlySex(temp)){
current_ptr
->sex = temp;
}
else{
cout
<<"信息输入有误,请注意:性别只能是男或者女。"<<endl;
getPause();
return;
}
cout
<<"\n请输入电话:";
cin
>>temp;
if(onlyNumber(temp)){
current_ptr
->phone = temp;
}
else{
cout
<<"信息输入有误,请注意:电话号码只能是数字。"<<endl;
getPause();
return;
}
cout
<<"\n请输入爱好:";
cin
>>new_ptr->hobby;
cout
<<"\n请输入该生曾经参加过的活动:";
cin
>>new_ptr->activity;
cout
<<"\n请输入该生曾经获得过的奖励:";
cin
>>new_ptr->reword;
cout
<<"\n请输入该生曾经遭受过的惩罚:";
cin
>>new_ptr->punishment;

}

 

//"list.cpp"
#include"record.h"
using namespace std;
void Record::list(){
system(
"cls");
string choice;
cout
<<endl<<" --------------屏幕显示---------------"<<endl<<endl;
cout
<<" *************************************"<<endl;
cout
<<" ****** 1_全部学生基本信息列表 *****"<<endl;
cout
<<" ****** *****"<<endl;
cout
<<" ****** 2_全部学生详细信息输出 *****"<<endl;
cout
<<" ****** *****"<<endl;
cout
<<" ****** 3_单个学生详细信息档输出 *****"<<endl;
cout
<<" ****** *****"<<endl;
cout
<<" ****** 4_单科成绩详细信息输出 *****"<<endl;
cout
<<" ****** *****"<<endl;
cout
<<" ****** 5_返回主菜单 *****"<<endl;
cout
<<" *************************************"<<endl;
cout
<<" 请选择:";
cin
>>choice;
if(choice=="1")
listOUT();
else if(choice=="2")
comuCOUT();
else if(choice=="3")
studentCOUT();
else if(choice=="4")
courseCOUT();
else if(choice=="5")
mainPage();
else error();

}
void Record::listOUT(){
current_ptr
= head_ptr;
if(head_ptr ==NULL){
cout
<<"记录为空,还未添加记录 !"<<endl;
return;
}
this->loadCourse();//将该班级的必修课程科目载入数组Bixiu[string] 中
system("cls");
cout
<<"*********************全部学生基本信息列表**********************"<<endl<<endl;
cout
<<"|"<<setw(8)<<"姓名"<<setw(4)<<"|"<<setw(8)<< "学号"<<setw(4)<<"|";
for(int i=0;i<Bixiu.size();i++)
cout
<<setw(8)<<Bixiu[i]<<setw(4)<<"|";
cout
<<endl<<endl;
do{
this->calForEach();//调用函数对该学生的成绩进行统计
cout<<"|"<<setw(8)<<current_ptr->getName()<<setw(4)<<"|"<<setw(8)<<current_ptr->getID()<<setw(4)<<"|";
for(int i=0;i<Bixiu.size();i++){
current_ptr
->find(Bixiu[i]);
cout
<<setw(8)<<current_ptr->fence->next->getScore()<<setw(4)<<"|";
}
cout
<<endl;
current_ptr
=current_ptr->next;
}
while(current_ptr!=NULL);
getPause();
}
void Record::comuCOUT(){
system(
"cls");
int n = 1;
int i;
current_ptr
= head_ptr;
if(head_ptr ==NULL){
cout
<<"记录为空,还未添加记录 !"<<endl;
return;
}
i
=1;//分屏显示
do{

//cout<<setw(20)<<"Sutdent Name"<<setw(20)<<"Student ID"<<endl;
//do{
cout<<""<<i<<"页 (每页显示一名学生的所有信息,回车翻页)"<<endl;
listSingle();
current_ptr
= current_ptr->next;
i
++;
//}while(current_ptr!=NULL&&i<=n);
if(current_ptr!=NULL){
getPause();
}
else cout<<"文件结束"<<endl;
}
while(current_ptr!=NULL);

getPause();
}
void Record::studentCOUT(){
system(
"cls");
cout
<<endl<<" -----------单个学生信息输出---------"<<endl<<endl;
cout
<<" ****************************"<<endl;
cout
<<" ******* 1_按姓名查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 2_按学号查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 3_返回上界面 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 4_返回主菜单 *******"<<endl;
cout
<<" ****************************"<<endl;
cout
<<" 请选择:";
string choice;
cin
>>choice;
if(choice=="1"){
if(searchByName())listSingle();
getPause();
}
else if(choice == "2"){
if(searchByID())listSingle();
getPause();
}
else if(choice=="3")list();
else if(choice=="4")mainPage();
else error();
}
void Record::courseCOUT(){
calForCourse();
}
void Record::error(){
cout
<<"\n输入有误。"<<endl;
cout
<<"\n按任意键继续..."<<endl;
cin.
get(pause);
cin.ignore(
1,pause);
system(
"cls");
return;
}
void Record::getPause(){
cout
<<"\n按任意键继续..."<<endl;
cin.
get(pause);
cin.ignore(
1,pause);
system(
"cls");
}
void Record::listSingle(){
this->calForEach();
cout
<<"**************************************************************"<<endl<<endl;
//cout<<left<<setw(20)<<current_ptr->getName()<<setw(20)<<current_ptr->getID()<<endl;
cout<<"姓名:"<<current_ptr->getName()<<" 学号:"<<current_ptr->getID()<<endl;

cout
<<endl<<" ---------------该生的文档信息如下--------------"<<endl;
fileOutput();

cout
<<endl<<" ---------------该同学的课程信息如下------------"<<endl;
current_ptr
->print();
cout
<<endl<<" 该学生所修科目总数:"<<current_ptr->courseNum<<" 不及格总数:"<<current_ptr->unpassed<<endl;
cout
<<" 该学生的总成绩为:"<<current_ptr->total<<" 平均成绩为:"<<current_ptr->ave<<endl;
cout
<<endl<<endl;
}

 

//"loadFile.cpp"
#include"record.h"
bool Record::loadFile(){
string fileName;
string choice;
cout
<<" --------------------班级文件载入系统----------------------"<<endl<<endl;
cout
<<" **********************************************************"<<endl;
cout
<<" ***************** 1_使用默认测试文件 *********************"<<endl;
cout
<<" ***************** *********************"<<endl;
cout
<<" ***************** 2_使用自定义文件 *********************"<<endl;
cout
<<" ***************** *********************"<<endl;
cout
<<" ***************** 3_退出系统 *********************"<<endl;
cout
<<" ***************** *********************"<<endl;
cout
<<" **********************************************************"<<endl;
cout
<<"\n 请进行选择:";
cin
>>choice;

ifstream infile;
Student
*new_ptr;
if(choice =="1") {
fileName
="FRIENDS.dat";
this->className = "FRIENDS";
}
else if(choice=="2"){
cout
<<"\n请输入你要打开的班级文件,输入班级名称即可:";
cin
>>this->className;


fileName
= className+".dat";
}
else if(choice=="3")
return false;
else {
error();
return false;
}

int end_loop = 0;
infile.open(fileName,ios::
in);
if(infile){
do{
new_ptr
= new Student;
if(new_ptr!=NULL){
string tempName;
infile
>>tempName;
new_ptr
->setName(tempName);
if(new_ptr->getName() != "文件结束"
&&new_ptr->getName() != ""){
string tempID;
infile
>>tempID;
new_ptr
->setID(tempID);
//内层循环读取课程信息
infile>>tempName;
double tempScore;
bool tempIs;
while(tempName != "课程结束"){
infile
>>tempScore;
infile
>>tempIs;
new_ptr
->insert(tempName,tempScore,tempIs);
infile
>>tempName;
}
//读取文档信息
infile>>new_ptr->sex;
infile
>>new_ptr->phone;
infile
>>new_ptr->hobby;
infile
>>new_ptr->activity;
infile
>>new_ptr->reword;
infile
>>new_ptr->punishment;

insertNode(new_ptr);
}
else{
delete new_ptr;
end_loop
= 1;
}
}
else{
cout
<<"\n没有成功从磁盘导入文件 !"<<endl;
end_loop
=1;
return false;
}
}
while(end_loop ==0);
infile.close();
return true;
}
else{
ofstream outfile;
cout
<<"\n没有可用的数据文件 !"<<endl;
cout
<<"\n是否建立该班级信息?(y/n):";
string tempString;
cin
>>tempString;
if(tempString == "y"){
outfile.open(fileName,ios::
out);
cout
<<"\n班级文件创建成功。"<<endl;
getPause();
loadFile();
}
else return false ;
}
}

 

//"modify.cpp"
#include"record.h"
void Record::modify(){
system(
"cls");
cout
<<" ----对某个学生信息进行修改----"<<endl;
cout
<<" ****************************"<<endl;
cout
<<" ***** 1_按学生姓名查找 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 2_按学生学号查找 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 3_返回主界面 *****"<<endl;
cout
<<" ****************************"<<endl;
cout
<<" 请选择:";
string choice;
cin
>>choice;

bool isFind = false;
if(choice=="1")isFind = searchByName();
else if(choice =="2")isFind = searchByID();
else if(choice =="3")mainPage();
else {
cout
<<"输入有误。"<<endl;
getPause();
return;
}
if(isFind) modifyDetail();

getPause();
}

void Record::modifyDetail(){
system(
"cls");
cout
<<" ----对某个学生信息进行修改----"<<endl;
cout
<<" **************************"<<endl;
cout
<<" ***** 1_修改姓名 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 2_修改学号 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 3_修改文档信息 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 4_修改成绩信息 ***** "<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 5_返回上界面 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 6_返回主界面 ***** "<<endl;
cout
<<" **************************"<<endl;
cout
<<" 请选择:";
string choice;
cin
>>choice;
string tempString;
if(choice=="1"){
cout
<<"\n请输入新的学生姓名";
cin
>>tempString;
current_ptr
->setName(tempString);
cout
<<"\n学生信息修改成功。"<<endl;
}
else if(choice=="2"){
cout
<<"\n请输入新的学生学号";
cin
>>tempString ;
current_ptr
->setID(tempString);
cout
<<"\n学生信息修改成功。"<<endl;
}
else if(choice=="3")
modifyDoc();
else if(choice=="4")
modifyCourse();
else if(choice=="5")
modify();
else if(choice=="6")
mainPage();
else error();
}
void Record::modifyDoc(){
system(
"cls");
cout
<<" ----对某个学生信息进行修改----"<<endl;
cout
<<" **************************"<<endl;
cout
<<" ***** 1_修改性别 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 2_修改手机号码 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 3_修改爱好 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 4_修改活动信息 ***** "<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 5_修改奖励信息 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 6_修改惩罚信息 ***** "<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 7_返回上界面 *****"<<endl;
cout
<<" ***** *****"<<endl;
cout
<<" ***** 8_返回主菜单 ***** "<<endl;
cout
<<" **************************"<<endl;
cout
<<" 请选择:";
string choice;
cin
>>choice;
if(choice=="1"){
cout
<<"\n请输入性别:";
string temp;
cin
>>temp;
if(onlySex(temp)){
current_ptr
->sex = temp;
cout
<<"\n信息修改成功。"<<endl;
}
else{
cout
<<"信息输入有误,请注意:性别只能是男或者女。"<<endl;
getPause();
return;
}
}
else if(choice=="2"){
cout
<<"\n请输入电话:";
string temp;
cin
>>temp;
if(onlyNumber(temp)){
current_ptr
->phone = temp;
cout
<<"\n信息修改成功。"<<endl;
}
else{
cout
<<"信息输入有误,请注意:电话号码只能是数字。"<<endl;
getPause();
return;
}
}
else if(choice=="3"){
cout
<<"\n请输入爱好:";
cin
>>current_ptr->hobby;
cout
<<"\n信息修改成功。"<<endl;
}
else if(choice=="4"){
cout
<<"\n请输入曾经参加的活动:";
cin
>>current_ptr->activity;
cout
<<"\n信息修改成功。"<<endl;
}
else if(choice=="5"){
cout
<<"\n请输入曾经获得过的奖励:";
cin
>>current_ptr->reword;
cout
<<"\n信息修改成功。"<<endl;
}
else if(choice=="6"){
cout
<<"\n请输入曾经获得过的处罚:";
cin
>>current_ptr->punishment;
cout
<<"\n信息修改成功。"<<endl;
}
else if(choice=="7"){
modifyDetail();
}
else if(choice=="8"){
mainPage();
}
else error();

}
void Record::modifyCourse(){
this->calForEach();
cout
<<endl<<"\n ---------------该同学的课程信息如下------------"<<endl;
current_ptr
->print();
cout
<<endl<<"\n 该学生所修科目总数:"<<current_ptr->courseNum<<" 不及格总数:"<<current_ptr->unpassed<<endl;
cout
<<"\n 该学生的总成绩为:"<<current_ptr->total<<" 平均成绩为:"<<current_ptr->ave<<endl;
cout
<<endl<<endl;
cout
<<"\n请输入需要修改的课程名称:";
string search_string;
cin
>>search_string;
if(current_ptr->find(search_string)){
cout
<<"\n请输入要修改的分数:";
double tempScore;
cin
>>tempScore;
current_ptr
->fence->next->setScore(tempScore);
cout
<<"\n信息修改成功。"<<endl;
cout
<<"\n是否需要继续修改?(y/n)";
string tempChar;
cin
>>tempChar;
if(tempChar == "y")modifyCourse();
else if(tempChar != "n"){
error();
return;
}
this->zero();//课程信息有改动,所以需要重新计算其课程信息

}
}


 

//"saveFile.cpp"
#include"record.h"
void Record::saveFile(){
ofstream outfile;
string fileName = this->className+".dat";
outfile.open(fileName,ios::
out);
if(outfile){
current_ptr
= head_ptr;
while(current_ptr!=NULL){
outfile
<<current_ptr->getName()<<endl;
outfile
<<current_ptr->getID()<<endl;
// 循环操作写入该学生的课程信息
current_ptr->fence = current_ptr->head;
while(current_ptr->fence->next != NULL){
outfile
<<current_ptr->fence->next->getCourseName()<<endl;
outfile
<<current_ptr->fence->next->getScore()<<endl;
outfile
<<current_ptr->fence->next->getIsBixiu()<<endl;
current_ptr
->fence = current_ptr->fence->next;
}
outfile
<<"课程结束"<<endl;//为文件的循环读取做停止标记
//写入文档信息
outfile<<current_ptr->sex<<endl;
outfile
<<current_ptr->phone<<endl;
outfile
<<current_ptr->hobby<<endl;
outfile
<<current_ptr->activity<<endl;
outfile
<<current_ptr->reword<<endl;
outfile
<<current_ptr->punishment<<endl;
current_ptr
= current_ptr->next;
}
outfile
<<"文件结束"<<endl;//为文件的循环读取做停止标记
outfile.close();
}
else
cout
<<"打开文件失败 !"<<endl;
}

 

//"search.cpp"
#include"record.h"
bool Record::search(){
string choice;
system(
"cls");
cout
<<endl<<" -----------信息查找---------"<<endl<<endl;
cout
<<" ****************************"<<endl;
cout
<<" ******* 1_按姓名查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 2_按学号查找 *******"<<endl;
cout
<<" ******* *******"<<endl;
cout
<<" ******* 3_返回主菜单 *******"<<endl;
cout
<<" ****************************"<<endl;
cout
<<" 请选择:";
cin
>>choice;
if(choice == "1"){
bool temp = searchByName();
if( temp&&requireList()){
listSingle();
getPause();
}
return temp;
}
else if(choice=="2"){
bool temp = searchByID();
if(temp&&requireList()){
listSingle();
getPause();
}
return temp;
}
else if(choice=="3")
mainPage();
else error();
return false;
}

bool Record::searchByName(){
//system("cls");
int flag =0;
string search_string;
current_ptr
= head_ptr;
if(current_ptr==NULL){
cout
<<"学生记录为空 !"<<endl;
getPause();
return false;
}
else{
cout
<<"\n请输入学生姓名:";
cin
>>search_string;
while(current_ptr!=NULL){
if(current_ptr->getName()==search_string){
if(flag==0)cout<<"\n找到记录"<<endl;
flag
= 1;
cout
<<"\n该学生姓名为:"<<search_string<<" ";
cout
<<"\n学号为:"<<current_ptr->getID()<<endl;
cout
<<"\n按任意键继续..." <<endl;
cin.
get(pause);
cin.ignore(
1,pause);
//system("cls");
return true;
}
current_ptr
=current_ptr->next;
}
if(flag == 0){
cout
<<"\n无该记录"<<endl;
getPause();
return false ;
}

}
return true;
}
bool Record::searchByID(){
//system("cls");
int flag =0;
string search_ID;
current_ptr
= head_ptr;
if(current_ptr==NULL){
cout
<<"\n学生记录为空 !"<<endl;
return false;
}
else{
cout
<<"\n请输入学生学号:";
cin
>>search_ID;
while(current_ptr!=NULL){
if(current_ptr->getID()==search_ID){
if(flag==0)cout<<"\n找到记录"<<endl;
flag
= 1;
cout
<<"\n该学生姓名为:"<<current_ptr->getName()<<" ";
cout
<<"\n学号为:"<<current_ptr->getID()<<endl;

cout
<<"\n按任意键继续..." <<endl;
cin.
get(pause);
cin.ignore(
1,pause);
//system("cls");
return true;
}
current_ptr
=current_ptr->next;
}
if(flag == 0){
cout
<<"\n无该记录"<<endl;
getPause();
return false ;
}

}
return true;
}

bool Record::requireList(){
string choice;
cout
<<" 是否显示该学生的详细信息?(y/n):";
cin
>>choice;
if(choice=="y")return true;
else if(choice =="n")return false;
else error();
return false;
}

 

//"student.cpp"
#include"student.h"
using namespace std;
Student::Student(){
head
= tail = fence = new Course;
this->unpassed = 0;
this->total = 0.0;
this->ave = 0.0;
this->courseNum = 0;
this->needUpdate = true;

this->sex = "";
this->phone="";
this->hobby ="";
this->punishment="";
this->reword ="";
this->activity="";
}
void Student::setName(string valName){
name
= valName;
}
void Student::setID(string valID){
ID
= valID;
}
string Student::getName(){
return name;
}
string Student::getID(){
return ID;
}

/*
需要实现的关于kecheng单向链表的函数
void clear();
void setStart();//指针置前
void setEnd();
void next();
bool getValue(string name,double score);
bool insert(string name,double score);
bool remove(string &name,double &score);
void pre();
bool setPos(string name);
void print();
bool find(string name);
*/
void Student::clear(){
while(head != NULL){
fence
= head;
head
= head->next;
delete fence;
}
head
= tail = fence = new Course;
}
void Student::setStart(){
fence
= head;
}
void Student::setEnd(){
fence
= tail;
}
void Student::nextItem(){
if(fence != tail){
fence
= fence->next;
}
else cout<<"\n这是最后一门课程,没有课程了 !"<<endl;
}
bool Student::getValue(string& nameVal,double& scoreVal,bool& isVal){
if(fence->next ==NULL)
return false;
//不要忘记fence指向的是当前元素的上一个位置
nameVal = fence->next->getCourseName();
scoreVal
=fence->next->getScore();
isVal
= fence->next->getIsBixiu();
return true;
}
bool Student::insert(string nameVal,double scoreVal,bool isVal){
//fence = tail;//暂时处理,追加到最后,暂且不排序
fence->next = new Course(nameVal,scoreVal,isVal,fence->next);

if(fence == tail)tail = fence->next;
return true;
}
bool Student::remove(string& nameVal,double& scoreVal,bool& isVal){
if(fence->next == NULL)return false;

nameVal
= fence->next->getCourseName();
scoreVal
= fence->next->getScore();
isVal
= fence->next->getIsBixiu();

Course
* temp = fence->next;
fence
->next = temp->next;
if(temp == tail)
tail
= fence;
delete temp;
return true;
}
void Student::pre(){
Course
* temp = head;
while(temp->next != fence)
temp
= temp->next;
fence
= temp;
}
bool Student::setPos(string nameVal){
fence
= head;
while(fence->next->getCourseName() != nameVal && fence->next!=NULL)
fence
= fence->next;
if(fence->next == NULL){
cout
<<"\n该学生没有选修该课程!"<<endl;
return false;
}
return true;
}
bool Student::find(string nameVal){
fence
= head;
while(fence->next!=NULL&&fence->next->getCourseName() !=nameVal )
fence
= fence->next;
if(fence->next == NULL){
//cout<<"\n该学生没有选修该课程!"<<endl;
cout<<"\n"<<this->getName()<<"同学没有选修该课程。"<<endl;
return false;
}
else return true;
}
void Student::print(){
//cout<<endl<<" "<<name<<"同学修的课程信息"<<endl;
fence = head;
if(fence->next == NULL) cout<<"\n该同学目前还未选择任何课程 !"<<endl;

else while(fence->next != NULL){
cout
<<" "<<left<<setw(20)<<fence->next->getCourseName()<<setw(20)<<fence->next->getScore();
if(fence->next->getIsBixiu())cout<<setw(20)<<"必修课"<<endl;
else cout<<setw(20)<<"选修课"<<endl;
fence
= fence->next;
}
}

 

//"userChoice.cpp"
#include"record.h"
#include
<iostream>
using namespace std;
void Record::userChoice(string choice){
if(choice=="1")
insertStudent();
else if(choice=="2")
deleteStudent();
else if(choice=="3")
insertCourse();
else if(choice=="4")
deleteCourse();
else if(choice=="5")
calculate();
else if(choice=="6")
list();
else if(choice=="7")
search();
else if(choice=="8")
outputTXT();
else if(choice=="9")
modify();
else if(choice=="0")
saveFile();
else
error();

}
posted on 2011-09-02 20:52  geeker  阅读(387)  评论(0编辑  收藏  举报