This repository contains a semester-long collection of C++ programming projects completed for an introductory programming course. The projects show my progression from basic console-based programs to larger object-oriented applications involving games, encryption algorithms, file input, simulation logic, and simple AI decision-making.
The purpose of this repository is to document the programming concepts I learned throughout the semester and demonstrate how I applied them through projects of increasing complexity.
| Project | Topic | Main Focus |
|---|---|---|
| Project 1 | Focaccia Calculator | Basic C++ syntax, arithmetic, input/output |
| Project 2 | Rock-Paper-Scissors | Functions, conditionals, loops, user input validation |
| Project 3 | Classical Ciphers | String processing, modular programming, encryption/decryption |
| Project 4 | Battleship Game | Object-oriented programming, file input, game logic |
| Final Project | Elevator Simulation | Multi-class simulation, AI decision-making, system design |
- C++
- Standard C++ libraries
- Console-based user interaction
- Text file input/output
- Header and source file organization
- Object-oriented programming
- Xcode project files
Project 1 is a console-based C++ program that calculates the ingredients needed to make focaccia bread for a given number of people. The user enters the number of people to serve, and the program calculates the required number of loaves, bags of flour, packages of yeast, canisters of salt, bottles of olive oil, and total estimated cost.
This project introduced the basic structure of a C++ program and focused on turning a real-world calculation problem into a working program.
The program follows a simple calculation workflow:
- Ask the user how many people need to be served.
- Calculate the number of focaccia loaves required.
- Calculate the amount of each ingredient based on the number of loaves.
- Use rounding logic so the shopping list uses whole packages.
- Calculate the total expected cost.
- Print a formatted shopping list.
The project also uses a helper function to handle singular and plural words in the output, such as 1 bag versus 2 bags.
The final program produces a complete shopping list and estimated ingredient cost based on user input. It demonstrates how programming can be used to automate a practical calculation task.
Example output:
How many people do you need to serve? 10
You need to make: 3 loaves of focaccia
Shopping List for Focaccia Bread
--------------------------------
1 bag of flour
3 packages of yeast
1 canister of salt
1 bottle of olive oil
Total expected cost of ingredients: $10.77
Have a great party!
- Basic C++ syntax
- Variables and constants
- Arithmetic operations
- Console input/output
- Rounding calculations
- Helper functions
- Output formatting
Project 2 is a two-player Rock-Paper-Scissors game written in C++. The program asks both players for their names, displays a menu, accepts player moves, validates input, determines the winner of each round, and announces the overall winner after multiple rounds.
This project focused on breaking a program into smaller functions and using conditional logic to manage game rules.
The program is divided into several functions, with each function handling a specific responsibility:
- Get player names.
- Display the game menu.
- Validate menu choices.
- Ask each player for a move.
- Check whether each move is valid.
- Compare two moves to determine the round winner.
- Track scores across rounds.
- Announce the final winner.
The game uses standard Rock-Paper-Scissors rules:
- Rock beats scissors.
- Scissors beats paper.
- Paper beats rock.
- Matching moves result in a draw.
The project also includes a menu option for Rock-Paper-Scissors-Lizard-Spock, but that mode is left as an under-construction feature.
The final program runs a complete text-based Rock-Paper-Scissors game through the terminal. It handles invalid input, tracks player performance, and prints the final result after the game ends.
Example output:
----------------------------------------
EECS 183
Rock-Paper-Scissors
----------------------------------------
Player 1, enter your name: Alice
Player 2, enter your name: Bob
Menu Options
------------
1) Play rock, paper, scissors
2) Play rock, paper, scissors, lizard, spock
3) Quit
Choice --> 1
Alice, enter your move: R
Bob, enter your move: S
Alice wins the round!
- Functions
- Parameters and return values
- Loops
- Conditional statements
- Input validation
- Character handling
- Game logic
- Score tracking
Project 3 is an encryption and decryption program that supports multiple classical ciphers, including Caesar cipher, Vigenere cipher, and Polybius square cipher. The user chooses a cipher type, selects encryption or decryption mode, enters a message, provides a key, and receives the converted result.
This project introduced more advanced string processing and modular programming. Each cipher is separated into its own source and header files, making the program easier to organize, test, and maintain.
The program supports three cipher methods.
The Caesar cipher shifts alphabetic characters by a fixed integer key.
Method:
- Read the original message.
- Read an integer key.
- Shift each alphabetic character forward for encryption or backward for decryption.
- Preserve non-alphabetic characters.
- Return the converted message.
The Vigenere cipher uses a keyword instead of a single numeric shift. Each letter in the keyword determines a different shift value.
Method:
- Read the message.
- Read the keyword.
- Convert keyword letters into shift values.
- Repeat the keyword across the message.
- Apply different shifts to alphabetic characters.
- Preserve spacing and non-letter characters where appropriate.
The Polybius cipher uses a grid-based substitution method. A keyword is used to generate a mixed character grid, and characters are converted into coordinate pairs.
Method:
- Read the message.
- Validate allowed characters.
- Read the keyword.
- Convert the keyword to uppercase.
- Remove duplicate characters from the keyword.
- Build a mixed Polybius grid.
- Convert characters to coordinate pairs for encryption.
- Convert coordinate pairs back to characters for decryption.
The final program works as an interactive command-line encryption and decryption tool. It allows the user to select the cipher method and transformation mode, then outputs the encrypted or decrypted message.
Example output:
Choose a cipher: Caesar
Encrypt or decrypt: Encrypt
Enter a message: Hello World
What is your key: 3
The encrypted message is: Khoor Zruog
- String manipulation
- Character processing
- Modular programming
- Header files and source files
- User input validation
- Encryption and decryption logic
- 2D arrays
- Function testing
Project 4 is a console-based Battleship game implemented using object-oriented programming. The user plays against a CPU opponent. The game supports loading ship grids from text files or generating grids randomly, and the user can select different CPU behavior modes.
This project was a major step from function-based programming to class-based program design. It required multiple interacting classes to represent positions, ships, players, and the overall game.
The project is organized around several major classes.
The Position class represents a coordinate on the Battleship grid. It stores row and column information and supports coordinate-based operations.
The Ship class represents an individual ship. It stores the ship’s placement, orientation, and hit status. It helps determine whether a ship has been hit or sunk.
The Player class stores a player’s grid, ships, guesses, and game-related actions. It manages board state and player attacks.
The Game class controls the overall game flow. It manages both the human player and CPU player, processes turns, checks hits and misses, and determines when the game ends.
The game setup process includes:
- Ask the user for their name.
- Create a human player and CPU player.
- Ask whether to load grids from text files.
- Create the game board.
- Select CPU mode.
- Start the game loop.
- Continue until one side wins.
The final program runs a complete Battleship game in the terminal. It demonstrates object-oriented design through multiple classes working together to represent a larger game system.
Example output:
Enter your name: Zehuan
Read your grid from file grid1.txt? (y or n): y
Read CPU grid from file grid2.txt? (y or n): n
Starting game with EASY AI
- Object-oriented programming
- Classes and objects
- Constructors
- Encapsulation
- Header/source file separation
- File input
- Grid-based logic
- Game state management
- Player vs. CPU interaction
- Testing and debugging
The final project is a building elevator simulation written in C++. The program models a building with multiple floors, elevators, and people waiting for service. The goal is to control elevator movement and pickups in a way that improves the satisfaction index and reduces passenger anger.
This was the most complex project in the course. It combined object-oriented programming, simulation logic, file-based scenarios, and AI decision-making.
The simulation is built using multiple classes that represent the main components of the system.
The Building class represents the full simulation environment. It manages the state of floors, elevators, people, and the progression of the game.
The Elevator class represents an individual elevator. It stores information such as the current floor, target floor, and whether the elevator is currently servicing a request.
The Floor class represents one floor in the building. It stores the people waiting on that floor and provides methods to access or update floor-level information.
The Person class represents an individual passenger. Each person has a current floor, target floor, and anger level. The anger level is important because it affects the satisfaction score.
The Move class represents an action taken by the player or AI. A move may send an elevator to a floor or pick up a group of people.
The SatisfactionIndex class tracks the performance of the elevator system. Better decisions improve the score, while poor service decisions can increase passenger anger and reduce satisfaction.
The final project includes AI decision logic to choose elevator actions based on the current building state.
The strategy follows these ideas:
- Check whether an elevator is idle.
- If an idle elevator is already on a floor with waiting people, pick them up.
- Otherwise, search for the floor with the highest total anger level.
- Avoid sending multiple elevators to the same target floor.
- Select the available elevator closest to the selected floor.
- During pickup, compare upward-going and downward-going passengers.
- Pick the group with higher total anger first.
This strategy focuses on reducing the highest-risk waiting groups and improving the satisfaction index.
The final project produced a working elevator simulation with an AI strategy for choosing elevator movements and passenger pickup groups. The AI prioritizes floors with higher total anger and selects nearby available elevators, which helps reduce passenger frustration and improve the simulation score.
The project also includes multiple input scenario files, allowing the simulation to be tested under different passenger patterns and difficulty levels.
- Large-scale object-oriented programming
- Multi-class system design
- Simulation modeling
- File input scenarios
- State-based programming
- Basic AI decision-making
- Performance evaluation
- Debugging a larger codebase
- Separating interface and implementation
Clone the repository:
git clone https://github.com/zehuanyu/EECS183Projects.git
cd EECS183Projectscd project-1
g++ focaccia.cpp -o focaccia
./focacciacd "project 2/project 2"
g++ rps.cpp start.cpp -o rps
./rpscd project3
g++ *.cpp -o ciphers
./cipherscd project4
g++ *.cpp -o battleship
./battleshipcd "final project"
g++ *.cpp -o elevator_simulation
./elevator_simulationNote: Some folders may include starter files, test files, or course-provided files. If a compile command causes a duplicate main() error, compile only the main driver file and the required implementation files.
Through these projects, I practiced and developed:
- C++ programming fundamentals
- Console-based program design
- User input and output handling
- Arithmetic and formatted output
- Functions and decomposition
- Loops and conditionals
- String and character processing
- File input and output
- Header/source file organization
- Object-oriented programming
- Class-based design
- Game logic
- Simulation logic
- Basic AI decision-making
- Testing and debugging
These projects show my progression through one semester of introductory C++ programming. I started with a simple calculator-style program and gradually moved into more complex applications involving games, encryption tools, object-oriented design, and simulation.
The biggest improvement across the semester was learning how to break a large problem into smaller components. In the earlier projects, most logic was handled through functions. In the later projects, the code became more structured through classes such as Player, Ship, Game, Elevator, Floor, and Person.
By the final project, I was able to work with a larger codebase, understand interactions between multiple classes, and implement simple AI logic based on the current state of the simulation.
Recommended repository name:
Intro-to-Programming-Cpp-Projects
This name is clear and professional because it explains the project content directly, even for people who are not familiar with the course number.
Zehuan Yu