write c++ code: The manager of a real estate company asked you to write a progra
ID: 3772314 • Letter: W
Question
write c++ code:
The manager of a real estate company asked you to write a program that computerizes the tasks commonly performed in his daily work. These tasks consist of maintaining the list of properties available for sale, and allowing staff at his company to query the system about available properties. The company deals with 3 types of properties land property, villas, and apartments. Available property information depends on the type of the property:
The land property information consists of the property id, the location (town name), the size (in sq. m) and its price.
Villa information consists of the property id, the location (town name), the land area (in sq. m), the built area (in sq. m), the number of rooms, the number of levels and its price.
Apartment information consists of the property id, the location (town name), the area of the apartment (in sq. m), the number of rooms, the level where the apartment is located, and its price.
When started, your program should read properties information from a file called properties.txt and save them in a linked list of properties. When terminated, your program should save back into properties.txt the updated property information. While running, your program should keep displaying the following menu and execute user’s requests until the user decides to quit.
The menu:
1. Add property acquired by the company to the list of available properties.
2. Remove a property ( that has been sold)
3. List all properties
4. List all properties in a specified town
5. List all properties with price <= specified amount
Functions to be used: Besides, your program should include at least the following functions:
• readProperties(…): This function is called when the program starts. It reads from a file called properties.txt information of available properties and stores them in a linked-list called properties. Finally, it returns the number of available properties (>=0) or -1 if it could not open the file properties.txt.
• displayProperties (…):This function is called when the user chooses to display information about the available properties (menu options: 2, 3 and 4). It first asks the user to enter complementary information if needed (town name for option 3 and maximum price for option 4) and performs the display. You may call other functions from displayProperties() if needed.
• addProperty(…): This function reads from the user information about a new property and inserts it into the linked list.
• deletPrperty(…): This function reads from the user the id of the property to remove and deletes it from the linked list if found or displays “ property id Not found” message otherwise
• saveProperties(…): This function saves the updated linked list into the file properties.txt. It is called when the user chooses the quit option.
• deleteProperties(…): that frees all the memory allocated for the linked list; it is called when the user chooses the quit option.
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
struct Villa
{
string id;
string location;
double totalArea;
double builtArea;
int rooms;
int levels;
double price;
struct Villa *next;
}*V;
struct Land
{
string id;
string location;
double size;
double price;
struct Land*next;
}*L;
struct Apartment
{
string id;
string location;
double Area;
int rooms;
int levels;
double price;
struct Apartment * next;
}*A;
int main()
{
ifstream infile("properties.txt");
if(!infile)
{
cout<<endl<<"properties.txt not found";
exit(0);
}
V=null;
A=null;
L=null;
int n1=0;
int n2=0;
int n3=0;
while(!infile.eof())
{
string id;
infile>>id;
if(id.substr(0,1)=="V")
{
struct Villa * temp=new struct Villa;
infile>>temp->location;
infile>>temp->totalArea;
infile>>temp->builtArea;
infile>>temp->rooms;
infile>>temp->levels;
infile>>temp->price;
insert(temp,V); // calling linked list insert
}
else if(id.substr(0,1)=="L")
{
struct Land * temp=new struct Land;
infile>>temp->location;
infile>>temp->size;
infile>>temp->price;
insert(temp,L); // calling linked list insert
}
else if(id.substr(0,1)=="A")
{
struct Apartement * temp=new struct Apartement;
infile>>temp->location;
infile>>temp->area;
infile>>temp->rooms;
infile>>temp->levels;
infile>>temp->price;
insert(temp,A); // calling linked list insert
}
}
cout<<endl<<n<<" properties were read successfully from properties.txt";
int option=0;
while(option<7)
{
cout<<endl<<"Properties Management System";
cout<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<endl<<"Please choose the task you like to perform";
cout<<endl<<"1 ---------------->Add a property";
cout<<endl<<"2 ---------------->Remove a property";
cout<<endl<<"3 ---------------->List all properties";
cout<<endl<<"4 ---------------->list properties in specified town";
cout<<endl<<"5 ---------------->list properties with price >= specified amount";
cout<<endl<<"6 ---------------->Quit the program";
cout<<endl<<"Your selection: ";
cin>>choice;
switch(choice)
{
case 1: cout<<endl<<"Please enter property id:";
string id;
cin>>id;
if(id.substr(0,1)=="V")
{
struct Villa * temp=new struct Villa;
cout<<endl<<"Location <town>:";
cin>>temp->location;
cout<<endl<<"Property total area:";
cin>>temp->totalArea;
cout<<endl<<"Property built area:";
cin>>temp->builtArea;
cout<<endl<<"Number of rooms:";
cin>>temp->rooms;
cout<<endl<<"Number of levels:";
cin>>temp->levels;
cout<<endl<<"Property price:";
cin>>temp->price;
insert(temp,V); // calling linked list insert
}
else if(id.substr(0,1)=="L")
{
struct Land * temp=new struct Land;
cout<<endl<<"Location <town>:";
cin>>temp->location;
cout<<endl<<"size (in sq. m):";
cin>>temp->size;
cout<<endl<<"Price:";
cin>>temp->price;
insert(temp,L); // calling linked list insert
}
else if(id.substr(0,1)=="A")
{
struct Apartement * temp=new struct Apartement;
insert(temp,A); // calling linked list insert
cout<<endl<<"Location <town>:";
cin>>temp->location;
cout<<endl<<"area of the apartment (in sq. m):";
cin>>temp->area;
cout<<endl<<"number of rooms:";
cin>>temp->rooms;
cout<<endl<<"the level where the apartment is located";
cin>>temp->levels;
cout<<endl<<"price:";
cin>>temp->price;
}
break;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6: break;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.