You are on page 1of 38

RV College of Engineering®

(Autonomous Institution Affiliated to VTU, Belagavi)

TITLE:
Experiential Report on Making a Quiz program using C language

Submitted by
Abhishek Bhagat-1RV20IS002

Information Science and Engineering

Submitted to
Prof. Raghavendra Prasad S G
Contents

1. Introduction.
2. Objectives.
3. Literature Review.
4. Methodology.
5. Results and Discussion.
6. References
1) Introduction

C is a procedural programming language. It was initially developed by Dennis Ritchie in the


year 1972 It was mainly developed as a system programming language to write an operating
system. The main features of the C language include low-level memory access, a simple set
of keywords, and a clean style, these features make C language suitable for system
programming like an operating system or compiler development.
We have created a quiz program using the C programming language, which will include
different kind of question such as multiple choice question, true false, fill in the blanks, error
correcting, output finding, etc.

2) Objectives
2.1) Look into the various problems encountered during the making of
quiz and find it’s solution.
2.2) Learning the various functions which will make the quiz more
user friendly
2.3) Make a quiz consisting of the following features:-
 The quiz will include different kind of question such as multiple choice question, true
false, fill in the blanks,error correcting,program output etc.

 Each quiz will be timed with a time limit of 10 minutes.

 Each quiz will be of 10 marks.

 Random questions will be given from different units.

 The quiz also has a main menu.

 Answers will be reviewed.

 Marks will be shown at the end and a scorecard will be given.

 The User is supposed to select any 3 units out of 5.

 3 Quizzes will be conducted of 1 unit each based on the choice of the user.

 Each Quiz of 10 marks and have 4 parts-

PART 1-Fill in the blanks-contains 3 questions and has a time of 3 minutes. The user
must answer 'true' or 'false’.
PART 2-Choose the correct options-contains 3 questions and has a time of 3 minutes.
The user must answer ‘a’, 'b’, 'c' or ‘d’.
PART 3-Fill in the blanks-contains 2 questions and has a time of 2 minutes. The user
must type the correct answer.
PART 4-Correcting the error and output-contains 2 questions and has a time of 2
minutes. The user must type the correct answer.
 User can check their marks and reviews.

 The 3 quizzes scores will be averaged and displayed.

 If any kind of correction is required, allow contacting host for marks correction and
finalization.

3) LITERATURE REVIEW
The following functions have been used in our C quiz.

3.1) Time.h
The time.h header file contains definitions of functions to get and manipulate date and time
information.
It describes three time-related data types.
clock_t: clock_t represents the date as an integer which is a part of the calendar time.
time_t: time_t represents the clock time as an integer which is a part of the calendar time.
struct tm: struct tm holds the date and time. It also contains CLOCKS_PER_SEC macro which
holds the number of times does the system clock ticks per second and Pre-defined functions in
time.h.
Sr no. Function Explanation

1 asctime() This function returns the date and time in the format
day month date hours:minutes:seconds year.
Eg: Sat Jul 27 11:26:03 2019.
asctime() function returns a string by taking struct tm variable
as a parameter.
2 clock() This function returns the processor time consumed by a
program
3 ctime() This function returns the date and time in the format
day month hours:minutes:seconds year
Eg: Sat Jul 27 11:26:03 2019
time is printed based on the pointer returned by Calendar
Time
4 difftime() This function returns the difference between the times
provided.
5 gmtime() This function prints the UTC (Coordinated Universal Time)
Time and date.
Format for both gmtime() and asctime() is same
6 mktime() This function returns the calendar-time equivalent using
struct tm.
7 time() This function returns the calendar-time equivalent using data-
type time_t.
8 strftime() This function helps to format the string returned by other time
functions using different format specifiers

3.2) rand ()
In the C language, the rand() function is used for Pseudo Number Generator(PRNG). The
random numbers generated by the rand() function are not truly random. It is a sequence that
repeats periodically, but the period is so large that we can ignore it. The rand() function works
by remembering a seed value that is used to compute the next random number and the next new
seed. In this article, we are going to discuss in detail how random numbers can be generated
using the rand() function. This function returns the next pseudo-random number in the series.
The range value of the number series is between 0 and RAND_MAX. RAND_MAX is a macro
defined in stdlib.h header file, whose value is the maximum value, which can return by rand()
function. The value of RAND_MAX is greater but not less than 32767 depending on the C
libraries. The value sequence of the rand() function is the same each time we run the program.
By default, the seed of the rand function is set to 1. We can set the seed for the rand function
using the srand() function. The seed can be set only once, and before the first
time rand() function call.

Syntax:
int rand(void):
returns a pseudo-random number in the range of [0, RAND_MAX).
RAND_MAX: is a constant whose default value may vary
\between implementations but it is granted to be at least 32767.

3.2) srand()

The pseudo-random number generator is initialized using the argument passed as seed.
For every different seed value used in a call to srand, the pseudo-random number generator can
be expected to generate a different succession of results in the subsequent calls to rand. Two
different initializations with the same seed will generate the same succession of results in
subsequent calls to rand. If seed is set to 1, the generator is reinitialized to its initial value and
produces the same values as before any call to rand or srand.
In order to generate random-like numbers, srand is usually initialized to some distinctive
runtime value, like the value returned by function time (declared in header <ctime>). This is
distinctive enough for most trivial randomization needs.
It doesn’t return any values.
Syntax:
void srand( unsigned seed ):
Seeds the pseudo-random number generator used by rand() with the value seed.

3.3) System(“cls”)
The system function is part of the C standard library, prototyped in <stdlib.h>. It allows you to
programmatically send commands to the operating system’s command processor, if any. The
string argument you pass into the system function is executed by the operating system’s
command processor.

Some, but not all, operating systems provide the “cls” command to clear the console window or
terminal screen, positioning the cursor in the upper left corner. However, this specific command
is not present in all operating system command processors. The command is available in
Windows, OS/2, MS-DOS, PC-DOS, FlexOS, ReactOS, DEC RT-11, etc. Some, but not all,
Linux and Unix derivatives provide the “clear” command to perform this action. Some
operating systems do not provide any command to clear the console window/screen/terminal.

3.4) Structure

Structure is a user-defined datatype in C language which allows us to combine data of different


types together. Structure helps to construct a complex data type which is more meaningful. It is
somewhat similar to an Array, but an array holds data of similar type only. But structure on the
other hand, can store data of any type, which is practical more useful.

For example: If I have to write a program to store Student information, which will have
Student's name, age, branch, permanent address, father's name etc, which included string values,
integer values etc, how can I use arrays for this problem, I will require something which can
hold data of different types together.

In structure, data is stored in form of records.

Struct keyword is used to define a structure. Struct defines a new data type which is a collection
of primary and derived data types.

Syntax:

struct [structure_tag]

//member variable 1

//member variable 2

//member variable 3

}[structure_variables];

As you can see in the syntax above, we start with the struct keyword, then it's optional to
provide your structure a name, we suggest you to give it a name, then inside the curly braces,
we have to mention all the member variables, which are nothing but normal C language
variables of different types like int, float, array etc.
After the closing curly brace, we can specify one or more structure variables, again this is
optional.

It is possible to declare variables of a structure, either along with structure definition or after
the structure is defined. Structure variable declaration is similar to the declaration of any
normal variable of any other datatype. Structure variables can be declared in following two
ways:

1) Declaring Structure variables separately


2) Declaring Structure variables with structure definition

Structure members can be accessed and assigned values in a number of ways. Structure
members have no meaning individually without the structure. In order to assign a value to any
structure member, the member name must be linked with the structure variable using a
dot . operator also called period or member access operator.

3.5) Switch

The switch statement in C is an alternate to if-else-if ladder statement which allows us to


execute multiple operations for the different possibles values of a single variable called switch
variable. Here, We can define various statements in the multiple cases for the different values of
a single variable.

The syntax of switch statement in c language is given below:

switch(expression){

case value1:

//code to be executed;

break; //optional

case value2:
//code to be executed;

break; //optional

......

default:

code to be executed if all cases are not matched;

Functioning of switch in C

First, the integer expression specified in the switch statement is evaluated. This value is then
matched one by one with the constant values given in the different cases. If a match is found,
then all the statements specified in that case are executed along with the all the cases present
after that case including the default statement. No two cases can have similar values. If the
matched case contains a break statement, then all the cases present after that will be skipped,
and the control comes out of the switch. Otherwise, all the cases following the matched case
will be executed.
3.6) Goto

The goto statement is known as jump statement in C. As the name suggests, goto is used to
transfer the program control to a predefined label. The goto statement can be used to repeat
some part of the code for a particular condition. It can also be used to break the multiple loops
which can't be done by using a single break statement. However, using goto is avoided these
days since it makes the program less readable and complicated.

Syntax:

label:

//some part of the code;

goto label;

The only condition in which using goto is preferable is when we need to break the multiple
loops using a single statement at the same time.
3.7)Loops

In programming, a loop is used to repeat a block of code until the specified condition is met.

C programming has three types of loops:

1)for loop

2)while loop

3)do...while loop

For Loop

The syntax of the for loop is:

for (initializationStatement; testExpression; updateStatement)

// statements inside the body of loop

How for loop works?

The initialization statement is executed only once.

Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is
terminated.

However, if the test expression is evaluated to true, statements inside the body of the for loop
are executed, and the update expression is updated.

Again the test expression is evaluated.

This process goes on until the test expression is false. When the test expression is false, the loop
terminates.

Flow chart of FOR LOOP


While loop

The syntax of the while loop is:

while (testExpression) {

// the body of the loop

How while loop works?

• The while loop evaluates the test Expression inside the parentheses ().
• If test Expression is true, statements inside the body of while loop are executed. Then,
test Expression is evaluated again.
• The process goes on until test Expression is evaluated to false.
• If test Expression is false, the loop terminates (ends).
3.8) if...else Statement

The if statement may have an optional else block. The syntax of the if..else statement is:

if (test expression) {

// run code if test expression is true

else {

// run code if test expression is false

How if...else statement works?

• If the test expression is evaluated to true, statements inside the body of if are executed
and statements inside the body of else are skipped from execution.
• If the test expression is evaluated to false, statements inside the body of else are
executed and statements inside the body of if are skipped from execution.

4) Methodology

4.1) Storing of questions


This can be done using structures
struct Units
{
char questions[41][200];
char answers[41][100];
char input[41][100];
char temp_input[41][100];
int random_number[31];

} units[6];
These are the various inputs in structure.
strcpy(units[1].questions[1],"Spaces and commas are allowed in a variable name");
strcpy(units[1].answers[1],"false");
This is an example of question added , added here is the question from first unit first question
same has been done with answer.
4.2) Main menu
This has been made using switch statement and goto, system(“cls”) has been used to clear
screens each option. The code is
switch(menu_option)
{
case 0:
{
goto instructions;
}
case 1:
{
if(unit_entered_checker==1)
{
printf("\nYOU HAVE ALREADY ENTERED THE UNITS\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
else
{
goto unitchecker;
}
}
case 2:
{
if (quiz_attempt_finished_checker==1)
{
printf("\nYOU HAVE ALLREADY FINISHED THE QUIZ ATTEMPTS\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
else if(unit_entered_checker==0)
{
printf("\nENTER THE UNITS FIRST\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
{
goto quiz;
}
}
case 3:
{
if(marks_and_review_opener!=1)
{
printf("\nATTEMPT QUIZ FIRST\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
else
{
goto score;
}
}
case 4:
{
if(marks_and_review_opener!=1)
{
printf("\nATTEMPT QUIZ FIRST\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
else
{
goto review;
}
}
case 5:
{
if (marks_and_review_opener!=1)
{
printf("\nATTEMPT QUIZ FIRST\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
else
{
goto markschanger;
}
}
case 6:
{
goto quit;
}
default:
{
printf("\nYou have entered an invalid input\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}

}
In this way switch statement and goto has been used the user can select any of the seven
numbers, giving wrong input will result in an error, flags like “unit_entered_checker” has been
used to make sure to make smooth continuity, for eg: In case 1 using :unit_entered_checker”
prevents the player from selecting the units again and again. This has been done for all the
options.

4.3) Entering the units


The process is very simple. The code is
unitchecker:
system("cls");
unit_selection_checker[1]=0;unit_selection_checker[2]=0;unit_selection_checker[3]=0;unit_selection_c
hecker[4]=0;unit_selection_checker[5]=0;
{
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nWhich three units you would like the quiz of\n");
for(unit=1;unit<4;unit++)
{
scanf("%d",&unit_selected[unit]);
unit_selection_checker[unit_selected[unit]]=1;
}
for(unit=1;unit<4;unit++)
{

if(unit_selected[unit]>5||unit_selected[unit]<1)
{
printf("\nYou have enterend invalid input please select from 1-5\n");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto unitchecker;
}
}

if(unit_selected[1]==unit_selected[2]||unit_selected[2]==unit_selected[3]||unit_selected[3]==unit_selecte
d[1])
{
printf("\nYou have entered a unit more than once please try again\n");
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto unitchecker;
}
printf("\nYou have successfully entered the units\n");
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
unit_entered_checker=1;
goto mainmenu;
}
Here three user inputs are taken and it is saved in the array unit_selected, then comparisions is
made between them to make sure that they are valid, if valid we go to mainmenu else input is
asked to be taken again.Once input is correctly entered the value of unit_entered_checker is
changed to prevent them from changing the units once again.
4.4) The main quiz
The main quiz is conducted using loops. The code is
quiz :
system("cls");
{
if(quiz_attempt_finished_checker==1)
{
printf("You have completed the quiz attempt");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
while(quiz_attempt_number<4)
{
time_start=time(NULL);
srand(time(0));
question_number=1;
seconds_passed=0;
printf("\nYou are attempting quiz from unit %d\n",unit_selected[quiz_attempt_number]);
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPART 1-TRUE OR FALSE\n");
seconds_passed=0;
while(question_number<4)
{
quizattempt(unit_selected[quiz_attempt_number],1,180);
}
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
system("cls");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPART 2-CHOOSE THE CORRECT OPTION\n");
time_start=time(NULL);
seconds_passed=0;
while(question_number<7)
{
quizattempt(unit_selected[quiz_attempt_number],11,180);
}
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
system("cls");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPART 3-FILL IN THE BLANKS\n");
time_start=time(NULL);
seconds_passed=0;
while(question_number<9)
{
quizattempt(unit_selected[quiz_attempt_number],21,120);
}
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
system("cls");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPART 4-CORRECTING THE ERROR OR SHOWING THE OUTPUT QUESTIONS\n");
time_start=time(NULL);
seconds_passed=0;
while(question_number<11)
{
quizattempt(unit_selected[quiz_attempt_number],31,120);
}
unit_selection_checker[unit_selected[quiz_attempt_number]]=2;
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
marks_and_review_opener=1;
quiz_attempt_number++;
break;
}
if(quiz_attempt_number==4)
{
quiz_attempt_finished_checker=1;
}
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
system("cls");
goto mainmenu;
}
It has four parts, for each part the quiz is conducted using quizattempt function which takes
three inputs ,the unit number,the question divider used for rand() function, and the time limit.
The start time is reset before each part .Quiz can be attempted a total of three times,after which
the flag quiz_attempt_finished_checker changes it’s value and prevents access.
The code for the function quiz attempt is
void quizattempt(int unit_selected,int question_divider,int time_limit)
{
if(seconds_passed<time_limit)
printf("YOU HAVE %d SECONDS LEFT",time_limit-seconds_passed);
else
printf("\nOUT OF TIME\n");
units[unit_selected].random_number[question_number]=rand()%10+question_divider;
printf("\nQUESTION NUMBER--
%d\n%s\n",question_number,units[unit_selected].questions[units[unit_selected].random_number[questi
on_number]]);
fflush(stdin);
do{
gets(units[unit_selected].input[units[unit_selected].random_number[question_number]]);
} while(units[unit_selected].input[units[unit_selected].random_number[question_number]][0] ==
'\0');

strcpy(units[unit_selected].temp_input[units[unit_selected].random_number[question_number]],uni
ts[unit_selected].input[units[unit_selected].random_number[question_number]]);
strlwr(units[unit_selected].temp_input[units[unit_selected].random_number[question_number]]);
time_end=time(NULL);
seconds_passed=time_end-time_start;
if(strcmp(units[unit_selected].temp_input[units[unit_selected].random_number[question_number]],
units[unit_selected].answers[units[unit_selected].random_number[question_number]])==0 && seconds_
passed<time_limit)
{
printf("\nYou are correct\n");
marks[unit_selected]++;
}
else if ( seconds_passed>=time_limit)
{
printf("\nYou are too slow\n");
strcpy(units[unit_selected].input[units[unit_selected].random_number[question_number]],"You
were too slow");
}
else
{
printf("\nYour answer is wrong\n");
printf("\nThe correct answer is %s\n",units[unit_selected].answers[units[unit_selected].random_nu
mber[question_number]]);
}
question_number++;
}
Here the question to be selected from the storage space is stored in-
“units[unit_selected].random_number[question_number]” which is randomized using rand()
function. This is intern used to access the questions and answer for eg the question is accessed
by -“units[unit_selected].questions[units[unit_selected].random_number[question_number]]”.
The answer entered is stored in the same way. The entered answer is copied to another one in
changed to small letters and then compared with stored one and give result whether it is right or
wrong. Time is also taken into consideration here. The remaining time is printed at the top
before each question. Marks of that is increased if correct else nothing is done.
4.5) Score checking
The code or this is
score:
system("cls");
{
loop_key=1;
while(loop_key==1)
{
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nWhich units would you like to see the marks of\n");
printf("\nPRESS 6 TO SEE YOUR FINAL MARKS\n");
printf("\nPRESS 0 TO GOTO MAINMENU\n");
scanf("%d",&unit);
if(unit==6 && quiz_attempt_finished_checker==1)
{
goto total_marks;
}
if(unit==6 && quiz_attempt_finished_checker!=1)
{
printf("Please finish your attempt first");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto score;
}
if(unit==0)
{
goto mainmenu;
}
if(unit_selection_checker[unit]==0)
{
printf("\nYou have not selected this unit for the quiz\n");
printf("\n-------------------------------------------------------------------------------------------------------
-------\n");

printf("\nPRESS ANY KEY TO CONTINUE\n");


getch();
goto score;
}
if(unit_selection_checker[unit]==1)
{
printf("\nYou have not attempted the quiz. TRY again after attempting\n");
printf("\n----------------------------------------------------------------------------------------------------
----------\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto score;
}
else

{
attemptcheck(unit,1);
attemptcheck(unit,2);
attemptcheck(unit,3);
attemptcheck(unit,4);
attemptcheck(unit,5);
}
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto score;
}
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
total_marks:
{
if(quiz_attempt_finished_checker==1)
{
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
total=(marks[1]+marks[2]+marks[3]+marks[4]+marks[5])/3;
printf("\nYour Final score is %.2f\n",total);

printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
}
}
goto mainmenu;
}

The first few if statements check whether the units have entered or quiz has been attempted
atleast once, if all of this is satisfied it asks for the unit whose mark should be selected, pressing
0 can allow to exit the loop and goto the mainmenu, when entered the unit it first checked
whether the input is proper / valid if yes it is carried to the function attemptcheck which has 2
inputs unit entered and numbers 1,2,3,4,5. Pressing 6 at the unit entering function gives the final
score if all the 3 attempts are finished.
The code for the function attemptcheck is
void attemptcheck(int unit_selected,int unit_compared)
{
if(unit_selected==unit_compared)
{
printf("\nYou have attemped quiz from Unit %d\n",unit_selected);
printf("\nYour score from this Unit is %d\n",marks[unit_selected]);
}
}
Here what is done is pretty simple unit_selected and unit_compared is checked and if both are
equal the score is displayed.
4.6) Review
The code for checking the review is
review:
system("cls");
{
loop_key=1;
while(loop_key==1)
{
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");

printf("Which unit would you like the review of\n");


printf(" \n0 TO GOTO MAINMENU\n");
scanf("%d",&unit);
if(unit==0)
{
goto mainmenu;
}
if(unit_selection_checker[unit]==0)
{
printf("\nYou have not selected this unit for the quiz\n");
printf("\n----------------------------------------------------------------------------------------------------------
----\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto review;
}
if(unit_selection_checker[unit]==1)
{
printf("\nYou have not attempted the quiz. TRY again after attempting\n");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");

printf("\nPRESS ANY KEY TO CONTINUE\n");


getch();
goto review;
}
else
{
reviewcheck(unit,1);
reviewcheck(unit,2);
reviewcheck(unit,3);
reviewcheck(unit,4);
reviewcheck(unit,5);
}
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
}
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
It’s structure is pretty similar to that of score viewing. 0 leads to main menu, The first if
statements are entered unit validity checker ,the function used here is reviewcheck which has 2
inputs similar to that of attempt check
The code for reviewcheck is

void reviewcheck(int unit_selected,int unit_compared)


{

if(unit_selected==unit_compared)
{
question_number=1;
printf("\nReview from unit %d\n",unit_selected);
for(question_number=1;question_number<11;question_number++)
{
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nQuestion %d--
>%s\n",question_number,units[unit_selected].questions[units[unit_selected].random_number[question_n
umber]]);
printf("\nCorrect answer %s\n",units[unit_selected].answers[units[unit_selected].random_number[que
stion_number]]);
printf("\nYour answer %s\n",units[unit_selected].input[units[unit_selected].random_number[question
_number]]);
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
system("cls");
}

}
}
The working is same as attemptcheck if both input are equal it displays the 10 questions along
with the answers by calling on the unique Id of each question.
4.7) Marks changing
This option has been input to correct the limitations of the quiz conducted, for example if the
answer for the quiz is ‘large’ but we enter it as ‘great’ the answer is correct but it will be
displayed as answer is wrong, so in this case the if the marks has to be changed this option can
be used.
markschanger:
system("cls");
{
printf("\n--------------------------------------------------------------------------------------------------------------
\n");

printf("\nEnter Password\n");
{
scanf("%s",&password);
}
unit=0;loop_key=1;
while(strcmp(password,"PICEL123")!=0)
{
unit++;
printf("\nWRONG PASSWORD!!\n");
printf("\nTRY AGAIN!!!\n");
scanf("%s",&password);
if(unit==3)
{
printf("\nOut of attempts try again from mainmenu\n");
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto mainmenu;
}
}
passwordless:
system("cls");
printf("\n--------------------------------------------------------------------------------------------------------------
\n");

{
while(loop_key==1)
{
printf("\nWhich units would you like to correct\n");
printf("\nPRESS 0 TO GOTO MAINMENU\n");
scanf("%d",&unit);

if(unit==0)
{
goto mainmenu;
}
if(unit_selection_checker[unit]==0)
{
printf("\nYou have not selected this unit for the quiz\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto passwordless;
}
if(unit_selection_checker[unit]==1)
{
printf("\nYou have not attempted the quiz. TRY again after attempting\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
goto passwordless;
}
else
{
markscorrect(unit,1);
markscorrect(unit,2);
markscorrect(unit,3);
markscorrect(unit,4);
markscorrect(unit,5);
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");
printf("\nPRESS ANY KEY TO CONTINUE\n");
getch();
}
}
}
goto mainmenu;
}
The only thing different from the score checker and review checker is that the A PASSWORD
has to be entered without which the marks cannot be changed. The PASSWORD will only be
known by the host of the quiz. The PASSWORD is PICEL123 when entered it allows a menu
with functionality as the previous two. The function used is here markscorrect. It’s code is
void markscorrect(int unit_selected,int unit_compared)
{
if (unit_selected==unit_compared)
{
printf("\nYour score in the selected lesson is %d\n",marks[unit_selected]);
printf("\n You want to change the score to \n");
scanf("%d",&marks[unit_selected]);
while(marks[unit_selected]>10&&marks[unit_selected]<0)
{
printf("Enter a score between 0 to 10\n");
scanf("%d",&marks[unit_selected]);
}
printf("\n CHANGE SUCCESFUL");
}
}
After passing of the if barrier in a similar way to previous two, it displays the current score and
we can change it the correct one, if a input other than 0 to 10 is entered it displays an error. In
way score is displayed.
4.8) Scorecard
Finally when the player chooses to quit the scorecard is displayed
quit:
{
FILE *filePointer ;
int system ( const char * command );
char grade;
printf("\n--------------------------------------------------------------------------------------------------------------
\n");
if(quiz_attempt_finished_checker==1)
{
total=(marks[1]+marks[2]+marks[3]+marks[4]+marks[5])/3;
if(total>=9)
grade='S';
else if(total>=8)
grade='A';
else if(total>=7)
grade='B';
else if(total>=6)
grade='C';
else if(total>=5)
grade='D';
else if(total>=4)
grade='E';
else
grade='F';

filePointer=kdkfopen("Scorecard.txt","w") ;
if ( filePointer == NULL )
{
printf("-----------------------------------------------------------------------------------------\n");
printf("| SCORECARD |\n");
printf("| Congratulations!! |\n");
printf("| %-40s |\n",name);
printf("| Report:- |\n");
printf("| Unit Attempted Score |\n");
printf("|1. Unit-
%d %2d |\n",unit_selected[1],marks[unit_selected[1]]);
printf("|2. Unit-
%d %2d |\n",unit_selected[2],marks[unit_selected[2]]);
printf("|3. Unit-
%d %2d |\n",unit_selected[3],marks[unit_selected[3]]);
printf("|Your final Score is: %-6.2f |\n",total);
printf("|Your final GRADE is: %-6.2c |\n",grade);
printf("|Thank you for Attempting our quiz |\n");
printf("-----------------------------------------------------------------------------------------");
}
else
{
fprintf(filePointer,"\n-----------------------------------------------------------------------------------------\n");
fprintf(filePointer,"| SCORECARD |\n");
fprintf(filePointer,"| Congratulations!! |\n");
fprintf(filePointer,"| %-40s |\n",name);
fprintf(filePointer,"| Report:- |\n");
fprintf(filePointer,"| Unit Attempted Score(Max:10) |\n");
fprintf(filePointer,"|1. Unit-
%d %2d |\n",unit_selected[1],marks[unit_selected[1]]);
fprintf(filePointer,"|2. Unit-
%d %2d |\n",unit_selected[2],marks[unit_selected[2]]);
fprintf(filePointer,"|3. Unit-
%d %2d |\n",unit_selected[3],marks[unit_selected[3]]);
fprintf(filePointer,"|Your final Score is: %6.2f |\n",total);
fprintf(filePointer,"|Your final GRADE is: %-6.2c |\n",grade);
fprintf(filePointer,"|Thank you for Attempting our quiz |\n");
fprintf(filePointer,"-----------------------------------------------------------------------------------------");
fclose(filePointer);
system("notepad Scorecard.txt");
}
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");

}
else
{
printf("\n-------------------------------------------------------------------------------------------------------
-------\n");
printf("\nIt appears that you have left without finishing your attempt. Please notify to us the reason for
this\n");
printf("\n-------------------------------------------------------------------------------------------------------------
-\n");

}
}
The scorecard consists of Name individual score and final score along with grade, the score is
stored in a notepad file which shows itself, If the file forming has failed the score is displayed
there itself. If the player leaves the quiz without finishing all attempts his screen displays a
message why he quit.
5) Observations.
5.1) Title Screen
This is the title screen we get, you just have to enter your name here.

5.2) Main menu


This is main menu that we get you can see the options given, these can be selected, Selecting
these in a correct order allows the continuation of the quiz or else we get a message as shown
below

This is the main menu when all the quiz is completed, here you can see your current status at the
bottom, It shows the units selected and the amount of attempts finished.
5.3) Instructions screen
This is an simple example of how the instruction screen works, there are three such pages

5.4 )Units Entering screen


This is an example of the screen you get when you enter the units, Here it shows an invalid
message when proper units are not entered

This is the screen we get when the units are entered properly
5.5) The Quiz screen

Above is an example of how the quiz appears while being conducted, you get a timer of a sort
which tells you how much time is left, and all the three cases has been displayed here, in the
first question the answer is correct, when the answer is wrong as in the case of the second
question the correct answer is displayed in the case of the third question where we were too
slow it doesn’t take in any answer. In the same way the player can attempt 3 quizzes of 10
questions each.

5.6 Checking the marks


You get a screen like this when you are asked to checking the mark, you just have to type the
unit you want to see and you get the marks scored in it, The final score can also be seen after
finishing all three attempts
This the warning we get when the unit entered is Invalid

The final score is displayed as follows

5.7) Seeing the review


The screen from review is similar to that of the marks checking. When improper unit is selected
a warning is shown while in the case of the correct one the reiview is shown like this. The user
can see the ten questions reivew and then go to the main menu.
5.8) Correcting the marks
When you want to change the marks you need to have a password without which you can’t
change the marks, both cases of correct and incorrect marks entering has been showed below

After the correct marks has been entered you can change the marks as shown below the same
rules are followed as in the previous

5.9) The scorecard


After finishing all kind of reviews/corrections the user can quit the quiz in which he gets a
scorecard as shown below

It consists of Name Individual score for each unit and the final score along with final grade.
If the quiz is ended prematurely, we get a screen like this

6)References
Information used: https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/
https://www.includehelp.com/c-programming-questions
https://www.studytonight.com/c/structures-in-c.php
https://www.javatpoint.com/c-switch
https://www.javatpoint.com/c-goto
https://www.programiz.com/c-programming/c-for-loop
https://www.programiz.com/c-programming/c-if-else-statement
https://www.programiz.com/c-programming/c-do-while-loops
https://linuxhint.com/rand-function-in-c-language/
https://www.cplusplus.com/reference/cstdlib/srand/
https://www.geeksforgeeks.org/time-h-header-file-in-c-with-examples/

Questions used in quiz: https://www.examtray.com/subject/c-language-mcq-questions-and-


answers-topics
http://deptcs.ssbnc.in/files/resources/C%20Questions.pdf

You might also like