C++ Program for Parking Charges of Two-Wheelers, Four-Wheelers and Heavy Vehicles (दोपहिया, चार पहिया और भारी वाहनों का पार्किंग शुल्क ज्ञात करने का C++ प्रोग्राम)

A parking management system is used to calculate parking charges according to the type of vehicle and the total parking duration. In this C++ program, we use a class named Parking to calculate the parking charges for three types of vehicles:

  1. Two-Wheelers – Bike or Scooter

  2. Four-Wheelers – Car or Loading Vehicle

  3. Heavy Vehicles – Bus or Truck

The program accepts the vehicle type, vehicle number, entry time, exit time and parking days. It then calculates the total parking duration and displays the parking receipt.

पार्किंग प्रबंधन प्रणाली का उपयोग वाहन के प्रकार और पार्किंग की कुल अवधि के आधार पर शुल्क ज्ञात करने के लिए किया जाता है। इस C++ प्रोग्राम में Parking नाम की Class बनाई गई है, जो तीन प्रकार के वाहनों का पार्किंग शुल्क ज्ञात करती है।

Parking Charges (पार्किंग शुल्क)

Vehicle TypeVehicle CategoryFirst 24 HoursAdditional Hours
1Bike / Scooter₹10 per hour₹1 per hour
2Car / Loading Vehicle₹20 per hour₹5 per hour
3Bus / Truck₹50 per hour₹10 per hour

C++ Program

#include <iostream>
using namespace std;
float minfee = 5;
int penalty1 = 1, penalty2 = 5, penalty3 = 10;
class Parking
{
int vtype;
char vno[20];
float days, charges, entrytime, exittime, hours;
void chargecount();
public:
void getreceipt();
void setreceipt();
};
void Parking::setreceipt()
{
cout << "Enter Vehicle Type (1-Two Wheeler, 2-Four Wheeler, 3-Heavy Vehicle): ";
cin >> vtype;
cout << "Enter Vehicle Number: ";
cin >> vno;
cout << "Enter Entry Time (24-hour format): ";
cin >> entrytime;
cout << "Enter Exit Time (24-hour format): ";
cin >> exittime;
cout << "Enter Parking Days: ";
cin >> days;
chargecount();
}
void Parking::chargecount()
{
if (exittime >= entrytime)
hours = exittime - entrytime;
else
hours = exittime + (24 - entrytime);
if (days >= 1)
hours = hours + days * 24;
switch (vtype)
{
case 1:
if (hours < 24)
charges = hours * 10;
else
charges = 24 * 10 + (hours - 24) * penalty1;
break;
case 2:
if (hours < 24)
charges = hours * 20;
else
charges = 24 * 20 + (hours - 24) * penalty2;
break;
case 3:
if (hours < 24)
charges = hours * 50;
else
charges = 24 * 50 + (hours - 24) * penalty3;
break;
default:
charges = 0;
cout << "Invalid Vehicle Type!" << endl;
}
}
void Parking::getreceipt()
{
cout << "\n========== PARKING RECEIPT ==========" << endl;
cout << "Vehicle Type = ";
if (vtype == 1)
cout << "Bike or Scooter" << endl;
else if (vtype == 2)
cout << "Car or Loading Vehicle" << endl;
else if (vtype == 3)
cout << "Bus or Truck" << endl;
else
cout << "Invalid Vehicle Type" << endl;
cout << "Vehicle Number = " << vno << endl;
cout << "Total Parking Hours = " << hours << endl;
cout << "Total Charge = Rs. " << charges << endl;
cout << "=====================================" << endl;
}
int main()
{
Parking p;
p.setreceipt();
p.getreceipt();
return 0;
}

Sample Output (उदाहरण आउटपुट)

Enter Vehicle Type (1-Two Wheeler, 2-Four Wheeler, 3-Heavy Vehicle): 1
Enter Vehicle Number: MP46AB1234
Enter Entry Time (24-hour format): 10
Enter Exit Time (24-hour format): 14
Enter Parking Days: 0
========== PARKING RECEIPT ==========
Vehicle Type = Bike or Scooter
Vehicle Number = MP46AB1234
Total Parking Hours = 4
Total Charge = Rs. 40
=====================================

Explanation of the Program (प्रोग्राम की व्याख्या)

1. Class Declaration

The Parking class contains data members such as vtype, vno, entrytime, exittime, days, hours and charges. It also contains two public member functions and one private member function.

Parking Class में वाहन का प्रकार, वाहन नंबर, प्रवेश समय, बाहर जाने का समय, पार्किंग के दिन, कुल घंटे और शुल्क संग्रहित करने के लिए Data Members बनाए गए हैं।

2. setreceipt() Function

This function accepts the vehicle type, vehicle number, entry time, exit time and number of parking days from the user. After accepting the details, it calls the chargecount() function.

यह Function उपयोगकर्ता से वाहन का प्रकार, वाहन नंबर, प्रवेश समय, बाहर जाने का समय तथा पार्किंग के दिनों की संख्या प्राप्त करता है।

3. chargecount() Function

This function calculates the total parking hours. If the exit time is earlier than the entry time, it assumes that the vehicle leaves on the next day and calculates the duration accordingly.

यह Function कुल पार्किंग समय की गणना करता है। यदि बाहर जाने का समय प्रवेश समय से कम है, तो प्रोग्राम मानता है कि वाहन अगले दिन बाहर गया है।

The switch statement selects the parking rate according to the vehicle type. The first 24 hours and additional hours are charged at different rates.

switch Statement वाहन के प्रकार के अनुसार पार्किंग शुल्क निर्धारित करता है। पहले 24 घंटों और उसके बाद के अतिरिक्त घंटों के लिए अलग-अलग दरें लागू होती हैं।

4. getreceipt() Function

This function displays the vehicle category, vehicle number, total parking hours and calculated parking charges.

यह Function वाहन का प्रकार, वाहन नंबर, कुल पार्किंग घंटे और कुल पार्किंग शुल्क प्रदर्शित करता है।

5. main() Function

The main() function creates an object p of the Parking class. It calls setreceipt() to accept the details and getreceipt() to display the receipt.

main() Function में Parking Class का p नामक Object बनाया जाता है। इसके माध्यम से वाहन की जानकारी प्राप्त की जाती है और पार्किंग रसीद प्रदर्शित की जाती है।

Important C++ Concepts Used

  • Class and Object

  • Data Members and Member Functions

  • Access Specifiers (private and public)

  • Encapsulation

  • switch Statement

  • Conditional Statements (if-else)

  • Function Definition Outside the Class

  • Object Creation and Function Calling

This program demonstrates the use of Object-Oriented Programming concepts in C++. It uses a class and its member functions to calculate parking charges for different categories of vehicles.

यह प्रोग्राम C++ में Object-Oriented Programming की अवधारणाओं को समझाता है। इसमें Class और Member Functions की सहायता से अलग-अलग प्रकार के वाहनों का पार्किंग शुल्क ज्ञात किया जाता है।

Note: This is an educational example based on the supplied program's charging rules. The variable minfee is retained from the original declaration but is not used in the calculation. The original program also assumes valid 24-hour time inputs and does not validate them. The parking-day calculation follows the original program's logic, so it should be refined before using this as a real parking billing system.

Comments

Popular posts from this blog

Important Questions (IMP) of Programming Methodologies and Data structures using C++ with OOP's Concepts

Complete C++ Programming Syllabus - From Basics to Advanced C++ , including OOP and Data Structures and Algorithms

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)