Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is to build a simplified version of MLS (Multiple Listing Service) Listings of properties on sales (console version). A property can be either

This program is to build a simplified version of MLS (Multiple Listing Service) Listings of properties on sales (console version). A property can be either a Single family house or a Townhouse. The program should allow users to:

View all listings

Search Townhouse by zip code

Search property by max price

concepts the assignment should cover:

Linked List implementation

Abstract classes with pure virtual functions

Polymorphism and dynamic_cast

Operator Overloading

Generic programming (extra credit only)

Sample run of your program:

MLSListings Menu

1. View all properties // polymorphism

2. Search Townhouse by zip code // dynamic_cast

3. Search properties by max price // operator overloading

4. Quit

Select an option (1-4): 1

// display all properties below

// ..............................................

MLSListings Menu

1. View all properties

2. Search Townhouse by zip code

3. Search properties by max price

4. Quit

Select an option (1-4): 2

Enter a zip code: 99999

Sorry no Townhouse listing found for zip code 99999! Please check it back at a later time.

MLSListings Menu

1. View all properties

2. Search Townhouse by zip code

3. Search properties by max price

4. Quit

Select an option (1-4): 2

Enter a zip code: 95112

// display all Townhouse with zip code 95112 below

// ..............................................

MLSListings Menu

1. View all properties

2. Search Townhouse by zip code

3. Search properties by max price

4. Quit

Select an option (1-4): 3

Enter max price: 1000000

// display all properties with offered prices <= 1000000

// ..............................................

MLSListings Menu

1. View all properties

2. Search Townhouse by zip code

3. Search properties by max price

4. Quit

Select an option (1-4): 4

Thanks for browsing our listings. See you again!

Class Design

MLSListings: this class contains the Linked List of Property objects (namely a PropertyList object) which is needed to perform the functionalities required by our MLSListings application such as list all properties currently for sales, search Townhouse based on zip code, search all properties based on max price.

PropertyList: a linked list whose nodes are Property objects which can be Single Family Houses or Townhouse

Property: the base class.

SingleFamilyHouse(SFH): derived class from Property.

Townhouse: derived class from Property.

Class Implementation

class Property (abstract class - the PropertyList will be a linked list of concrete Property objects (SFH or Townhouse)

Private member data: a pointer to a Property object called next - this is the link to the next node in a Linked List

Protetected member data: address, zip code, offeredPrice, year built

Constructors

Default constructor: setting the member data to default values (don't forget to init the "next" field)

Non-default constructor (take 4 parameters): initialize the member data based on the parameters' values (don't forget to init the "next" field)

Destructor: must be declared as virtual destructor (no-op)

Public member functions:

accessors and mutators for all member data including the next pointer

ShowPropertyInfo: a pure virtual function (no implementation is required) which will be defined later by its derived classes. It should return void, take no parameter and be declared as constant function

overload the operator <= to allow an expression of the form: property <= 988888.88 returns true or false based the property's offeredPrice

class SingleFamilyHouse (derived from Property)

Private member data: backyard area (double representing back yard's sqft)

Constructors

Default constructor (initialize backyard to 0.0, must explicitly invoke base class default constructor)

Non-default constructor (takes 5 parameters): You must know what to do here

Destructor: explicitly declared as virtual (no-op)

Public member functions:

accessor/mutator for backyard area

ShowPropertyInfo: must be explicitly declared it as virtual and nicely format the console output for the Property

class Townhouse (derived from Property)

Private member data: HOA (Home Owner Association)) monthly fee (of type double)

Constructor

Default constructor (initialize HOA fee to 100, must explicitly invoke base class default constructor)

Non-default constructor (takes 5 parameters): You must know what to do here

Destructor: explicitly declared as virtual (no-op)

Public member fnctions:

accessor/mutator for HOA monthly fee

ShowPropertyInfo: must be explicitly declared it as virtual and nicely format the console output for the Property.

class PropertyList

Private memeber data: a pointer to a Property object (head). Note: you can have a pointer to an abstract object but you can't instantiate an abstract object

Constructor

Default constructor: initialize head to NULL (or nullptr)

Destructor: since all of the linked list's nodes are dynamically allocated the destructor must traverse the entire linked list to free memory for all nodes to avoid memory leak.

Public instance methods:

Init: to manually (hard-coded) build the list. See Code Helper section at the end of the specs.

Insert (take a pointer to a Property object): to add a Property object (Single Family House or Townhouse) to the front of the linked list.Note: the pointer parameter must be pointing to a dynamically allocated SFH or Townhouse object prior to the Insert function's invocation.

ViewAllProperties: traverse thru the entire linked list to invoke ShowPropertyInfo function for each node.

SearchTownhouseByZipcode: takes a zip code integer as its only parameter. The function will traverse thru the entire linked list to show address, zip code, offered price and HOA fee (you must invoke accessors or getters) for only nodes that are: 1> Townhouse (use dynamic_cast to determine if a node is Townhouse object) 2> The Townhouse's zip code matches the zip code parameter

SearchByMaxPrice: takes a price of type double as its only parameter. The function will traverse thru the entire linked list to invoke ShowPropertyInfo function on nodes whose prices <= the parameter price

class MLSListings

Private member data: a PropertyList object

Constructor/destructor: no-op but must be explicitly defined

Private member functions:

Menu: to display the menu to the console

GetUserOption: ask user for an option (1-4) and return it

Public member functions:

Init: invoke PropertyList's Init function which is to build the Linked list of properties

Run: a menu-driven function. Use do while or while loop. Show the menu then ask for user option. A switch statement is implemented to handle user's option. Each of user option will be handled by the functions described below. No cin/cout should be seen in the Run function.

Private member functions

ViewAllProperties: invoke ViewAllProperties from the PropertyList object

SearchTownhouseByZipCode: ask user to enter a zip code then invoke SearchTownhouseByZipCode from the PropertyList object passing the zip code to the function.

SearchByMaxPrice: ask user to enter a max price then invoke SearchByMaxPrice from the PropertyList object passing the max price to the function.

Quit: Enter a goodbye message (see sample of run) and exit the loop thus exit the Run function

Main Program

Dynamically allocate an MLSListing object

Invoke its Init function

Invoke its Run function

Free memory for the object

PropertyList's Init function

Use the below information for the PropertyList's Init fucntion. I could have asked you to read a text file to load the properties into a Linked List but I'd rather see you spend time to focus on learning how to properly implement other C++ features (abstract classes, dynamic_cast, operator overloading). See helper code below to learn how to implement the Init function.

Townhouse ;1011 Giacomo Ln #6, San Jose, CA 95131;1004710;2018;250.00 SFH;200 Autumn St, La Honda, CA 94020;692000;1930;7400 SFH;2150 Monterey Rd #68, San Jose, CA 95112;169900;1963;1000 Townhouse ;410 Auburn Way #14, San Jose, CA 95129;649000;1970;230.00 Townhouse ;1256 Copper Peak Ln, San Jose, CA 95120;1150000;1986;270.00

void PropertyList::Init ( ) { Insert (new SingleFamilyHouse ("123 First Street, San Jose, CA ", 95112,450000,1956,5000.0 )); Insert (new Townhouse ("234 Hillview Ave. #245, Milpitas, CA ", 95023,670000,2010,250.0 )); Insert (new SingleFamilyHouse ("787 Adam Street, San Jose, CA", 95123,750000,1980,7000.0 )); Insert (new SingleFamilyHouse ("2580 Albert Ave., Sunnyvale, CA", 94086,1250000,2010,3000.0 ));

// insert the rest of them. Note: you must implement PropertyList::Insert to compile this Init function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions