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<
cin>>num;
cout<<"请输入名称:";
cin>>name;
cout<<"请输入成绩:";
cin>>score;
}
void Show() const
{
cout<
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<<"打开文件失败、"<
}
string ch;
while( 1 )
{
obj.Input();
outfile.write( (char *)&obj, sizeof( obj ) );
cout<
if(ch != "Y"&&ch != "y")
break;
}
outfile.close();
}
void StudentShow() const
{
Student obj;
ifstream infile("stu.dat", ios::binary);
if( !infile )
{
cout<<"打开文件失败、"<
}
cout<
while( !infile.eof() )
{
obj.Show();
infile.read( (char *) &obj, sizeof( obj ) );
}
infile.close();
}
};
int main ()
{
cout<
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<
}