Property Management System in C++
property management system in C++
Code :
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Property structure
struct Property {
string address;
string city;
string state;
int zip;
string tenantName;
};
// Function to add property
void addProperty(vector<Property>& properties) {
Property newProperty;
cout << "Enter property address: ";
cin.ignore();
getline(cin, newProperty.address);
cout << "Enter property city: ";
getline(cin, newProperty.city);
cout << "Enter property state: ";
getline(cin, newProperty.state);
cout << "Enter property zip: ";
cin >> newProperty.zip;
newProperty.tenantName = "Vacant";
properties.push_back(newProperty);
cout << "Property added successfully!" << endl;
}
// Function to remove property
void removeProperty(vector<Property>& properties) {
string address;
cout << "Enter property address to remove: ";
cin.ignore();
getline(cin, address);
for (int i = 0; i < properties.size(); i++) {
if (properties[i].address == address) {
properties.erase(properties.begin() + i);
cout << "Property removed successfully!" << endl;
return;
}
}
cout << "Property not found!" << endl;
}
// Function to view properties
void viewProperties(const vector<Property>& properties) {
if (properties.empty()) {
cout << "No properties available!" << endl;
return;
}
cout << "Properties:" << endl;
for (const auto& property : properties) {
cout << "Address: " << property.address << endl;
cout << "City: " << property.city << endl;
cout << "State: " << property.state << endl;
cout << "Zip: " << property.zip << endl;
cout << "Tenant Name: " << property.tenantName << endl;
cout << endl;
}
}
// Function to add tenant
void addTenant(vector<Property>& properties) {
string address;
string tenantName;
cout << "Enter property address to add tenant: ";
cin.ignore();
getline(cin, address);
for (auto& property : properties) {
if (property.address == address) {
cout << "Enter tenant name: ";
getline(cin, tenantName);
property.tenantName = tenantName;
cout << "Tenant added successfully!" << endl;
return;
}
}
cout << "Property not found!" << endl;
}
int main() {
vector<Property> properties;
int choice;
do {
cout << "Property Management System" << endl;
cout << "1. Add Property" << endl;
cout << "2. Remove Property" << endl;
cout << "3. View Properties" << endl;
cout << "4. Add Tenant" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addProperty(properties);
break;
case 2:
removeProperty(properties);
break;
case 3:
viewProperties(properties);
break;
case 4:
addTenant(properties);
break;
case 5:
cout << "Exiting the system. Goodbye!" << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 5);
return 0;
}
***************
This program uses a vector of "Property" structures to store the properties. It provides options to add, remove, and view properties, as well as add tenants to properties. The program uses a simple text-based menu for user interaction.


Comments
Post a Comment