This project is a data structures-based system for managing participants, teams, and countries in a simulated Olympics competition. The system supports efficient operations for adding, removing, and managing entities while ensuring optimal performance.
- Country Management:
- Add or remove countries with unique IDs and medal counts.
- Team Management:
- Add or remove teams associated with specific countries and sports.
- Merge teams within the same sport and country.
- Contestant Management:
- Add or remove contestants with unique IDs, strength, and sports.
- Assign contestants to teams with appropriate validations.
- Competitions:
- Simulate matches between teams and update results dynamically.
- Retrieve team or contestant strengths.
- Optimization:
- Calculate maximum team strength after reducing the number of contestants.
- Error handling for invalid inputs and allocation issues.
- Custom memory-efficient data structures.
- Complexity guarantees for all operations.
main24a1.cpp: Entry point of the program. Processes input commands and initializes the system.olympics24a1.h/olympics24a1.cpp: Contains core data structures and logic for country, team, and contestant management.wet1util.h: Utility functions for error handling and standardized output.
- Test Files:
input.txt: Sample input commands for testing the system.output.txt: Expected output for verification.
- Clone the repository:
git clone <repository_url> cd project_directory
- Compile the program:
g++ -std=c++11 -o olympics -Wall -pedantic-errors -Werror -DNDEBUG *.cpp
- Run the executable:
./olympics
- Use interactive commands to manage the system, or redirect an input file:
./olympics < input.txt
add_country <country_id> <medal_count>Example:
add_country 1 5Adds a country with ID 1 and 5 medals.
add_team <team_id> <country_id> <sport>Example:
add_team 10 1 BOULDERINGAdds a team with ID 10 for country 1 in the sport of bouldering.
add_contestant <contestant_id> <country_id> <sport> <strength>Example:
add_contestant 100 1 BOULDERING 50Adds contestant 100 to country 1 in the sport of bouldering with a strength of 50.
play_match <team_id_1> <team_id_2>Example:
play_match 10 20Simulates a match between teams 10 and 20.
- Create a test input file (e.g.,
input.txt):add_country 1 5 add_team 10 1 BOULDERING add_contestant 100 1 BOULDERING 50 add_contestant_to_team 10 100 play_match 10 20 - Execute the program with the test file:
./olympics < input.txt > output.txt
- Compare
output.txtwith the expected results.
Run the program with valgrind to detect memory leaks:
valgrind --leak-check=full ./olympics- Invalid Inputs:
- Outputs an error message and continues operation.
- Deck Errors:
- Handles file not found, invalid format, or invalid size errors.
Deck File Error: File not foundDeck File Error: File format error in line <lineNumber>Deck File Error: Deck size is invalid
- Modular Design:
- Each operation is handled independently for better extensibility.
- Memory Management:
- Ensure no memory leaks by using smart pointers and proper cleanup.
- Error Handling:
- Handle edge cases and invalid operations gracefully.
This Olympics Management System demonstrates efficient use of custom data structures to handle complex operations in a scalable and optimized way. It is designed with clean coding practices, making it robust and extensible for future enhancements.