学生信息管理系统想不通,求解.......
这是我编的一个学生信息管理系统,要求的全部功能没有完成,但是在输入时我就是不明白为什么静态变量(全局变量)i 为什么没有变化
求解。顺便问下怎么将数据 写入文件,因为老师没有讲解,可以的话也请
解说解说 谢谢!
程序代码:
#include "fstream.h" #include "string.h" #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<process.h> void Wfile(); //================================================================================ class CPerson { public: CPerson(); void showP(); virtual ~CPerson(); char IDNo[25]; protected: char Name[20]; char Tel[20]; char Addr[50]; }; CPerson::CPerson() { cout<<"请输入身份证号:"; cin>>IDNo; cout<<"请输入姓名:"; cin>>Name; cout<<"请输入家庭住址:"; cin>>Addr; cout<<"请输入电话号码:"; cin>>Tel; } CPerson::~CPerson() { } void CPerson::showP() { cout<<"身份证号:"<<IDNo<<" "; cout<<"姓名:"<<Name<<endl; cout<<"家庭住址:"<<Addr<<" "; cout<<"电话号码:"<<Tel<<endl;; } //================================================================================ class CStudent : public CPerson { public: CStudent(); void showS(); virtual ~CStudent(); char StuNo[20]; private: float Average; float English; float Math; }; CStudent::CStudent() { cout<<"请输入学生学号:"; cin>>StuNo; cout<<"请输入数学成绩:"; cin>>Math; cout<<"请输入英语成绩:"; cin>>English; Average=(English+Math)/2.0; } CStudent::~CStudent() { } void CStudent::showS() { cout<<"学生学号:"<<StuNo<<" "; cout<<"英语成绩:"<<English<<" "; cout<<"数学成绩:"<<Math<<endl; cout<<"平均分:"<<Average<<endl; } //================================================================================ class CClass { public: CClass(); virtual ~CClass(); CStudent *n[50]; static int i; void input(); void outp(); void Add(); private: char ClassN[50]; }; CClass::CClass() { for(int k=0;k<50;k++) { n[k]=NULL; } } CClass::~CClass() { for(int m=0;m<50;m++) { delete n[m]; n[m]=NULL; } } int CClass::i=0; void CClass::input() { cout<<"请输入班级名称:"; cin>>ClassN; i++; cout<<"您已成功添加一个班级,请返回主菜单选择添加学生信息功能."<<endl; /*int j=0; for (i=0;j==0;i++) { n[i]=new CStudent; cout<<"输入任意键 回车退回主菜单"; cin>>j; }*/ } void CClass::Add() { int j=0; for (i=0;j==0;i++) { cout<<"请输入第 " <<i+1<<"个学生的信息"; n[i]=new CStudent; cout<<"输入任意键 回车退回主菜单"; cin>>j; } i++; } void CClass::outp() { char search_name[50]; int k; cout<<"请输入你想要打印的学生的身份证号."<<endl; cin>>search_name; for(k=0;k<i;k++) { if(strcmp(n[k]->IDNo,search_name)==0) { cout<<"班级名称:"<<ClassN<<" "; n[k]->showP(); n[k]->showS(); } } } //================================================================================ /*void Wfile() { int j;char c; int i; CClass A1[1]; cout<<"是否保存文件?是输入 y 否 输入 n 退出 \n"; c=getchar(); c=getchar(); if(c=='y'||c=='Y') { ofstream fout("test"); if(!fout) { cout<<"Cantnot open ouput file."; } for(j=0;j<i;j++) { fout<<A1[j].Math; } fout.close(); } }*/ void main() { int j,p=0; CClass A[50]; do { cout<<"_____________________学生信息管理系统___________________"<<endl; cout<<"_______________________请选择操作_______________________"<<endl; cout<<"______________________01.创建班级________________________"<<endl; cout<<"______________________02.添加学生信息____________________"<<endl; cout<<"______________________03.修改学生信息____________________"<<endl; cout<<"______________________04.删除学生信息____________________"<<endl; cout<<"______________________05.打印学生信息____________________"<<endl; cout<<"______________________06.退出____________________________"<<endl; cout<<"___________请输入你要的功能:___________________________"<<endl; cin>>j; switch(j) { case 01:A[p].input();break; case 02:A[p].Add();break; case 03:;break; case 04:;break; case 05:A[p].outp();break; case 06:;break; default:cout<<"错误!!";break; } }while(j!=06); p++; } //================================================================================