parking charge system project c++

Sure! Here is an example of a parking charge system project in C++, along with explanations for each step:

Step 1: Include necessary header files

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

Explanation: In this step, we include the necessary header files that provide functionality for input/output operations (iostream), manipulators for formatting output (iomanip), and time-related functions (ctime).

Step 2: Define constants and variables

const double HOURLY_RATE = 2.5;
const int MAX_HOURS = 24;

int main()
{
    int entryHour, entryMinute, exitHour, exitMinute;
    double totalCharge;
    time_t now = time(0);
    tm* localTime = localtime(&now);

Explanation: Here, we define two constants: HOURLY_RATE represents the parking charge per hour, and MAX_HOURS represents the maximum number of hours a car can be parked. We also declare variables to store the entry and exit time, total charge, and a time_t variable to get the current time.

Step 3: Get user input for entry and exit time

    cout << "Enter the entry time (hour minute): ";
    cin >> entryHour >> entryMinute;

    cout << "Enter the exit time (hour minute): ";
    cin >> exitHour >> exitMinute;

Explanation: In this step, we prompt the user to enter the entry and exit time in hours and minutes, and store the values in the respective variables (entryHour, entryMinute, exitHour, exitMinute) using the cin object.

Step 4: Calculate the total parking charge

    int parkingHours = exitHour - entryHour;
    int parkingMinutes = exitMinute - entryMinute;

    if (parkingMinutes < 0) {
        parkingHours--;
        parkingMinutes += 60;
    }

    if (parkingHours < 0) {
        parkingHours += 24;
    }

    totalCharge = parkingHours * HOURLY_RATE;

Explanation: Here, we calculate the total parking duration by subtracting the entry time from the exit time. We handle cases where the exit minutes are less than the entry minutes or the exit hours are less than the entry hours. The total charge is then calculated by multiplying the parking hours by the hourly rate.

Step 5: Display the parking details and total charge

    cout << "--- Parking Details ---" << endl;
    cout << "Entry Time: " << entryHour << ":" << setw(2) << setfill('0') << entryMinute << endl;
    cout << "Exit Time: " << exitHour << ":" << setw(2) << setfill('0') << exitMinute << endl;
    cout << "Parking Duration: " << parkingHours << " hours and " << parkingMinutes << " minutes" << endl;
    cout << "Total Charge: $" << fixed << setprecision(2) << totalCharge << endl;

    return 0;
}

Explanation: Finally, we display the parking details including the entry and exit time, parking duration, and the total charge. The setw(2) and setfill('0') manipulators are used to ensure the minutes are displayed with leading zeros. The fixed and setprecision(2) manipulators are used to display the total charge with two decimal places.

This is a simple example of a parking charge system project in C++. Feel free to modify and enhance it according to your requirements.