hello am in need of some help on question 7 and 11, if someone has time please also try question 15. i really don't have any idea how to do the following question, and i need to have this assignment in soon. could you please try. thank you

(7)
allows a user to put a maximum and minimum price and see all properties in that price range.

(11)
allows a user to see all properties with certain number of bedrooms or more

if you have time. but not important

(15)
allows a user to see all properties in a "similar" range - where "similar" is defined as the same number of bedroons and the same garden status (HINT overload ==);

/////////////////////////////////////////////////////////////////
//****FILE - flat.h ****
/////////////////////////////////////////////////////////////////
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
class flat 
{
	private :
		int bathrooms;
		int bedrooms;
		int price;
		int garden;

	public :
		flat();
		void set_rooms(int bd, int ba, int pr, int gr);
		void display_rooms();
		void show_all();
		void change_price();
		void show_all_with_gardens();
};

//////////////////////////////////////////////////////
//****flat.cpp ****
//////////////////////////////////////////////////////

//#include "flat.h"

flat :: flat()
{
	bedrooms = 0;
	bathrooms = 0;
}

void flat::set_rooms(int bd, int ba, int pr, int gr)
{
	bedrooms = bd;
	bathrooms = ba;
	price = pr;
	garden = gr;
}

void flat::display_rooms()
{
	cout<<"Bedrooms : " << bedrooms << endl;
	cout<<"Bathrooms : " << bathrooms << endl;
	cout << "Price :" << price << endl;
	cout << "Garden: " << garden << endl;
}

void flat::show_all()
{
	display_rooms();
}

///////////////////////////////////////////////////////
//****FILE - house.h ****
//////////////////////////////////////////////////////

class house
{
private :
	int bathrooms;
	int bedrooms;
	int price;
	int garden;

public :
	house();
	void set_rooms(int bd, int ba, int pr, int gr);
	void display_rooms();
	void show_all();
	void change_price();
	void show_all_with_gardens();

};

////////////////////////////////////////////////////////
//****FILE - house.cpp ****
///////////////////////////////////////////////////////

//#include "house.h"

house :: house()
{
	bedrooms = 0;
	bathrooms = 0;
	price = 0;
	garden = 0;
}

void house::set_rooms(int bd, int ba, int pr, int gr)
{
	bedrooms = bd;
	bathrooms = ba;
	price = pr;
	garden = gr;
}

void house::display_rooms()
{
	cout<<"Bedrooms : " << bedrooms << endl;
	cout<<"Bathrooms : " << bathrooms << endl;
	cout << "Price :" << price << endl;
}

void house::show_all()
{
	display_rooms();
}

//////////////////////////////////////////////
//24 April 2005
//**** FILE - building.h ****
/////////////////////////////////////////////

//#include "flat.h"
//#include "house.h"



class building
{
	private :

		flat flats[20];
		house houses[20];
		int no_flats;
		int no_houses;

	public :

		building();
		void control(); //display menu, control the program
		void add_flat(); // add flat to sell
		void remove_flat(); // remove flat 
		void show_all_flats(); // display all flats for sale
		void show_all_house(); //display all houses for sale
		void remove_house(); //remove house
		void add_house(); // add house to sell
		void price(); //change flat price
		void housePrice(); //chnage house price
		void show_all_flats_with_gardens(); //display all flat with garden
		void show_all_houses_with_gardens(); //display all houses with garden
		void sellFlat(); //sell flat
		void sellHouse(); //sell house
};
/////////////////////////////////////////////////////////
//**** FILE - building.cpp ****
////////////////////////////////////////////////////////

//#include "building.h"

building :: building()
{
   no_flats = 0;
   no_houses = 0;

}

void building::control()
{
	int option = -1;
	while (option != 0)
	{
      cout << "\n#### MAIN MENU ####\n";
		cout << "0. Quit\n";
		cout << "1. Add a Flat\n";
		cout << "2. Add an House\n";
		cout << "3. Remove a Flat\n";
		cout << "4. Remove an House\n";
		cout << "5. Show all flats " << endl;
		cout << "6. Show all Houses " << endl;
		cout << "7. show all flats with gardens " << endl;
		cout << "8. show all Houses with gardens " << endl;
		cout << "9.Change flat price " << endl;
		cout << "10.Change Houses price " << endl;
		cout << "11.Sell house " << endl;
		cout << "12.Sell Flat " << endl;

		cout << "\nEnter choice : ";
		cin >> option;

		system("cls");
		switch(option)
		{
		case 1 : add_flat();
			break;
		case 2 : add_house();
			break;
		case 3 : remove_flat();
			break;
		case 4 : remove_house();
			break;
		case 5 : show_all_flats();
			break;
		case 6 : show_all_house();
			break;
		case 7: show_all_flats_with_gardens();
			break;
		case 8: show_all_houses_with_gardens();
			break;
		case 9: price();
			break;
		case 10: housePrice();
			break;
		case 11: sellFlat();
			break;
		case 12: sellHouse();
			break;
		}
	}
}

void building::add_flat()
{
	int fn, bd, bh, pr, gr;

	cout << "Enter Floor No : ";
	cin >> fn;
	cout << "Enter No bedrooms : ";
	cin >> bd;
	cout << "Enter No bathrooms : ";
	cin >> bh;
	 cout << "Enter the price you wish to sell for :";
   cin >> pr;
     cout << "enter number of gardens :";
   cin >> gr;
	flats[no_flats].set_rooms(bd, bh, pr, gr);
	no_flats++;
}


void building::add_house()
{
	int fn, bd, bh,pr,gr;

	cout << "Enter Floor No : ";
	cin >> fn;
	cout << "Enter No bedrooms : ";
	cin >> bd;
	
	cout << "Enter No bathrooms : ";
	cin >> bh;
	 cout << "Enter the price you wish to sell for :";
   cin >> pr;
     cout << "enter number of gardens :";
   cin >> gr;

	houses[no_houses].set_rooms(bd, bh, pr, gr);
	no_houses++;
}

void building::remove_flat()
{
	int flat_rem;

	if (no_flats == 0)
	{
		cout << "There are no flats!!!\n";
		return;
	}
	cout << "Enter flat number to remove 0 - " << (no_flats - 1) << " : ";
	cin >> flat_rem;
	if (flat_rem >= 0 && flat_rem <= no_flats -1)
	{
		flats[flat_rem] = flats[no_flats - 1];
		no_flats--;
		cout << "Flat " << flat_rem << " was removed\n";
	}
}

void building::remove_house()
{
	int house_rem;

	if (no_houses == 0)
	{
		cout << "There are no houses!!!\n";
		return;
	}
	cout << "Enter house number to remove 0 - " << (no_houses - 1) << " : ";
	cin >> house_rem;
	if (house_rem >= 0 && house_rem <= no_houses -1)
	{
		flats[house_rem] = flats[no_houses - 1];
		no_houses--;
		cout << "house " << house_rem << " was removed\n";
	}
}
void building::show_all_flats()
{
	for (int i = 0 ; i < no_flats ; i++)
	{
		cout << "FLAT " << i << "  ==================\n";
		flats[i].show_all();
		cout << endl;
	}
}

void building::show_all_house()
{
	for (int i = 0 ; i < no_flats ; i++)
	{
		cout << "FLAT " << i << "  ==================\n";
		houses[i].show_all();
		cout << endl;
	}
}

void building :: price()
{
   int flat_rem;

   if (no_flats == 0)
   {
      cout << "There are no flats!!!\n";
      return;
   }
   cout << "Enter flat number to change price 0 - " << (no_flats - 1) 
<< " : ";
   cin >> flat_rem;
   if (flat_rem >= 0 && flat_rem <= no_flats -1)
   {
      flats[flat_rem].change_price();
   }
}

void building::housePrice()
{
   int house_rem;

   if (no_houses == 0)
   {
      cout << "There are no houses!!!\n";
      return;
   }
   cout << "Enter house number to change price 0 - " << (no_houses - 1) 
<< " : ";
   cin >> house_rem;
   if (house_rem >= 0 && house_rem <= no_houses -1)
   {
      houses[house_rem].change_price();
   }
}

void flat::show_all_with_gardens()
{
   if(garden)
   {
      display_rooms();
   }
}

void house::show_all_with_gardens()
{
   if(garden)
   {
      display_rooms();
   }
}

void building::show_all_flats_with_gardens()
{
   for (int i = 0 ; i < no_flats ; i++)
   {
      cout << "FLAT " << i << "  ==================\n";
      flats[i].show_all_with_gardens();
      cout << endl;
   }
}

void building::show_all_houses_with_gardens()
{
   for (int i = 0 ; i < no_houses ; i++)
   {
      cout << "HOUSE " << i << "  ==================\n";
      houses[i].show_all_with_gardens();
      cout << endl;
   }
}

void flat::change_price()
{
   cout<<"current price : " << price << "\nnew price? ";
   cin >>price;
}

void house::change_price()
{
   cout<<"current price : " << price << "\nnew price? ";
   cin >>price;
}


void building::sellFlat()
{
	int flat_sold;

	if (no_flats == 0)
	{
		cout << "There are no flats to sell!!!\n";
		return;
	}
	cout << "Enter flat number to sell 0 - " << (no_flats - 1) << " : ";
	cin >> flat_sold;
	if (flat_sold >= 0 && flat_sold <= no_flats -1)
	{
		flats[flat_sold] = flats[no_flats - 1];
		no_flats--;
		cout << "Flat " << flat_sold << " was removed\n";
	}
}

void building::sellHouse()
{
	int house_sold;

	if (no_houses == 0)
	{
		cout << "There are no houses to sell!!!\n";
		return;
	}
	cout << "Enter house number to sell 0 - " << (no_houses - 1) << " : ";
	cin >> house_sold;
	if (house_sold >= 0 && house_sold <= no_houses -1)
	{
		houses[house_sold] = houses[no_houses - 1];
		no_houses--;
		cout << "house " << house_sold << " was removed sucessfully\n";
	}
}

///////////////////////////////////////////////////////////////////
//**** FILE - main.cpp ****
//////////////////////////////////////////////////////////////////

//#include "building.h";

void main()
{
	building b;
	b.control();
	cout <<" Program Finised: " << endl;
}

Code tags added. -Narue

Recommended Answers

All 6 Replies

please help

Don't post that much code without code tags, and don't bump your thread after just an hour. Both are incredibly rude and don't encourage people to help you.

am sorry, thanks anywhere

i really am in need of help

so.... what are you having problems with? Are you getting any errors? Is it not giving the right values for something? Let us know what the problem is and we can try to help you

Please don't ask for help in a private message. I will be more than happy to help you if you just let us know what part of this assignment you are having a problem with... not just which assignment numbers then all of your code.

For assignment 7.) - it seems you need to implement a search function in your building class and hold the array index of each house within the price range in another array, then display them. Something like the following prototype with what I've described defining it:

building::searchPrice(int minPrice, int maxPrice)
{
//search for houses in the array
//display houses found
}

If you are still having problems with that, then show me the code you try for it and we'll see what we can work with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.