Skip to content

NE-PREP-2024-2025/dsa_ne_2025

Repository files navigation

City Road Management System (National Examination)

Overview

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.

Features

  • 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 to roads.txt.
  • Input Validation: Ensures valid inputs for indices, budgets, and city names.
  • Bidirectional Roads: Treats roads like Musanze-Kigali and Kigali-Musanze as identical.

Prerequisites

  • 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 and roads.txt.

Installation

  1. Download:

    • download main.cpp and CMakeLists.txt.
    cd dsa
  2. Generate Build Files:

    • Ensure CMake 3.20+ is installed (cmake --version).
    • Run:
      cmake .
  3. Build the Executable:

    cmake --build .
    • The executable main (or main.exe on Windows) is created in build/bin/.

Usage

  1. Run the Program:

    ./main  # Linux/macOS
    main  # Windows
  2. 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:
      
  3. 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
      

File Structure

  • 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
    

Notes

  • 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 .

Acknowledgments

  • Built with C++20 and CMake for robust city and road management.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published