|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
编译的时候总在while(infile.read( reinterpret_cast(&people_one),sizeof(Data) ) != 0 )这一句的前后有错误,
错误形式为:
syntax error : '('
syntax error : missing ';' before '{'
这怎么回事啊
源代码:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void Begin();
int List();
int Choose();
class Basic//基本信息类
{
public:
virtual void enter();
virtual void show();
char num[11];
char name[30];
char department[20];
char Class[30];
};
//***********************************************************
class Data:public Basic//数据类
{
public:
virtual void enter();
virtual void show();
double Total_grade();
double Average_scores();
private:
double c;
double math;
double english;
double sport;
};
//**********************************************************
class Student//学生类
{
public:
void Look();
void Print();
private:
Data people_one;
};
//**********************************************************
class Teacher//教师类
{
public:
void Add();
void Find();
void Modify();
void Delete();
void See();
private:
Data people;
};
//***********************************************************
int main()
{
Loop:
Begin();
char n;
cout << "\n\t登录类型[1~2][ ]\b\b";
cin >> n;
if (n == '1')
{
Teacher tp;
while(1)
{
switch(List())
{
case '1' :tp.Add();break;
case '2' :tp.See();break;
case '3' :tp.Find();break;
case '4' :tp.Modify();break;
case '5' :tp.Delete();break;
case '0' : goto Loop;break;
default:
cout << "\t\t—————————————————————————————————————————" << endl;
cout <<"\t\t\t*提示:输入错误!,请重新输入!" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
}
}
}
else if (n == '2')
{
Student sp;
while(1)
{
switch(Choose())
{
case '1' :sp.Look();break;
case '2' :sp.Print();break;
case '0' : goto Loop;break;
default:
cout << "\t\t—————————————————————————————————————————" << endl;
cout <<"\t\t\t*提示:输入错误!,请重新输入!" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
}
}
}
else
{
cout << "\t\t\t**********\n";
cout << "\t\t\t*Bey Bey!*\n";
cout << "\t\t\t**********\n";
exit(0);
}
return 0;
}
//***********************************************************
void Basic::enter() //基本信息输入
{
cout << "请输入学生信息" << endl;
cout << "学号:";
cin >> num ;
cout << "姓名:";
cin >> name ;
cout << "系别:";
cin >> department;
cout << "班级:";
cin >> Class;
}
void Basic::show() //基本信息显示
{
cout << "学号" << "\t" << "姓名" << "\t" << "系别" << "\t" << "班级" << endl;
cout << num << "\t" << name << "\t" << department << "\t" << Class << endl;
}
//***************************************************************
void Begin()
{
cout << "\t\t *****************************" << endl;
cout << "\t\t *Welcome to 高校学籍管理系统*" << endl;
cout << "\t\t *****************************" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
cout << "\t\t|\t1.[教师]\t2.[学生]\t|" << endl;
cout << "\t\t| 其他任意字符退出高校学籍管理系统 |" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
}
int List()
{
cout << "\t\t****************教师在线*****************" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
cout << "\t\t|\t1.[添加]\t2.[显示]\t|" << endl;
cout << "\t\t|\t3.[查找]\t4.[修改]\t|" << endl;
cout << "\t\t|\t5.[删除]\t0.[返回]\t|" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
cout << "\n\t请选择操作[1~7][ ]\b\b";
char m;
cin >> m;
return m;
}
int Choose()
{
cout << "\t\t****************学生在线*****************" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
cout << "\t\t|\t1.[显示]\t2.[查找]\t|" << endl;
cout << "\t\t|\t 0.[返回登录界面]\t\t|" << endl;
cout << "\t\t—————————————————————————————————————————" << endl;
cout << "\n\t请选择操作[0~2][ ]\b\b";
char k;
cin >> k;
return k;
}
//****************************************************************
void Data::enter() //成绩输入
{
Basic::enter();
cout << "**************录入成绩**************" << endl;
cout << "C++ 语言:";
cin >> c;
cout << "高等数学:";
cin >> math;
cout << "大学英语:";
cin >> english;
cout << "体育健康:";
cin >> sport;
}
void Data::show() //成绩显示
{
Basic::show();
cout << "************成绩*************" << endl;
cout << "C++ 语言:" << c << endl;
cout << "高等数学:" << math << endl;
cout << "大学英语:" << english << endl;
cout << "体育健康:" << sport <<endl;
cout << "总 成 绩:" << Total_grade() <<endl;
cout << "平均成绩:" << Average_scores() <<endl;
cout << "—————————————————————————————" << endl;
}
double Data::Total_grade() //计算总成绩
{
return (c + math + english + sport);
}
double Data::Average_scores()//计算平均成绩
{
return (Total_grade()/4.0);
}
//*********************************************************
void Student::Look() //学生显示信息
{
ifstream infile("file.txt",ios::binary);
if(infile.fail())
{
cout << "打开文件失败!" <<endl;
exit(1);
}
cout << "\n\t\t\t********显示学生信息********" <<endl;
infile.clear();
infile.seekg(0,ios::beg);
while(infile.read( reinterpret_cast(&people_one),sizeof(Data) ) != 0 )
{
people_one.show();
}
infile.close();
}
void Student::Print() //学生查询信息
{
int n;
char ch;
char str_num[20],str_name[20];
cout << "\n\t\t\t********查询学生信息********" <<endl;
ifstream infile("file.txt",ios::binary);
if(infile.fail())
{
cout << "打开文件失败!" <<endl;
exit(1);
}
do
{
cout << "请选择:";
cout << "1.按学号查找 2.按姓名查找" << endl;
cin >> n;
infile.clear();
infile.seekg(0,ios::beg); //文件指针定位到开头
if(n == 1) //按编号查询Grade的信息
{
cout << "输入学号: ";
cin >> str_num;
while(infile.read((char *)(&people_one),sizeof(Data)) !=0)
{
if(strcmp(str_num,people_one.num) == 0)
{
people_one.show();
}
}
}
else if(n == 2) //按姓名查询Grade的信息
{
cout << "输入姓名: ";
cin >> str_name;
while(infile.read(reinterpret_cast(&people_one),sizeof(Data)) != 0)
{
if(strcmp(str_name,people_one.name) == 0)
{
people_one.show();
}
}
}
cout << "\n是否继续此操作[Y/y]: ";
cin >> ch;
}while(ch =='Y' || ch == 'y');
infile.close();
}
//***************************************************************
void Teacher::Add() //教师录入信息
{
char ch;
ofstream openfile("file.txt",ios::binary | ios::app); //文件写入操作
if( openfile.fail() )
{
cout << "打开文件失败!" <<endl;
exit(1);
}
cout << "***********增加学生信息*************" <<endl;
do
{
people.enter();
openfile.write(reinterpret_cast(&people),sizeof(Data)); //强制类型转换成char*写入
cout << "\n是否继续此操作[Y/y]: ";
cin >> ch;
}while(ch == 'Y' || ch == 'y');
openfile.close();
}
void Teacher::See() //教师显示信息
{
ifstream infile("file.txt",ios::binary);//文件读取操作
if(infile.fail())
{
cout << "打开文件失败!" <<endl;
exit(1);
}
cout << "\n\t\t\t********显示学生信息********" <<endl;
infile.clear();
infile.seekg(0,ios::beg);
while(infile.read(reinterpret_cast(&people),sizeof(Data)) != 0)
{
people.show();
}
infile.close();
}
void Teacher::Find() //教师查询信息
{
int n;
char ch;
char str_num[20],str_name[20];
cout << "\n\t\t\t********查询学生信息********" <<endl;
ifstream infile("file.txt",ios::binary);
if(infile.fail())
{
cout << "打开文件失败!" <<endl;
exit(1);
}
do
{
cout << "请选择:";
cout << "1.按学号查找 2.按姓名查找" << endl;
cin >> n;
infile.clear();
infile.seekg(0,ios::beg); //文件指针定位到开头
if(n == 1) //按编号查询Grade的信息
{
cout << "输入学号: ";
cin >> str_num;
while(infile.read((char *)(&people),sizeof(Data)) !=0)
{
if(strcmp(str_num,people.num) == 0) //数据比较
{
people.show();
}
}
}
else if(n == 2) //按姓名查询Grade的信息
{
cout << "输入姓名: ";
cin >> str_name;
while(infile.read(reinterpret_cast(&people),sizeof(Data)) != 0)
{
if(strcmp(str_name,people.name) == 0)
{
people.show();
}
}
}
cout << "\n是否继续此操作[Y/y]: ";
cin >> ch;
}while(ch =='Y' || ch == 'y');
infile.close();
}
void Teacher::Modify() //教师修改信息
{
char ch;
char str_num[15];
bool pass;
do
{
cout << "\n\t\t\t********修改学生信息********" <<endl;
ofstream openfile("temp.txt",ios::binary);
ifstream infile("file.txt",ios::binary);
if(infile.fail())
{
cout << "打开文件失败" << endl;
exit(1);
}
if(openfile.fail())
{
cout << "打开文件失败" << endl;
exit(1);
}
cout << "输入学号:";
cin >> str_num;
infile.clear();
infile.seekg(0,ios::beg); //文件定位到最前面
while(infile.read(reinterpret_cast(&people),sizeof(Data))!=0)
{
if(strcmp(str_num,people.num) == 0)
{
people.show();
cout << "...............修改..............." <<endl;
cout << endl;
people.enter();
pass = true;
}
openfile.write(reinterpret_cast(&people),sizeof(Data));
}
infile.close();
openfile.close();
if(pass == true)
{
cout << "修改成功!" << endl;
remove("file.txt");
rename("temp.txt","file.txt");
pass = false;
}
else
{
cout << "没找到你输入的信息!" << endl;
}
cout << "\n是否继续此操作[Y/y]:";
cin >> ch;
}while(ch == 'y' || ch == 'Y');
}
void Teacher::Delete() //教师删除信息
{
char ch;
char str_num[15];
bool pass;
do
{
cout << "\n\t\t\t********删除学生信息********" <<endl;
ofstream openfile("temp.txt",ios::binary);
ifstream infile("file.txt",ios::binary);
if(infile.fail())
{
cout << "打开文件失败" << endl;
exit(1);
}
if(openfile.fail())
{
cout << "打开文件失败" << endl;
exit(1);
}
cout << "输入学号:";
cin >> str_num;
infile.clear();
infile.seekg(0,ios::beg); //文件定位到最前面
while(infile.read(reinterpret_cast(&people),sizeof(Data))!=0)
{
if(strcmp(str_num,people.num) == 0)
{
people.show();
cout << "正在删除。。。" <<endl;
cout << endl;
pass = true;
}
else
{
openfile.write(reinterpret_cast(&people),sizeof(Data));
}
}
infile.close();
openfile.close();
if(pass == true)
{
cout << "删除成功!" << endl;
remove("file.txt");
rename("temp.txt","file.txt");
pass = false;
}
else
{
cout << "没找到你输入的信息!" << endl;
}
cout << "\n是否跳过此操作[Y/y]:";
cin >> ch;
}while(ch == 'y' || ch == 'Y');
}
//************************************************************
reinterpret_cast后面接的不应该是<>吗?
|
|