首页 > 用户发贴区 > 编程问题提问区 > 小妹需要帮助
2009
01-05

学校外教给布置的编程题,小妹没学过编程,请帮帮我啊。


题目如下:(全是英文的)


Course Work


 


Write a program that will help elementary school pupils practice math.


 


a)      The program will first ask the user for his/her ID number (including two letters & 4 digits), e.g.


Please input your four digit ID no: AB1234


  


       The program should have input validation.


 


Then the program prompts three choices:


(1)   Start a test


(2)   Check scores


(3)   Exit


 


b)      Test: the program will give 10 math problems, e.g.:


 


12 *  3 = 36


48 + 32 = 80



56 / 28 = 2


 


Note:


i) Pupils will answer each problem before the next one is given.


 


ii) The problems should include addition, subtraction, multiplication and division. They are randomly generated.


 


iii) Randomly generates numbers for problems. However, must ensure that both the problem and the result are no larger than two digits. The problem and the result should be greater than or equal to zero. The divisor cannot be zero.


 


iv) After ten problems are finished, record the time used by the student to do the ten problems.


 


v) Gives a score to each student. Saves this student’s ID, his/her score and the time used into a file named ‘record.txt’.


 


vi) Print the following information on the screen:


Prob. | Correct Answ.  |  Ur Answ


 


c)      Check scores: Searches the file ‘record.txt’ and lists all the historical scores for this student, e.g.:


 


Your previous records are:


AB1234  80  150 seconds


AB1234  50  182 seconds


AB1234  90  98 seconds


 


 


 


 


 


 


Your programming report should include:


(1)    Title page


(2)    Pseudocode or flowchart to describe the algorithm of your program


(3)    The C source file


(4)    The printout on the screen


 


 


 


You will be marked based on your program’s:


(1)    Correctiveness


(2)    Readability


(3)    Robustness


(4)    Conciseness


——————————————————————————————————


请各位哥哥帮帮啊!谢谢!


小妹需要帮助》有 3 条评论

  1. 细雨霏霏 说:

    有个错误提示:

    error:do statement must have while

    帮我看看啊

    —————————————————————————————————— 

      #include<stdio.h>
       #include<stdlib.h>/*to ues the srand(),rand()and exit() functions*/
       #include<time.h>/*to use the time() function*/
       #include<string.h>/*to ues the strlen() functions*/
       #include<ctype.h> /*to use the isalpha() and isdigit()functions*/
       #define IDNUM 7
       #define TNUM 10
       #define T 1
       #define F 0

       int main()
       {
        int ValidID(char []);
        void Test(char []);
        void Check(char []);
        FILE *fp;
        char ID[IDNUM],IDnumber[IDNUM];
      
        int choice,j,i;
        int score,time;

        printf(“*********************************************************\n”);
        printf(“               Welcome to use this system! \n “);
        printf(“                    ****************\n”);
        printf(“                Made by Miao Zhou(08213196)\n”);
        printf(“**********************************************************\n”);
     
        inputIDnumber:
        printf(“Please enter your ID number:\n”);
        gets(ID);

        while(ValidID(ID)==F) /*check whether the number is valid */
         {
           printf(“\nSorry, this number is not valid! Please enter another one.\n”);
           goto inputIDnumber;/* enter an ID again */
         
          }
           printf(“                  Hello! No.%s!\n”,ID);
           printf(“\n”);
        do
         {
          printf(“\nWhat do you want to do?\n”);/*choose what the student want to do.*/
          printf(“(a) Start a test.\n”);
          printf(“(b) Check your scores.\n “);
          printf(“(c) Exit.\n”);
          printf(“\nPlease enter the nunber your choice:\n”);
          scanf(“%c”,&choice);

         switch(choice)
          {
           case’a':/*choose 1 and begin a test.*/
           printf(“\nWelcome to enter the test.\nPlease answer the question one by one.\n”);
           Test(ID);
           break;

           case’b':
           fp=fopen(“record.txt”,”a”);
            if( fp == NULL ) /*to check whether the file is opened successfully*/
            {
       printf(“\nError!The file can not be opened.\n”);
       exit(1);
             }   
              i = 0;  /*initialize i to 0 */
              while( fscanf(fp,”%4s   %4d   %4d “,&IDnumber,&score,&time)!=EOF )
               {
                if( strcmp(ID,IDnumber)==0 )/*if the recorded ID is the same as the studnet’s ID*/
          {
            printf(“%10s %10d %10d seconds\n”,IDnumber,score,time);/*printf the record*/
            i=+1;
           }
                }
             
              if(i==0)   /*Check whether there exists records for the student or not*/
              printf(“Sorry!There is no record of your ID No.\n”);
              fclose(fp);/*close the file*/
              break;

           case’c':
           exit(1);
           }while(1);
           return 0;

        }

      int ValidID(char ID[IDNUM])/* ensure whether the ID is valed */
       {
        int a;
        if(strlen(ID)!=IDNUM)
        return 0;           /* ensure the number of the characters are 6.*/
        for(a=0;a<=1;a++)
        if(isalpha(ID[a])==0)
        return 0;            /* ensure the first and the second characters are litters.*/
        for(a=2;a<=5;a++)
        if(isdigit(ID[a])==0)
        return 0;            /* ensure the others are digits.*/

        return 1;/*ID is valid, return 1 to the function.*/
      }

     void Test(char ID[IDNUM])
     {
     
       int num1,num2,condition,i,j;
       int correct_a[TNUM],student_a[TNUM];
       int score=0;
       char sim;
       char n1[TNUM],n2[TNUM],sym[TNUM];
       long int start,end,all;

       printf(“\n Print Enter to start the test.\n”);
       getchar();
      
       srand(time(NULL));/*generate a “seed” value.*/
       start=time(NULL);/* start to record the time.*/
    for(i=0;i<10;)
    {
       do
        {
          n1[i]=0+(int)rand()%100;
          n2[i]=0+(int)rand()%100;
          condition=1+(int)rand()%100;

          switch(condition)
            {
              case 1:
              sim=’+';
              correct_a[i]=n1[i]+n2[i];
              break;

              case 2:
              sim=’-';
              correct_a[i]=n1[i]-n2[i];
              break;

              case 3:
              sim=’*';
              correct_a[i]=n1[i]*n2[i];
              break;

              case 4:
              sim=’/';         
              correct_a[i]=n1[i]/n2[i];
              break;
             }    
          
            if(correct_a[i]>100||correct_a[i]<0||correct_a[i]||n1[i]%n2[i]=0||n2[i]==0)
            {
              i=i;
              continue;
             }
            else
             {
               printf(“%d %c %d =”,n1[i],sim,n2[i]);
               scanf(“%f”,&student_a[i]);
       
               if(correct_a[i]=student_a[i])
                  {
                   score=score+10;
                    i++;
                   
                   }
              }
              j=1;
            }while(j=1)
       }           
          end=time(NULL);
          all=(end-start)/CLK_TCK;
     
     FILE *outfile;
     
     outfile=fopen(“record.txt”,”a”);
     
     if (outfile==NULL)
      {
      printf (“Failed to open the file.\n”);
      exit(1);
      }
            fprintf(outfile,”%s   %d   %d \n”,ID,score,all);
            fclose(outfile);

          printf(“\n The test end.\n\n”);
          printf(“\n      Prob.      |     Correct Answ.       |     Ur Answ.   \n”);
          for(i=0;i<TNUM;i++)
         {
           printf(“(%d)%3d %c %4d         %12d       %15d\n”,i+1,n1[i],sym[i],n2[i],correct_a[i],student_a[i]);
           }
          printf(“\n\n You spent %d seconds to finish the test.”,end-start);
          printf(“\n You score is %d.”,score);

    printf(“\n Press Enter to return to menu.”);
    getchar();
    }}}

  2. hiroki 说:

    真是不错啊

  3. 细雨霏霏 说:

    哥哥啊,不错什么啊,调试通过不了。

留下一个回复