主题:请大家帮忙看看这个C++写的学生成绩单管理系统???
不知道哪里出错了, 感觉是文件读和写那一块出了问题, 调试了很久都没找出来;
主要问题是当"学生成绩单.txt"还没有建立的时候(就是第一次运行该程序), 调试过程中数据显示,修改这块都还是正常, 但是当关闭程序,再次打开程序,运行测试时,在GetList()函数处,从文件读数据时, 学生的名字就开始乱码了,当然显示,修改这些函数就没法做了,请明白的人说一说阿 。。感激不敬。
student.h///#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(){}
void InputData(); //学生数据输入;
void LinkData(Student *s); //链接学生数据;
void ShowData(); //显示学生数据;
string Getname(); //取姓名;
long Getnumber(); //取学号;
float Getscores(); //取成绩;
Student &AlterName(); //修改姓名;
Student &AlterNumber(); //修改学号;
Student &AlterScores(); //修改成绩;
Student *next;
private:
string name;
long number;
float scores;
};
void Student::ShowData(void)
{
cout<<"姓名\t学号\t成绩:"<<endl;
cout<<name<<"\t"<<number<<"\t"<<scores<<endl;
}
void Student::InputData()
{
cout<<"请输入学生数据:"<<endl;
cout<<"姓名:"<<endl;
cin>>name;
cout<<"学号:"<<endl;
cin>>number;
cout<<"成绩:"<<endl;
cin>>scores;
}
void Student::LinkData(Student *s)
{
next = s;
}
string Student::Getname()
{
return name;
}
long Student::Getnumber()
{
return number;
}
float Student::Getscores()
{
return scores;
}
Student &Student::AlterName()
{
string new_name;
cout<<"请输入新名字:"<<endl;
cin>>new_name;
name = new_name;
return *this;
}
Student &Student::AlterNumber()
{
long new_number;
cout<<"请输入新学号:"<<endl;
cin>>new_number;
number = new_number;
return *this;
}
Student &Student::AlterScores()
{
float new_scores;
cout<<"请输入新成绩:"<<endl;
cin>>new_scores;
scores = new_scores;
return *this;
}
主函数文件在下面
主要问题是当"学生成绩单.txt"还没有建立的时候(就是第一次运行该程序), 调试过程中数据显示,修改这块都还是正常, 但是当关闭程序,再次打开程序,运行测试时,在GetList()函数处,从文件读数据时, 学生的名字就开始乱码了,当然显示,修改这些函数就没法做了,请明白的人说一说阿 。。感激不敬。
student.h///#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(){}
void InputData(); //学生数据输入;
void LinkData(Student *s); //链接学生数据;
void ShowData(); //显示学生数据;
string Getname(); //取姓名;
long Getnumber(); //取学号;
float Getscores(); //取成绩;
Student &AlterName(); //修改姓名;
Student &AlterNumber(); //修改学号;
Student &AlterScores(); //修改成绩;
Student *next;
private:
string name;
long number;
float scores;
};
void Student::ShowData(void)
{
cout<<"姓名\t学号\t成绩:"<<endl;
cout<<name<<"\t"<<number<<"\t"<<scores<<endl;
}
void Student::InputData()
{
cout<<"请输入学生数据:"<<endl;
cout<<"姓名:"<<endl;
cin>>name;
cout<<"学号:"<<endl;
cin>>number;
cout<<"成绩:"<<endl;
cin>>scores;
}
void Student::LinkData(Student *s)
{
next = s;
}
string Student::Getname()
{
return name;
}
long Student::Getnumber()
{
return number;
}
float Student::Getscores()
{
return scores;
}
Student &Student::AlterName()
{
string new_name;
cout<<"请输入新名字:"<<endl;
cin>>new_name;
name = new_name;
return *this;
}
Student &Student::AlterNumber()
{
long new_number;
cout<<"请输入新学号:"<<endl;
cin>>new_number;
number = new_number;
return *this;
}
Student &Student::AlterScores()
{
float new_scores;
cout<<"请输入新成绩:"<<endl;
cin>>new_scores;
scores = new_scores;
return *this;
}
主函数文件在下面