[go: up one dir, main page]

0% found this document useful (0 votes)
15 views27 pages

Grammar Quiz Game

The document describes a project to develop a grammar quiz game program. It includes objectives like creating a database of questions, implementing randomization of questions, evaluating and scoring user answers, and ensuring maintainable code. System requirements for running the program like hardware specifications and software dependencies are also outlined. Flow diagrams and pseudocode are provided to explain the program's algorithms and logic.

Uploaded by

glenswaber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views27 pages

Grammar Quiz Game

The document describes a project to develop a grammar quiz game program. It includes objectives like creating a database of questions, implementing randomization of questions, evaluating and scoring user answers, and ensuring maintainable code. System requirements for running the program like hardware specifications and software dependencies are also outlined. Flow diagrams and pseudocode are provided to explain the program's algorithms and logic.

Uploaded by

glenswaber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

GRAMMAR QUIZ GAME

In Partial Fulfillment of the Subject

In CT 215 PROGRAMMING

2nd Semester, A.Y. 2022-2023

Submitted by:

GLEN BOY RELLON

JUN AL ESPAÑOL

Submitted to:

MAAM CATHERINE PAYUSAN ODIONG

June 3,2023
Project Description:

The purpose of this project is to develop a quiz game program (Grammar quiz)
that allows users to test their knowledge on a specific topic. The scope of the project
includes designing and implementing a user-friendly interface, creating a database of
questions and answers, and implementing the logic for presenting questions, accepting
user responses, and providing feedback on the correctness of the answers.

The objectives of the project are as follows:

1. User Interaction: Develop an intuitive and user-friendly interface that allows users to
navigate through the quiz, submit their answers, and receive feedback on their
performance.

2. Question Database: Create a structured database containing a wide range of


questions related to the chosen topic. The questions should cover various difficulty
levels and ensure that they are relevant and accurate.

3. Randomization: Implement a mechanism to randomize the selection of questions for


each quiz session. This ensures that users are presented with a different set of
questions every time they take the quiz, enhancing the user experience and preventing
predictability.

4. Answer Evaluation: Develop the logic to evaluate user responses and provide
immediate feedback on the correctness of the answers. The program should accurately
assess whether the provided answer matches the expected answer and display the
appropriate result to the user.

5. Scoring and Progress Tracking: Implement a scoring system that assigns points for
correct answers and keeps track of the user's progress throughout the quiz. Display the
final score at the end of the quiz, allowing users to gauge their performance and
improve their knowledge.

6. Code Maintainability: Ensure that the code is well-structured, modular, and adheres
to good programming practices. Utilize functions to enhance code readability and
maintainability, making it easier to debug, modify, and extend the program in the future.

By achieving these objectives, the project aims to provide an engaging and educational
quiz experience for users, allowing them to test their knowledge, learn new information,
and track their progress over time.
System requirements:

Hardware Requirements:

1. Processor: Intel Core i3 or equivalent (or higher recommended)

2. Memory (RAM): 4 GB (8 GB or more recommended)

3. Storage: At least 100 MB of free disk space

4. Display: Minimum screen resolution of 1280x720 pixels

Software Requirements:

1. Operating System: Windows 7 or later, macOS, or Linux

2. C++ Compiler: You will need a C++ compiler to compile and run the code. Popular
options include GCC (GNU Compiler Collection), Clang, and Microsoft Visual C++
Compiler.

3. Integrated Development Environment (IDE): While not mandatory, using an IDE can
provide a more convenient development environment. Examples of C++ IDEs include
Visual Studio, Code::Blocks, and Eclipse CDT.

4. Standard Template Library (STL): The C++ code may rely on the Standard Template
Library (STL) for various data structures and algorithms. The STL is typically included
with the C++ compiler.
Flow diagrams:
Algorithms:

1. Start the program.


2. Define the `welcomeMessage` function to display the welcome message and
instructions for the quiz.
3. Declare and initialize arrays for easy, medium, and hard quiz questions,
choices, and correct answers.
4. Define an enum `Difficulty` with values EASY, MEDIUM, and HARD.
5. Declare variables `level` of type `Difficulty` and `levelChoice` of type `char`.
6. Display a prompt to select the difficulty level and read the user's choice.
7. Use a while loop to validate the user's input and assign the appropriate
difficulty level based on the choice.
8. If the input is invalid, display an error message and continue to prompt for a
valid choice.
9. Break out of the loop when a valid choice is made.
10. Declare variables `questions`, `choices`, `correctAnswers`, and
`numQuestions` of appropriate types.
11. Use a switch statement based on the selected difficulty level to assign the
corresponding arrays and number of questions to the variables declared in the
previous step.
12. Declare variables `score` and `exitQuiz` and initialize them to 0 and false,
respectively.
13. Start a for loop to iterate through each question.
14. Display the current current question and choices.
15. Read the user's answer or option to exit.
16. If the user chooses to exit, set `exitQuiz` to true and break out of the loop.
17. Convert the user's answer to lowercase.
18. Compare the user's answerwihcorrc aswer.
19. If the answer is correct, increment the `score` and display a "Correct!"
message.
20. If the answer is incorrect, display an "Incorrect!" message and show the
correct answer.
21. Display an empty line for spacing.
22. After the loop, check if `exitQuiz` is false.
23. If `exitQuiz` is fse, dispayiz complnmessghe final score.
24. If `exitQuiz` is true, display a message indicating that the quiz was exited and
the progress was not recorded.
25. End the program.
Source code:

#include <iostream>

#include <string>

using namespace std;

void welcomeMessage() {

cout << "Welcome to the Grammar Quiz Game!" << endl;

cout << "Test your grammar knowledge by answering a series of questions." << endl;

cout << "Each question has multiple choices, and you need to enter the
corresponding letter (a, b, or c) for your answer." << endl;

cout << "Let's get started!" << endl;

cout << endl;

int main() {

welcomeMessage();

// Quiz questions and answers

string easyQuestions[] = {

"1. Which of the following is a verb?",

"2. Choose the correct form of the verb: He ___ to school every day.",

"3. Select the pronoun that best completes the sentence: ___ like to eat pizza.",

"4. Identify the preposition in the sentence: The book is ___ the table.",

"5. Choose the correct plural form of 'box':",


"6. Which of the following is an adjective?",

"7. Select the correct word order for a basic English sentence:",

"8. Identify the adverb in the sentence: She ran quickly to catch the bus.",

"9. Choose the correct form of the verb: They ___ playing soccer in the park.",

"10. Select the conjunction in the sentence: I like both ice cream ___ cake."

};

string easyChoices[] = {

"a) Run\nb) Tree\nc) Dog\n",

"a) Walks\nb) Walking\nc) Walk\n",

"a) I\nb) You\nc) They\n",

"a) on\nb) in\nc) at\n",

"a) boxs\nb) boxies\nc) boxes\n",

"a) Red\nb) Jumped\nc) Beautiful\n",

"a) Subject - Verb\nb) Verb - Subject\nc) Subject - Adjective\n",

"a) ran\nb) quickly\nc) to\n",

"a) plays\nb) play\nc) playing\n",

"a) and\nb) but\nc) or\n"

};

string easyCorrectAnswers[] = {

"a",

"c",
"c",

"b",

"c",

"a",

"a",

"b",

"c",

"a"

};

string mediumQuestions[] = {

"1. Choose the correct form of the verb: She ___ to the party last night.",

"2. Identify the direct object in the sentence: They bought ___ new car.",

"3. Select the correct comparative form of the adjective 'big':",

"4. Identify the pronoun in the sentence: ___ will be there in a moment.",

"5. Choose the correct form of the verb: He ___ his bike to work every day.",

"6. Select the correct word order for a question in English:",

"7. Identify the adverbial phrase in the sentence: She sings with joy.",

"8. Choose the correct form of the possessive pronoun: That book is ___",

"9. Identify the conjunction in the sentence: I like to swim and play tennis.",

"10. Choose the correct form of the verb: They ___ their vacation in Europe."

};
string mediumChoices[] = {

"a) went\nb) goes\nc) go\n",

"a) a\nb) an\nc) the\n",

"a) bigger\nb) biggers\nc) biggest\n",

"a) He\nb) We\nc) They\n",

"a) rides\nb) ride\nc) riding\n",

"a) Verb - Subject\nb) Subject - Verb\nc)",

"a) Adjective - Verb - Subject\nb) Subject - Verb - Adjective\nc)"

" Verb - Adjective - Subject\n",

"a) with joy\nb) sings\nc) she\n",

"a) mine\nb) my\nc) me\n",

"a) and\nb) or\nc) but\n",

"a) spent\nb) spend\nc) spends\n",

};

string mediumCorrectAnswers[] = {

"a",

"c",

"c",

"b",

"a",

"b",

"a",
"b",

"a",

"c"

};

string hardQuestions[] = {

"1. Choose the correct form of the verb: She ___ already ___ her homework before
dinner.",

"2. Identify the gerund in the sentence: Swimming is my favorite sport.",

"3. Select the correct form of the adjective: This is the ___ book I have ever read.",

"4. Identify the relative pronoun in the sentence: The person ___ won the
competition will get a prize.",

"5. Choose the correct form of the verb: They ___ studying for hours when I
arrived.",

"6. Select the correct word order for a passive sentence in English:",

"7. Identify the infinitive phrase in the sentence: He wants to learn how to play the
guitar.",

"8. Choose the correct form of the pronoun: The gift is for ___",

"9. Identify the participial phrase in the sentence: The dog, wagging its tail, greeted
me at the door.",

"10. Choose the correct form of the verb: She ___ her best to win the competition."

};

string hardChoices[] = {
"a) has, done\nb) have, did\nc) had, do\n",

"a) Swimming\nb) is\nc) sport\n",

"a) most interesting\nb) interestingest\nc) interested\n",

"a) who\nb) whom\nc) which\n",

"a) were\nb) have been\nc) had been\n",

"a) Object - Verb - Subject\nb) Verb - Subject - Object\nc) Subject - Verb - Object\
n",

"a) to learn how to play the guitar\nb) wants to learn how\nc) how to play the guitar\
n",

"a) me\nb) myself\nc) mine\n",

"a) wagging its tail\nb) The dog\nc) greeted me at the door\n",

"a) is trying\nb) trying\nc) tried\n"

};

string hardCorrectAnswers[] = {

"c",

"a",

"a",

"a",

"b",

"b",

"a",

"a",
"a",

"b"

};

// Difficulty levels

enum Difficulty {

EASY,

MEDIUM,

HARD

};

// Prompt for difficulty level

Difficulty level;

char levelChoice;

while (true) {

cout << "Select difficulty level:" << endl;

cout << "E - Easy" << endl;

cout << "M - Medium" << endl;

cout << "H - Hard" << endl;

cout << "Enter your choice: ";

cin >> levelChoice;


switch (levelChoice) {

case 'E':

case 'e':

level = EASY;

break;

case 'M':

case 'm':

level = MEDIUM;

break;

case 'H':

case 'h':

level = HARD;

break;

default:

cout << "Invalid choice. PLEASE TRY ENTER VALID CHOICE" << endl;

continue;

break;

// Select the appropriate set of questions based on the difficulty level

string *questions;

string *choices;

string *correctAnswers;
int numQuestions;

switch (level) {

case EASY:

questions = easyQuestions;

choices = easyChoices;

correctAnswers = easyCorrectAnswers;

numQuestions = sizeof(easyQuestions) / sizeof(easyQuestions[0]);

break;

case MEDIUM:

questions = mediumQuestions;

choices = mediumChoices;

correctAnswers = mediumCorrectAnswers;

numQuestions = sizeof(mediumQuestions) / sizeof(mediumQuestions[0]);

break;

case HARD:

questions = hardQuestions;

choices = hardChoices;

correctAnswers = hardCorrectAnswers;

numQuestions = sizeof(hardQuestions) / sizeof(hardQuestions[0]);

break;

}
// Quiz loop

int score = 0;

bool exitQuiz = false; // Added variable to track if user wants to exit

for (int i = 0; i < numQuestions; i++) {

cout << questions[i] << endl;

cout << choices[i] << endl;

string userAnswer;

cout << "Enter your answer (a, b, or c), or 'q' to exit: ";

cin >> userAnswer;

// Convert user's answer to lowercase

userAnswer = tolower(userAnswer[0]);

if (userAnswer == "q") {

exitQuiz = true; // User wants to exit

break; // Exit the quiz loop

if (userAnswer == correctAnswers[i]) {

cout << "Correct!" << endl;

score++;
} else {

cout << "Incorrect!" << endl;

cout << "The correct answer is " << correctAnswers[i] << endl;

cout << endl;

// Display final score unless the user exited the quiz

if (!exitQuiz) {

cout << "Quiz complete!" << endl;

cout << "Your score: " << score << "/" << numQuestions << endl;

} else {

cout << "Quiz exited. Your progress will not be recorded." << endl;

return 0;

}
Testing:

Date Test cases Remarks


May 19,2023 Missing break statement  ERROR
after displaying the error  Issue: After displaying the
message for an invalid error message for an
choice. invalid choice, the code
continues to execute the
rest of the switch case
statements.
 Solution: Add a break
statement after displaying
the error message to exit
the switch case. Here’s
the corrected line:
cout << "Invalid choice.
PLEASE TRY ENTER VALID
CHOICE" << endl;
continue;

May 19,2023 Incorrect line  ERROR


continuation in  Issue: In
mediumChoices. mediumChoices, there is
a missing line
continuation ("") in the
second-to-last choice.
 Solution: Add a line
continuation ("") at the
end of the second-to-last
choice to continue the
string on the next line.
Here's the corrected line:

“a) Adjective – Verb – Subject\


nb) Subject – Verb – Adjective\
nc) “\
“Verb – Adjective – Subject\n”,

May 19,2023 Incorrect comparison of  ERROR


userAnswer with “q”.  Issue:userAnswer == "q"
is incorrect because
userAnswer is a string,
not a character.
 Solution: Change the
comparison to
userAnswer[0] == 'q' to
compare the first
character of userAnswer
with the character 'q'.
Here's the corrected line:
If (userAnswer[0] == ‘q’) {
May 20,2023 Missing the std::  ERROR
namespace qualifier for  Issue: The code is
cout, endl, and cin. missing the std::
namespace qualifier for
the cout, endl, and cin
objects, which are part of
the std namespace.
 Solution: Add the std::
namespace qualifier
before cout, endl, and cin
throughout the code.
Alternatively, you can add
using namespace std; at
the beginning of the code
to avoid using the std::
qualifier.
May 20,2023 Missing semicolon at the  ERROR
end of the switch case  Issue: The case EASY in
for EASY in the switch the switch statement is
statement. missing a semicolon at
the end.
 Solution: Add a
semicolon at the end of
the case EASY: line.
May 20,2023 Missing variable name  ERROR
for hardChoices in the  Issue: The variable name
hard question section. for hardChoices is
missing in the hard
question section.
 Solution: Add a variable
name before the equal
sign in the line =
hardChoices; in the hard
question section. For
example, choices =
hardChoices;.
May 23,2023 Missing the  ERROR
numQuestions variable  Issue: The numQuestions
initialization for the variable is not being
HARD case in the switch initialized for the HARD
statement. case in the switch
statement.
 Solution: Add the
numQuestions
initialization for the HARD
case similar to the other
cases. For example,
numQuestions =
sizeof(hardQuestions) /
sizeof(hardQuestions[0]);
.
May 23,2023 Invalid switch case label  ERROR
in the main while loop.  Issue: The level =
statement is missing the
case value after the colon
in the case 'H': label in
the main while loop.
 Solution: Provide a valid
case value after the colon
for the case 'H': label in
the main while loop.
May 23,2023 Incorrect function call in  ERROR
the final score display.  Issue: The final score
display is missing the
parentheses for the if
condition.
 Solution: Add
parentheses to the if
condition for the final
score display. For
example, if (!exitQuiz)
should be changed to if (!
exitQuiz) {.
May 25,2023 Missing break statement  ERROR
in the ‘H’ case of the  Issue: The HARD case in
switch statement. the switch statement is
missing a break
statement.
 Solution: Add a break
statement at the end of
the HARD case in the
switch statement.
May 25,2023 Missing semicolon at the  ERROR
end of the switch case  Solution: Add a
for EASY in the switch semicolon at the end of
statement. the case EASY: line.
May 25,2023 Missing variable name  ERROR
for hardChoices in the  Solution: Add a variable
hard question section. name before the equal
sign in the line =
hardChoices; in the hard
question section. For
example, choices =
hardChoices;.
May 25,2023 Missing the  ERROR
numQuestions variable  Solution: Add the
initialization for the numQuestions
HARD case in the switch initialization for the HARD
statement case similar to the other
cases. For example,
numQuestions =
sizeof(hardQuestions) /
sizeof(hardQuestions[0]);
.
May 25,2023 Missing semicolon  ERROR
 Issue:There is a missing
semicolon after the
declaration of the
mediumChoices array.
 Solution: Add a
semicolon at the end of
the line.
May 25,2023 Typo in variable name  ERROR
 Issue:There is a typo in
the variable name
mediumCorrectAnswers
in the
mediumCorrectAnswers
array declaration.
 Solution: Fix the typo in
the variable name.
May 25,2023 Missing comma  ERROR
 Issue:There is a missing
comma after the
declaration of the
Difficulty enum values.
 Solution: Add a comma
after each enum value.
May 25,2023 Variable assignment  ERROR
 Issue: In the switch
statement, the variable
que is assigned to
mediumQuestions
instead of questions.
 Solution: Change que to
questions.
May 25,2023 Typo in variable name  ERROR
 Issue:In the switch
statement for the HARD
case, there is a typo in
the variable name wers.
 Solution: Fix the typo in
the variable name.
May 25,2023 Missing semicolon  ERROR
 Issue:After the
numQuestions variable
assignment in the HARD
case, there is a missing
semicolon.
 Solution: Add a
semicolon at the end of
the line.
May 25,2023 Missing namespace  ERROR
qualification  Issue:In the main
function, the tolower
function call is missing
the std:: namespace
qualification.
 Solution: Add the std::
namespace qualification
to the tolower function
call.
May 25,2023 Incorrect condition check  ERROR
 Issue:In the quiz loop, the
condition check if
(userAnswer [i]) is
incorrect and should be if
(userAnswer ==
correctAnswers[i]) to
compare the user’s
answer with the correct
answer.
 Solution: Change the
condition check to
compare the user’s
answer.

Conclusion:
We conclude that the grammar quiz project was successfully implemented using
C++. The program allowed users to test their grammar knowledge by answering a
series of questions with multiple-choice options. The project aimed to provide an
interactive and educational experience for users to improve their grammar skills.
Throughout the development process, several challenges were encountered.

One of the challenges was designing the user interface to be intuitive and user-
friendly. This involved presenting the questions, choices, and feedback in a clear and
organized manner. Additionally, validating user input and handling different scenarios,
such as allowing users to quit the quiz, posed implementation challenges.

However, through careful planning and problem-solving of my partner, these


challenges were overcome. The project provided an opportunity to practice and
enhance programming skills, particularly in the areas of user input handling, array
manipulation, conditional statements, and manipulating errors. The project also
reinforced the importance of testing and debugging. By thoroughly testing the program
and identifying and fixing any issues or errors, the final implementation became more
robust and reliable.

In terms of future improvements, additional features could be added to enhance


the user experience, such as a timer for each question or a scoring system with different
levels of achievements. Furthermore, expanding the question bank and incorporating
different difficulty levels would provide more comprehensive grammar practice. The
grammar quiz project was a valuable learning experience, combining programming
skills with educational content. It demonstrated the effectiveness of using code to create
interactive and engaging learning tools.

You might also like