C++万年历源代码,网上那些代码让我寒心呀

#include< iostream >
#include< fstream >
#include< iomanip >
#include< string >
using namespace std;

class Student
{

protected:
int num;
char name[18];
double score;

public:
void Input()
{
cout<cout<<"请输入学生信息:"<cout<<"请输入学号:";
cin>>num;
cout<<"请输入名称:";
cin>>name;
cout<<"请输入成绩:";
cin>>score;
}

void Show() const
{
cout<if(score >= 90)
cout<<" 优";
if(score < 60)
cout<<" 不及格";
switch( int(score/10) )
{
case 8:
cout<<" 良";
break;
case 7:
cout<<" 中";
break;
case 6:
cout<<" 及格";
break;
default:
break;
}
cout<}
void Write()
{
Student obj;
ofstream outfile("stu.dat", ios::binary | ios::app );

if(!outfile)
{
cout<<"打开文件失败、"<exit(1);
}

string ch;

while( 1 )
{
obj.Input();
outfile.write( (char *)&obj, sizeof( obj ) );
cout<cin>>ch;
if(ch != "Y"&&ch != "y")
break;
}

outfile.close();
}

void StudentShow() const
{
Student obj;
ifstream infile("stu.dat", ios::binary);

if( !infile )
{
cout<<"打开文件失败、"<exit(2);
}

cout<cout<infile.read( (char *) &obj, sizeof( obj ) );
while( !infile.eof() )
{
obj.Show();
infile.read( (char *) &obj, sizeof( obj ) );

}

infile.close();
}

};


int main ()
{

cout<cout<<" ||"<cout<<" ||"<cout<<" ╲╱ "<cout<<" 输入 ==》 1 写入学生信息;"<cout<<" 输入 ==》 2 输出学生信息;"<cout<<" 输入 ==》 3 退 出;"<

Student file;
char ch;
while( true )
{
cout<<" 请输入你要进行的步骤 ==》 ";
cin>>ch;
while (getchar()!='\n');

switch(ch)
{
case '1':
file.Write();
break;
case '2':
file.StudentShow();
break;
case '3':
exit(1);
dafluat:
cout<<"输入有误,";
}
}
cout<return 0;
}

相关主题
相关文档
最新文档