0% found this document useful (0 votes)
17 views11 pages

FDS Report

Mini Game Report in C++

Uploaded by

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

FDS Report

Mini Game Report in C++

Uploaded by

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

D.Y.

PATIL COLLEGE OF ENGINEERING, AKURDI, PUNE -


411035

Fundamentals of Data Structures Seminar Report

Group Members

Roll Number Name


SEAIDC03 Amaan Khan
SEAIDC19 Snehil Somanjay
SEAIDC20 Pranjal Sharma

Subject : Data Structures Report

Branch : Artificial Intelligence and Data Science

Year : 2024 - 2025

Student. Teacher. HOD.


INDEX

Content Page
Aim 3

Theory 3-5

Objectives 5

Algorithm 5-6

Codet 7-9

Output and Conclusion 10-11


Arithmetic Puzzle Game – Project Report

Aim:

The purpose of this project is to develop an interactive


arithmetic puzzle game using C++. This game aims to challenge
users by presenting equations with missing values that they must
solve. It provides a learning experience for practicing arithmetic
operations while also demonstrating good coding practices. The
puzzle employs input validation and dynamic updates of a grid
in real-time, keeping the player engaged until the puzzle is
solved correctly.

This project not only serves as a basic programming exercise but


also demonstrates modular programming concepts such as
encapsulation through functions, input handling, and
two-dimensional (2D) arrays to create a visual structure.

Theory:

This arithmetic puzzle game makes use of several core


programming concepts:
1. Object-Oriented Programming (OOP):
The project uses functions to group related logic together,
demonstrating modularity and encapsulation. Each function
serves a specific purpose—whether printing the grid, validating
input, or updating the grid state dynamically.

2. 2D Arrays (Vectors):
The puzzle grid is represented as a 2D vector of strings, which
allows it to store both arithmetic symbols and unknown
variables. This structure makes it easy to access and manipulate
the elements based on player input.

3. Input Handling and Validation:


The game asks the player to solve for several unknown
variables (like `a`, `b`, `c`, `d`). It ensures that only the correct
values are accepted, encouraging the user to try again if the
input is invalid.

4. Dynamic Grid Updates:


After each correct input, the grid is updated to reflect the
player’s progress. This dynamic feedback creates a more
engaging experience, giving players a visual sense of
accomplishment.

5. Console-based User Interface:


The use of `|` and `-` symbols makes the grid look structured
and readable, enhancing user interaction through a simple,
text-based interface.

This project emphasizes clear and readable code, the use of


loops, conditional statements, and arrays, which are essential
building blocks for any beginner-level programming project.

Objectives:

1. Develop a console-based arithmetic puzzle game in C++.


2. Use 2D vectors to create and manage the puzzle grid.
3. Implement OOP concepts through modular functions.
4. Ensure correct input handling and validation for user inputs.
5. Create a user-friendly interface using text-based grid layout
with dividers.
6. Display dynamic updates to the puzzle grid as the user solves
it step-by-step.
7. Provide feedback after every input to guide the player toward
solving the puzzle.

Algorithm:

1. Initialize the Grid:


- The grid is represented as a 2D vector with arithmetic
equations containing variables (`a`, `b`, `c`, `d`) that need to be
solved.

2. Display the Initial Grid:


- Use a function to print the grid with dividers (`|` and `-`
symbols) to enhance readability.

3. Game Loop:
- For each variable (`a`, `b`, `c`, `d`):
1. Ask the player to enter the value for the variable.
2. Validate the input:
- If the value is incorrect, prompt the user to try again.
- If the value is correct, update the grid with the new value
and display it.
3. Continue asking until the player provides the correct value.

4. Update the Grid:


- Replace the variable with the correct value in the grid once it
is validated.

5. End of Game:
- After all variables are solved, display a congratulatory
message and exit the game.
Code:

include <iostream>
include <vector>
include <string>
using namespace std;

// Function to print the current grid state with dividers


void printGrid(const vector<vector<string>>& grid) {
cout << "-----------------" << endl;
for (const auto& row : grid) {
cout << "|";
for (const auto& cell : row) {
cout << " " << cell << " |";
}
cout << endl << "-----------------" << endl;
}
}

// Function to validate input values for the puzzle


bool validateInput(char var, int value) {
switch (var) {
case 'a': return value == 3;
case 'b': return value == 5;
case 'c': return value == 7;
case 'd': return value == 2;
default: return false;
}
}

// Function to update the grid with the correct input


void updateGrid(vector<vector<string>>& grid, char var, int
value) {
for (auto& row : grid) {
for (auto& cell : row) {
if (cell == string(1, var)) {
cell = to_string(value);
}
}
}
}

int main() {
// Initialize the grid with arithmetic operations and variables
vector<vector<string>> grid = {
{"2", "+", "a", "=", "5"},
{"b", "-", "3", "=", "2"},
{"4", "+", "c", "=", "11"},
{"d", "+", "6", "=", "8"}
};

// Variables to be solved sequentially


char variables[] = {'a', 'b', 'c', 'd'};
// Display the initial grid
cout << "Welcome to the Arithmetic Puzzle!" << endl;
printGrid(grid);

// Loop through each variable, ask for input, and validate


for (char var : variables) {
int value;
do {
cout << "Enter the value for " << var << ": ";
cin >> value;
if (!validateInput(var, value)) {
cout << "Invalid input! Try again." << endl;
} else {
cout << var << " = " << value << " is correct!" <<
endl;
updateGrid(grid, var, value); // Update the grid
printGrid(grid); // Print the updated grid
}
} while (!validateInput(var, value)); // Keep asking until
correct
}

cout << "Congratulations! You solved the puzzle!" << endl;


return 0;
}
Output:

Welcome to the Arithmetic Puzzle!


-----------------
|2|+|a|=|5|
-----------------
|b|-|3|=|2|
-----------------
| 4 | + | c | = | 11 |
-----------------
|d|+|6|=|8|
-----------------
Enter the value for a: 4
Invalid input! Try again.
Enter the value for a: 3
a = 3 is correct!
-----------------
|2|+|3|=|5|
-----------------
|b|-|3|=|2|
-----------------
| 4 | + | c | = | 11 |
-----------------
|d|+|6|=|8|
-----------------
Enter the value for b: 5
b = 5 is correct!
-----------------
|2|+|3|=|5|
-----------------
|5|-|3|=|2|
-----------------
| 4 | + | c | = | 11 |
-----------------
|d|+|6|=|8|
-----------------
...
Congratulations! You solved the puzzle!

Conclusion:

This project successfully demonstrates core C++ programming


principles through an interactive arithmetic puzzle game. The
use of 2D vectors to represent the puzzle grid ensures scalability
and simplicity. Modular functions improve code organization,
making the program easy to maintain. The dynamic grid updates
provide immediate feedback, enhancing the user experience.
This project serves as an effective way to apply input handling,
loops, and conditionals in a real-world scenario, making it a
valuable learning tool for beginners.

You might also like