Home > Back-end >  The single item choice standardized test system design
The single item choice standardized test system design

Time:09-23

Don't know what is going wrong, ask the great spirit show

# include & lt; Stdio. H>
# include & lt; stdlib.h>
# include & lt; Time. H>
# define TEST struct TEST
# define SIZE sizeof (struct test)

Struct test
{
Char main [1000];
Char answer [4] [80].
Int rightanswer;
Struct test * next;
};

Int menu ();//select menu
* print TEST (TEST * head, const TEST * p).//will output file title
TEST, TEST * taketest (TEST * int size);//randomly selected topic
Void addtest (TEST * TEST);//to add subject question bank
Void the save (const TEST * head, FILE * fp);//gets the title of the save to file
The load TEST * (fp) TEST * head, the FILE *;//read the file
Int myanswer ();//the user to enter the answer
Void answer (const TEST * head, int n);//the user answer


The main ()
{
The TEST * head=NULL, temp.
Int choice, len=0, c;
The FILE * fp=fopen (" test. Dat ", "a");
The head=load (head, fp);
While ((choice=menu ())!
=3)If (choice==1)
{
Addtest (& amp; Temp);
The head=print (head, & amp; Temp);
+ + len.
}
Else if (choice==2)
{
C=600;
While (c> 500 | | c> Len)
{
Printf (" please enter the answer to the number of questions: ");
The scanf (" % d ", & amp; C);
Taketest (head, c);
}
}
Save (head, fp);
fclose(fp);
return 0;
}

TEST, TEST * taketest (TEST * int size)//from a file random topic
{
int i;
Int seed=1000;//seed
Int m [16].
Int nn=1;
Double r;

Srand (seed);//initializes the random number generator
for (i=0; i M [I]=0;
While (nn & lt; 10)//r is double-precision floating-point random Numbers, the range of 0.0 to 1.0
{
R=((double) rand ()/((double) (RAND_MAX) + (double) (1)));
I=(int) (r * size);
If (m==0) [I]
{
M [I]=1;
Nn=nn + 1;
}
The test - & gt; Next=test;
Answer (test, size);

}
Return the test;

}
Void answer (const TEST * head, int n)
{
Int I=0, t=n;
Char result [1001], * p=the result;
for(i=0; N -; The head=head - & gt; Next)
{
Printf (" % s \ nA. % s \ nB. % s \ nC % s \ nD % s \ n \ n ", the head - & gt; The main, the head - & gt; Answer [0], the head - & gt; Answer [1], the head - & gt; Answer [2], the head - & gt; Answer [3]);
If ((* p=head - & gt; Rightanswer)==(* (p + 1)=myanswer ()))
+ + I;
P +=2;
}
* p='\ 0';
Printf (" \ n % - 13-13 s % s % s \ n ", "standard answer", "your answer", "evaluation");
For (p=the result; * p!='\ 0'; P +=2)
Printf (" % - 13 c - 13 c % % s \ n ", * p, * (p + 1), * (p + 1) * p==?" Right ", "error");
Printf (" \ n you answered % d problem, right % d problem, score: %, 2 f \ n \ n ", t, I, (float) I/t * 100.00);
}

The TEST * print (TEST * head, const TEST * p)
{
TEST * p1=(TEST *) malloc (SIZE);
If (p1==NULL)
exit(0);
* p1=* p;
P1 - & gt; Next=head;
Return p1;
}


Void addtest (TEST) TEST *
{
int i=0;
Printf (" input dry: \ n ");
The scanf (" % s ", the test - & gt; The main);
While (I & lt; 4)
{
Printf (" please enter the answer options for % c: \ n ", I + 'A');
The scanf (" % s ", the test - & gt; Answer [i++]);
The fflush (stdin);
}
The test - & gt; Rightanswer=myanswer ();
}

* load TEST (TEST * head, FILE * fp)
{
The TEST temp.
While (fread (& amp; Temp, SIZE, 1, fp))
The head=print (head, & amp; Temp);
return head;
}

Void the save (const TEST * head, FILE * fp)
{
fclose(fp);
If ((fp=fopen (" test. Dat ", "w"))==NULL)
return;
While (the head)
{
Fwrite (head, SIZE, 1, fp);
The head=head - & gt; Next;
}
}


Int myanswer ()
{
Char c='a';//here
The fflush (stdin);
If ((c>='A' & amp; & C & lt;='D') | | (c>='a' & amp; & C & lt;='d'))//here
{
Printf (" please input A, B, C, D/A, B, C, D: ");
The scanf (" % c ", & amp; C);
}
return c;
}


Int menu ()
{
The int value.
Printf (" 1 - add choice \ n2 - answer choice \ n3 - exit \ n ");
The scanf (" % d ", & amp; Value);
return value;
}

CodePudding user response:

First of all, don't know whether the file is opened at data correctly, to do a test
The second
The TEST * print (TEST * head, const TEST * p)
{
TEST * p1=(TEST *) malloc (SIZE);
If (p1==NULL)
exit(0);
* * p;
this assignment can not be directly, part of an array of structure containing, needs to be replicated in the past, not the assignment in the past,
With memcpy, strcpy function to copy the contents of the array
p1 - & gt; Next=head;
Return p1;
}

CodePudding user response:

Fun
reference 1 floor response:
first of all don't know whether the file is opened at the data correctly, to do a test
The second
The TEST * print (TEST * head, const TEST * p)
{
TEST * p1=(TEST *) malloc (SIZE);
If (p1==NULL)
exit(0);
* * p;
this assignment can not be directly, part of an array of structure containing, needs to be replicated in the past, not the assignment in the past,
With memcpy, strcpy function to copy the contents of the array
p1 - & gt; Next=head;
Return p1;
}

A freshman small white is not very will use to copy an array of content function, ask for help

CodePudding user response:

Looking at didn't question it

CodePudding user response:

Option 2 to answer the question whether answer answer wrong will always repeat the question just now
  • Related