House Rental Listing System in C++
Introduction
This project simulates a rental listing system where users can list houses or portions for rent. It allows users to add new properties, display available listings, and search for rentals based on location and rent criteria.
Main Features
1. Adding a Property
- Users can list houses or portions available for rent.
- Each listing includes details like owner name, type, location, rent amount, and availability.
2. Viewing All Listings
- Displays all currently available rental properties.
3. Searching for Rentals
- Users can filter listings based on:
C++ Implementation
Code: Rental Listing System
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Structure to store details of a property
struct Property {
string type; // "House" or "Portion"
string owner;
string location;
int rent;
bool isAvailable;
// Display function
void display() const {
cout << "--------------------\n";
cout << "Owner: " << owner << "\n";
cout << "Type: " << type << "\n";
cout << "Location: " << location << "\n";
cout << "Rent: $" << rent << "\n";
cout << "Availability: " << (isAvailable ? "Available" : "Rented") << "\n";
}
};
// Function to add a property
void addProperty(vector<Property>& listings) {
Property newProperty;
cout << "Enter owner name: ";
cin.ignore();
getline(cin, newProperty.owner);
cout << "Enter type (House/Portion): ";
getline(cin, newProperty.type);
cout << "Enter location: ";
getline(cin, newProperty.location);
cout << "Enter rent amount: ";
cin >> newProperty.rent;
newProperty.isAvailable = true;
listings.push_back(newProperty);
cout << "Property added successfully!\n";
}
// Function to display all available properties
void displayProperties(const vector<Property>& listings) {
if (listings.empty()) {
cout << "No properties available.\n";
return;
}
cout << "\nAvailable Properties:\n";
for (const auto& property : listings) {
if (property.isAvailable) {
property.display();
}
}
}
// Function to search for properties based on criteria
void searchProperties(const vector<Property>& listings) {
string location;
int maxRent;
cout << "Enter location to search: ";
cin.ignore();
getline(cin, location);
cout << "Enter maximum rent: ";
cin >> maxRent;
cout << "\nSearch Results:\n";
bool found = false;
for (const auto& property : listings) {
if (property.isAvailable && property.location == location && property.rent <= maxRent) {
property.display();
found = true;
}
}
if (!found) {
cout << "No matching properties found.\n";
}
}
// Main function: House Rental Management System
int main() {
vector<Property> listings;
int choice;
do {
cout << "\nHouse Rental Management System\n";
cout << "1. Add Property\n";
cout << "2. View Available Properties\n";
cout << "3. Search Property\n";
cout << "4. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1:
addProperty(listings);
break;
case 2:
displayProperties(listings);
break;
case 3:
searchProperties(listings);
break;
case 4:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice! Try again.\n";
}
} while (choice != 4);
return 0;
}
Explanation of Code
-
Property Structure:
- Defines attributes like
type
, owner
, location
, rent
, and isAvailable
.
- Includes a
display()
function to show property details.
-
addProperty() Function:
- Takes input from the user and stores it in a
vector<Property>
.
-
displayProperties() Function:
- Displays all available properties in the system.
-
searchProperties() Function:
- Allows users to filter rentals by location and maximum rent.
-
Main Menu Loop:
- Provides an interactive menu for the user to manage the rental system.
Future Enhancements
- Implement a feature for owners to mark a property as rented.
- Add a login system to differentiate owners and renters.
- Introduce a graphical interface (GUI) using Qt for better user experience.
- Integrate a database (MySQL) for storing rental listings permanently.
This C++ rental listing system provides a basic yet functional model for property rentals. It can be further expanded to create a full-fledged property management system.
Comments
Post a Comment