0% found this document useful (0 votes)
8 views7 pages

C++ OOP Quiz Game Documentation

Uploaded by

akapegbe1
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)
8 views7 pages

C++ OOP Quiz Game Documentation

Uploaded by

akapegbe1
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

C++ Quiz Game - OOP Documentation

Overview

This project implements a modular, object-oriented Quiz Game in C++. It uses core OOP
principles—abstraction, encapsulation, inheritance, and polymorphism—to create a flexible and
maintainable quiz system. The game supports multiple quiz categories, including Science,
History, and Pop Culture, and features both Multiple Choice and True/False question types.

OOP Principles Applied

1. Abstraction
• Abstract Question base class defines a general interface for quiz questions.
• Clients interact with quiz questions through this interface without needing to know
the underlying implementation.

2. Encapsulation
• All class attributes are marked private or protected, accessed through public
methods.
• Keeps internal data safe and exposes only necessary operations.

3. Inheritance
• MultipleChoiceQuestion and
TrueFalseQuestion classes inherit from the Question base class.
• Allows shared logic to reside in the base class while enabling specialized
behavior in derived classes.

4. Polymorphism
• Virtual methods displayQuestion() and checkAnswer() allow dynamic behavior at
runtime.
• The Quiz class can store and manage different question types uniformly using
Question*.

Class Structure

class Question (Abstract Base

questionText :Text of the points Score value for the question


category: Subject category of the question
displayQuestion(). Pure virtual method for displaying the question
checkAnswer() Pure virtual method to check correctness
getPoints() Returns points assigned to the question
getCategory() Returns question category

class MultipleChoiceQuestion : public


Question

Additional Member :Description


optionsList of possible answer choices
correctAnswer The correct answer (as string index or value)
displayQuestion() Displays question with options
checkAnswer(userInput) Returns true if user input matches correctAnswer

class TrueFalseQuestion : public Question

correctAnswer Boolean value (true or false)


displayQuestion() Displays question with True/False options
checkAnswer(userInput) Evaluates if user’s choice matches correctAnswer

class Quiz

Member: Description
quizName: Title of the quiz
timeLimit: Total time allowed in seconds
questions: List of Question* objects
addQuestion() Adds a question to the quiz
shuffleQuestions() Randomizes order of questions
runQuiz() Displays and manages entire quiz session
getTotalPoints() Returns the total possible score for the quiz

Game Flow Summary

1. Display Main Menu: User chooses a quiz category.


2. Quiz Initialization: Questions are added based on selected topic.
3. Shuffle & Run: Questions are randomized and the quiz timer starts.
4. Question Loop:
• Each question is displayed.
• User inputs their answer.
• Correctness is checked and score is updated.
• Remaining time and current score are shown.
5. End of Quiz: Final score and percentage are displayed.

Features

• Multiple quiz categories


• Timer-based quiz duration
• Automatic input validation
• Randomized question order
• Tracks and displays score progress

Potential Enhancements

Feature: OOP Impact


getCorrectAnswer() method: Adds extensibility to base class
Replay / High score system: Introduce new User or ScoreBoard classes
Question Difficulty Levels: Subclass Question further or add attribute
Question Bank Loader (from file): Demonstrates encapsulation + file I/O
Per-question timer: More granular time control in Quiz

Conclusion

This C++ Quiz Game showcases solid object-oriented design with emphasis on reusability,
extensibility, and maintainability. It serves as a robust foundation for more complex quiz
systems, educational tools, or interactive games.

Would you like this formatted as a PDF, markdown file, or header-style documentation for
inclusion in source code?

Class diagram (UML)


Flowchart diagram

README representation
Features

• Multiple quiz categories (Science, History, Pop Culture

• Supports Multiple Choice and True/False questions

• Time-limited quizzes (each quiz has its own time limit)


• Points-based scoring system

• Randomized question order in each quiz

• User input validation and error handling

• Console-based menu for quiz selection and game navigation

Classes

Question (Abstract Base Class)

• Holds common properties for a question: text, points, and category.

• Pure virtual methods to display the question and check the user’s answer.

MultipleChoiceQuestion (Derived Class)

• Extends Question

• Stores multiple options and the correct answer.

• Implements display and answer checking specific to multiple-choice.

TrueFalseQuestion (Derived Class)

• Extends Question

• Stores the correct boolean answer.

• Implements display and answer checking specific to true/false format.

Quiz

• Manages a collection of Question objects.

• Handles quiz timing, question shuffling, user interaction, scoring, and displaying
results.

How to Run

1. Compile the code with a C++ compiler (supports C++11 and later):
g++ -std=c++11 -o quiz_game quiz_game.cpp

2. Run the executable:

./quiz_game

3. Select a quiz category from the menu by entering the corresponding number.

4. Answer the questions within the time limit.

5. View your final score and percentage.

6. After the quiz ends, press Enter to return to the main menu or exit.

Code Structure

• main() contains the main menu loop and quiz selection logic.

• Quiz creation functions (createScienceQuiz(), etc.) build quizzes with predefined


questions.

• Each question is dynamically allocated and managed within the Quiz class.

• The Quiz::runQuiz() function runs the quiz loop, checks time limit, and scores
answers.

Dependencies

• Standard C++ libraries only (<iostream>, <vector>, <string>, <ctime>,


<algorithm>, <limits>, <thread>, <chrono>).

Future Enhancements

• Add support for more question types (e.g., fill-in-the-blank).

• Load questions from external files or databases.

• Add a graphical user interface.

• Track player statistics across multiple sessions.

• Provide detailed feedback showing correct answers after each question.

Author

Your Name / Your GitHub (optional)

If you’d like, I can also help generate a shorter version or include instructions for specific
platforms!

Common questions

Powered by AI

The modular design facilitates future enhancements by clearly separating responsibilities and using an abstract base class to define common behaviors. This allows developers to extend functionality, such as introducing new question types or integrating new features like a scoring system or graphical interface, without impacting existing components. The encapsulation of data and functions within classes supports easy integration and testing of new modules .

Features contributing to the system's reusability and extensibility include its modularity, use of a general interface via an abstract base class, and separation of concerns through encapsulation. The system supports various question types and categories and easily integrates enhancements such as the getCorrectAnswer() method for extensibility or a Question Bank Loader demonstrating encapsulation and file I/O for added functionality .

Implementing a Question Bank Loader could significantly enhance the system by adding the ability to dynamically load questions from external files. This demonstrates encapsulation and file I/O, which promotes greater flexibility and ease in updating or expanding the quiz questions without hardcoding them into the software. It allows for better management of questions and could support scalability and customization of quiz content .

The strategic planning of using a strong object-oriented framework, modular components, and extensible design allows the quiz game to serve as a foundation for educational tools and interactive games. By supporting flexible question management, scalable design patterns, and ease of integration with additional functionalities, this system provides a robust architecture adaptable to various educational domains and interactive applications .

Introducing a per-question timer may pose challenges like ensuring accurate timing across different system loads and managing user experience when they are pressured by time constraints. This could be addressed by using a multithreaded approach to manage timers separately from the main game loop and providing visual cues or warnings for time management. Proper input validation and testing across platforms would also ensure consistent functionality .

The current scoring and feedback mechanism provides immediate feedback on correctness and updates scores, keeping users engaged by showing progress. However, the lack of detailed feedback on incorrect answers might limit learning opportunities. Providing more detailed feedback, such as showing correct answers after each question, could enhance learning outcomes by allowing users to understand their mistakes and improve .

The Quiz class supports dynamic interaction by managing a collection of Question objects through pointers, allowing it to handle different question types uniformly. By utilizing polymorphism with virtual methods, the Quiz class can dynamically call methods like displayQuestion() and checkAnswer() on different derived classes without needing to know their specific types, facilitating seamless management and interaction during a quiz session .

Polymorphism plays a crucial role in achieving uniformity by allowing the Quiz class to interact with objects of derived classes through pointers or references to the base Question class. This design enables invoking derived-specific implementations of virtual methods like displayQuestion() and checkAnswer() without knowing the derived class type. Consequently, it simplifies the management of various question formats, enhancing code flexibility and maintainability .

The C++ Quiz Game applies OOP principles by using abstraction to define a general interface for quiz questions through an abstract Question base class. Encapsulation is employed, with class attributes marked as private or protected and accessed through public methods, ensuring that internal data is protected while exposing necessary operations. Inheritance is used where MultipleChoiceQuestion and TrueFalseQuestion classes derive from the Question base class, allowing shared logic and enabling specialized behavior. Polymorphism is implemented through virtual methods like displayQuestion() and checkAnswer() that allow runtime dynamic behavior, facilitating uniform management of different question types in the Quiz class .

The system ensures robustness by implementing automatic input validation and error handling mechanisms. This design checks user input to ensure it matches expected formats, prevents invalid actions, and appropriately handles errors to maintain the quiz flow without crashes. This approach helps maintain a seamless and error-free user experience, crucial for effective gameplay and learning .

You might also like