The City Road Management System is a C++ application for managing cities and their connecting roads, including associated budgets, using adjacency matrices. It provides a console-based interface to add cities, create bidirectional roads (e.g., Kigali-Musanze is the same as Musanze-Kigali), assign budgets, edit city names, search cities, and display data. Data is stored persistently in cities.txt
and roads.txt
.
- Add Cities: Add multiple cities with unique indices and names.
- Add Roads: Create bidirectional roads between cities (e.g., Kigali-Musanze).
- Assign Budgets: Set budgets for roads in billions (e.g., 28.6 billion for Kigali-Musanze).
- Edit Cities: Update city names, automatically updating road names in files and matrices.
- Search Cities: Find cities by index or name.
- Display Data: View cities, road adjacency matrix, and budget adjacency matrix.
- Persistent Storage: Save cities to
cities.txt
and roads/budgets toroads.txt
. - Input Validation: Ensures valid inputs for indices, budgets, and city names.
- Bidirectional Roads: Treats roads like Musanze-Kigali and Kigali-Musanze as identical.
- C++ Compiler: C++20-compliant (e.g., GCC 10+, Clang 10+, MSVC 2019 16.8+).
- CMake: Version 3.20 or higher.
- Operating System: Linux, macOS, or Windows.
- File Permissions: Write access in the executable’s directory for
cities.txt
androads.txt
.
-
Download:
- download
main.cpp
andCMakeLists.txt
.
cd dsa
- download
-
Generate Build Files:
- Ensure CMake 3.20+ is installed (
cmake --version
). - Run:
cmake .
- Ensure CMake 3.20+ is installed (
-
Build the Executable:
cmake --build .
- The executable
main
(ormain.exe
on Windows) is created inbuild/bin/
.
- The executable
-
Run the Program:
./main # Linux/macOS main # Windows
-
Menu Navigation:
- Select options 1–9 from the menu:
Menu: 1. Add Cities 2. Add road between cities 3. Add budget for cities 4. Edit city 5. Search for city using its index or name 6. Display cities 7. Display roads 8. Display recorded data on console 9. Exit Enter your choice:
- Select options 1–9 from the menu:
-
Example Interactions:
- Add a City:
Enter the number of Cities to add: 1 Enter the name for city 1: Gisenyi Cities added successfully
- Add a Road:
Enter the name of first city: Kigali Enter the name of second city: Musanze Road added between Kigali and Musanze
- Note: Musanze-Kigali is same Kigali-Musanze.
- Add a Budget:
Enter the name of first city: Musanze Enter the name of second city: Kigali Enter the budget for the road: 28.6 Budget of 28.6 added for road between Musanze and Kigali
- Edit a City:
Enter index of the city to edit: 1 Enter the new name for the city: Kigari City updated successfully
- Display All Data (Sample Output):
Cities: 1: Kigali 2: Huye 3: Muhanga 4: Musanze 5: Nyagatare 6: Rubavu 7: Rusizi Roads Adjacency Matrix: 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 Budgets Adjacency Matrix: 0.00 28.60 0.00 28.60 70.84 0.00 0.00 28.60 0.00 56.70 0.00 0.00 0.00 80.96 0.00 56.70 0.00 66.30 0.00 0.00 117.50 28.60 0.00 66.30 0.00 96.14 33.70 0.00 70.84 0.00 0.00 96.14 0.00 0.00 0.00 0.00 0.00 0.00 33.70 0.00 0.00 0.00 0.00 80.96 117.50 0.00 0.00 0.00 0.00
- Add a City:
- Generated Files:
cities.txt
: Stores city indices and names (e.g.,1 Kigali
).roads.txt
: Stores road indices, names (canonical order), and budgets (e.g.,1 Kigali-Musanze 28.6
).
- Project Files:
CityRoadManager/ ├── main.cpp # Main program source code ├── CMakeLists.txt # CMake build configuration ├── README.md # This file ├── build/ # Build directory (created during build) # Executable output directory │ ├── dsa ├── cities.txt # Created/updated during execution ├── roads.txt # Created/updated during execution
- Bidirectional Roads: Roads are stored in alphabetical order (e.g., Kigali-Musanze) to ensure Musanze-Kigali and Kigali-Musanze are treated as the same road.
- C++20: Built with C++20 for modern features, using CMake 3.20+.
- Error Handling: Validates inputs and prevents duplicate roads or invalid operations.
- Portability: Runs on Linux, macOS, and Windows with a C++20-compliant compiler.
- Debugging: Build with debug symbols:
cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build .
- Built with C++20 and CMake for robust city and road management.