C++编程语言

2025-01-14 06:33:59
推荐回答(2个)
回答1:

#include
#include 
#include 
#include 
#include 
using namespace std;


int main(int argc, char *argv[])
{
    srand((unsigned)time(NULL));
    char name[20],symbol;
    int num,sum=0,sym,x,y,result_in,result;
    cout<<"input name and num:";
    cin>>name;
    cin>>num;
    cout<    cout<<"let's begin test:"<    for(int i=0;i<10;i++)
    {
        sym = rand()%10;
        if(sym>6)
            symbol = '-';
        else
            symbol = '+';
        x = rand()%100+1;
        y = rand()%100+1;
        do
        {
            x = rand()%100+1;
            y = rand()%100+1;
        }while(x        if(symbol == '-')
            result = x-y;
        else
            result = x+y;
        cout<        cin>>result_in;
        if(result == result_in)
        {
            cout<<"   correct!"<            sum+=10;
        }
        else
            cout<<"   error!"<
    }
    cout<<"your total socre is "<    ofstream fout("D:\score.txt");
    fout << "Number: " << num << "\n";
    fout << "Name: " << name<<"\n";
    fout << "Score: " << sum << "\n";
    fout << flush; fout.close();

    return 0;
}

回答2:

#include 
#include 
#include 
using namespace std;

int test(int c)
{
  int a, b;
  //int c;
  int answer;
  while(true)
  {
    a=rand()*100;
    b=rand()*100;
    if(a+b<=100 && a-b>=0)
      break;
   }
   char op;
   op=(c==0)?'+':'-';
   cout<   cin>>answer;
   int result;
   if(op=='+')  result=a+b;
   if(op=='-')  result==a-b;
   if(answer==result)
      return 10;
   else
      return 0;   
}

int main()
{
   int num;
   int score=0;
   string name;
   cout<<"请输入学号:";cin>>num;
   cout<<"请输入姓名:";cin<   int c;
   int add=0;
   int sub=0;
   
   for(int i=0;i<10;i++)
   { 
     c=rand()*2;
     if(c==0) add++;
     if(add>7)
        c=1;
     if(c==1)  sub++;
     if(sub>3)
        c=0;
     score=score+test(c);
    }
   ofstream  f;
   f.open("score.txt",ios::out);
   if(!f) {cerr<<"文件打开失败";exit(0);}
   f<<"学号\t姓名\t成绩\n";
   f<}