#include
#include
#include
#include
#include
#include
const int N=20;
using namespace std;
//创建结构体
struct student
{
string name;//姓名
string xh;//学号
int age;//年龄
int score;//分数
} ;
int main()
{
string name;//姓名
string xh;//学号
int age;//年龄
int score;//分数
//判断是否为青年
cout<<"请依次输入: 姓名、学号、年龄;" <<endl;
cin>>name>>xh>>age;
if(16<=age && age<=18)
cout<<"您的题目为青年题目(共十题)"<<endl;
else
cout<<"非青年"<<endl;
//打开试卷
ifstream cin("1.txt");
//显示试卷内容并答题
string s;
int n=0;
while(n<2)//题目的数量 n
{
getline(cin,s,'.');
cout<<s<<endl;
string answer;
cout<<"您的答案为:"<<endl;
cin>>answer;
string m;
getline(cin,m,'.');
if(answer==m)
{
cout<<"right"<<endl;
score+=10;
}
else
{
cout<<"wrong"<<endl;
}
++n;
}
cout<<"您取得的成绩为:"<<score<<endl;
//保存成绩到score.txt文件
ofstream cout("score.txt",ios::app);
cout<<name<<" "<<xh<<" "<<age<<" "<<score<<endl;
//读出文件并按照成绩排序
ifstream px("score.txt");
string ss;
int m=0;//有成绩记录的学生总数
while(getline(px,ss))
++m;
// cout<<"共有学生:"<<m<<endl;
//创建成绩数组
student stud[m];
for(int i=0;i<m;++i)
{
string str;
getline(px,str,' ');
stud[i].name=str;
getline(px,str,' ');
stud[i].xh=str;
getline(px,str,' ');
stringstream ss1;//string转化为int
ss1<<str;
ss1>>stud[i].age;
getline(px,str,' ');
stringstream ss2;
ss2<<str;
ss2>>stud[i].score;
}
//排序
student temp;
int k;
for(int i=0;i<m-1;++i)
{
k=i;
for(int j=i+1;j<m;++j)
{
if(stud[k].score<stud[j].score)
k=j;
}
if(k!=i)
{
stud[i]=temp;
temp=stud[k];
stud[k]=temp;
}
}
//输出成绩单
// ofstream fout("score.txt");
for(int i=0;i<m;++i)
{
cout<<stud[i].name<<" "<<stud[i].xh<<" "<<stud[i].age<<" "<<stud[i].score<<endl;
}
}
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。