allows a user to put a maximum and minimum price and see all properties in that price

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #1
Apr 25th, 2005
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 ==);
  1. /////////////////////////////////////////////////////////////////
  2. //****FILE - flat.h ****
  3. /////////////////////////////////////////////////////////////////
  4. #include <iostream.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. class flat
  8. {
  9. private :
  10. int bathrooms;
  11. int bedrooms;
  12. int price;
  13. int garden;
  14.  
  15. public :
  16. flat();
  17. void set_rooms(int bd, int ba, int pr, int gr);
  18. void display_rooms();
  19. void show_all();
  20. void change_price();
  21. void show_all_with_gardens();
  22. };
  23.  
  24. //////////////////////////////////////////////////////
  25. //****flat.cpp ****
  26. //////////////////////////////////////////////////////
  27.  
  28. //#include "flat.h"
  29.  
  30. flat :: flat()
  31. {
  32. bedrooms = 0;
  33. bathrooms = 0;
  34. }
  35.  
  36. void flat::set_rooms(int bd, int ba, int pr, int gr)
  37. {
  38. bedrooms = bd;
  39. bathrooms = ba;
  40. price = pr;
  41. garden = gr;
  42. }
  43.  
  44. void flat::display_rooms()
  45. {
  46. cout<<"Bedrooms : " << bedrooms << endl;
  47. cout<<"Bathrooms : " << bathrooms << endl;
  48. cout << "Price :" << price << endl;
  49. cout << "Garden: " << garden << endl;
  50. }
  51.  
  52. void flat::show_all()
  53. {
  54. display_rooms();
  55. }
  56.  
  57. ///////////////////////////////////////////////////////
  58. //****FILE - house.h ****
  59. //////////////////////////////////////////////////////
  60.  
  61. class house
  62. {
  63. private :
  64. int bathrooms;
  65. int bedrooms;
  66. int price;
  67. int garden;
  68.  
  69. public :
  70. house();
  71. void set_rooms(int bd, int ba, int pr, int gr);
  72. void display_rooms();
  73. void show_all();
  74. void change_price();
  75. void show_all_with_gardens();
  76.  
  77. };
  78.  
  79. ////////////////////////////////////////////////////////
  80. //****FILE - house.cpp ****
  81. ///////////////////////////////////////////////////////
  82.  
  83. //#include "house.h"
  84.  
  85. house :: house()
  86. {
  87. bedrooms = 0;
  88. bathrooms = 0;
  89. price = 0;
  90. garden = 0;
  91. }
  92.  
  93. void house::set_rooms(int bd, int ba, int pr, int gr)
  94. {
  95. bedrooms = bd;
  96. bathrooms = ba;
  97. price = pr;
  98. garden = gr;
  99. }
  100.  
  101. void house::display_rooms()
  102. {
  103. cout<<"Bedrooms : " << bedrooms << endl;
  104. cout<<"Bathrooms : " << bathrooms << endl;
  105. cout << "Price :" << price << endl;
  106. }
  107.  
  108. void house::show_all()
  109. {
  110. display_rooms();
  111. }
  112.  
  113. //////////////////////////////////////////////
  114. //24 April 2005
  115. //**** FILE - building.h ****
  116. /////////////////////////////////////////////
  117.  
  118. //#include "flat.h"
  119. //#include "house.h"
  120.  
  121.  
  122.  
  123. class building
  124. {
  125. private :
  126.  
  127. flat flats[20];
  128. house houses[20];
  129. int no_flats;
  130. int no_houses;
  131.  
  132. public :
  133.  
  134. building();
  135. void control(); //display menu, control the program
  136. void add_flat(); // add flat to sell
  137. void remove_flat(); // remove flat
  138. void show_all_flats(); // display all flats for sale
  139. void show_all_house(); //display all houses for sale
  140. void remove_house(); //remove house
  141. void add_house(); // add house to sell
  142. void price(); //change flat price
  143. void housePrice(); //chnage house price
  144. void show_all_flats_with_gardens(); //display all flat with garden
  145. void show_all_houses_with_gardens(); //display all houses with garden
  146. void sellFlat(); //sell flat
  147. void sellHouse(); //sell house
  148. };
  149. /////////////////////////////////////////////////////////
  150. //**** FILE - building.cpp ****
  151. ////////////////////////////////////////////////////////
  152.  
  153. //#include "building.h"
  154.  
  155. building :: building()
  156. {
  157. no_flats = 0;
  158. no_houses = 0;
  159.  
  160. }
  161.  
  162. void building::control()
  163. {
  164. int option = -1;
  165. while (option != 0)
  166. {
  167. cout << "\n#### MAIN MENU ####\n";
  168. cout << "0. Quit\n";
  169. cout << "1. Add a Flat\n";
  170. cout << "2. Add an House\n";
  171. cout << "3. Remove a Flat\n";
  172. cout << "4. Remove an House\n";
  173. cout << "5. Show all flats " << endl;
  174. cout << "6. Show all Houses " << endl;
  175. cout << "7. show all flats with gardens " << endl;
  176. cout << "8. show all Houses with gardens " << endl;
  177. cout << "9.Change flat price " << endl;
  178. cout << "10.Change Houses price " << endl;
  179. cout << "11.Sell house " << endl;
  180. cout << "12.Sell Flat " << endl;
  181.  
  182. cout << "\nEnter choice : ";
  183. cin >> option;
  184.  
  185. system("cls");
  186. switch(option)
  187. {
  188. case 1 : add_flat();
  189. break;
  190. case 2 : add_house();
  191. break;
  192. case 3 : remove_flat();
  193. break;
  194. case 4 : remove_house();
  195. break;
  196. case 5 : show_all_flats();
  197. break;
  198. case 6 : show_all_house();
  199. break;
  200. case 7: show_all_flats_with_gardens();
  201. break;
  202. case 8: show_all_houses_with_gardens();
  203. break;
  204. case 9: price();
  205. break;
  206. case 10: housePrice();
  207. break;
  208. case 11: sellFlat();
  209. break;
  210. case 12: sellHouse();
  211. break;
  212. }
  213. }
  214. }
  215.  
  216. void building::add_flat()
  217. {
  218. int fn, bd, bh, pr, gr;
  219.  
  220. cout << "Enter Floor No : ";
  221. cin >> fn;
  222. cout << "Enter No bedrooms : ";
  223. cin >> bd;
  224. cout << "Enter No bathrooms : ";
  225. cin >> bh;
  226. cout << "Enter the price you wish to sell for :";
  227. cin >> pr;
  228. cout << "enter number of gardens :";
  229. cin >> gr;
  230. flats[no_flats].set_rooms(bd, bh, pr, gr);
  231. no_flats++;
  232. }
  233.  
  234.  
  235. void building::add_house()
  236. {
  237. int fn, bd, bh,pr,gr;
  238.  
  239. cout << "Enter Floor No : ";
  240. cin >> fn;
  241. cout << "Enter No bedrooms : ";
  242. cin >> bd;
  243.  
  244. cout << "Enter No bathrooms : ";
  245. cin >> bh;
  246. cout << "Enter the price you wish to sell for :";
  247. cin >> pr;
  248. cout << "enter number of gardens :";
  249. cin >> gr;
  250.  
  251. houses[no_houses].set_rooms(bd, bh, pr, gr);
  252. no_houses++;
  253. }
  254.  
  255. void building::remove_flat()
  256. {
  257. int flat_rem;
  258.  
  259. if (no_flats == 0)
  260. {
  261. cout << "There are no flats!!!\n";
  262. return;
  263. }
  264. cout << "Enter flat number to remove 0 - " << (no_flats - 1) << " : ";
  265. cin >> flat_rem;
  266. if (flat_rem >= 0 && flat_rem <= no_flats -1)
  267. {
  268. flats[flat_rem] = flats[no_flats - 1];
  269. no_flats--;
  270. cout << "Flat " << flat_rem << " was removed\n";
  271. }
  272. }
  273.  
  274. void building::remove_house()
  275. {
  276. int house_rem;
  277.  
  278. if (no_houses == 0)
  279. {
  280. cout << "There are no houses!!!\n";
  281. return;
  282. }
  283. cout << "Enter house number to remove 0 - " << (no_houses - 1) << " : ";
  284. cin >> house_rem;
  285. if (house_rem >= 0 && house_rem <= no_houses -1)
  286. {
  287. flats[house_rem] = flats[no_houses - 1];
  288. no_houses--;
  289. cout << "house " << house_rem << " was removed\n";
  290. }
  291. }
  292. void building::show_all_flats()
  293. {
  294. for (int i = 0 ; i < no_flats ; i++)
  295. {
  296. cout << "FLAT " << i << " ==================\n";
  297. flats[i].show_all();
  298. cout << endl;
  299. }
  300. }
  301.  
  302. void building::show_all_house()
  303. {
  304. for (int i = 0 ; i < no_flats ; i++)
  305. {
  306. cout << "FLAT " << i << " ==================\n";
  307. houses[i].show_all();
  308. cout << endl;
  309. }
  310. }
  311.  
  312. void building :: price()
  313. {
  314. int flat_rem;
  315.  
  316. if (no_flats == 0)
  317. {
  318. cout << "There are no flats!!!\n";
  319. return;
  320. }
  321. cout << "Enter flat number to change price 0 - " << (no_flats - 1)
  322. << " : ";
  323. cin >> flat_rem;
  324. if (flat_rem >= 0 && flat_rem <= no_flats -1)
  325. {
  326. flats[flat_rem].change_price();
  327. }
  328. }
  329.  
  330. void building::housePrice()
  331. {
  332. int house_rem;
  333.  
  334. if (no_houses == 0)
  335. {
  336. cout << "There are no houses!!!\n";
  337. return;
  338. }
  339. cout << "Enter house number to change price 0 - " << (no_houses - 1)
  340. << " : ";
  341. cin >> house_rem;
  342. if (house_rem >= 0 && house_rem <= no_houses -1)
  343. {
  344. houses[house_rem].change_price();
  345. }
  346. }
  347.  
  348. void flat::show_all_with_gardens()
  349. {
  350. if(garden)
  351. {
  352. display_rooms();
  353. }
  354. }
  355.  
  356. void house::show_all_with_gardens()
  357. {
  358. if(garden)
  359. {
  360. display_rooms();
  361. }
  362. }
  363.  
  364. void building::show_all_flats_with_gardens()
  365. {
  366. for (int i = 0 ; i < no_flats ; i++)
  367. {
  368. cout << "FLAT " << i << " ==================\n";
  369. flats[i].show_all_with_gardens();
  370. cout << endl;
  371. }
  372. }
  373.  
  374. void building::show_all_houses_with_gardens()
  375. {
  376. for (int i = 0 ; i < no_houses ; i++)
  377. {
  378. cout << "HOUSE " << i << " ==================\n";
  379. houses[i].show_all_with_gardens();
  380. cout << endl;
  381. }
  382. }
  383.  
  384. void flat::change_price()
  385. {
  386. cout<<"current price : " << price << "\nnew price? ";
  387. cin >>price;
  388. }
  389.  
  390. void house::change_price()
  391. {
  392. cout<<"current price : " << price << "\nnew price? ";
  393. cin >>price;
  394. }
  395.  
  396.  
  397. void building::sellFlat()
  398. {
  399. int flat_sold;
  400.  
  401. if (no_flats == 0)
  402. {
  403. cout << "There are no flats to sell!!!\n";
  404. return;
  405. }
  406. cout << "Enter flat number to sell 0 - " << (no_flats - 1) << " : ";
  407. cin >> flat_sold;
  408. if (flat_sold >= 0 && flat_sold <= no_flats -1)
  409. {
  410. flats[flat_sold] = flats[no_flats - 1];
  411. no_flats--;
  412. cout << "Flat " << flat_sold << " was removed\n";
  413. }
  414. }
  415.  
  416. void building::sellHouse()
  417. {
  418. int house_sold;
  419.  
  420. if (no_houses == 0)
  421. {
  422. cout << "There are no houses to sell!!!\n";
  423. return;
  424. }
  425. cout << "Enter house number to sell 0 - " << (no_houses - 1) << " : ";
  426. cin >> house_sold;
  427. if (house_sold >= 0 && house_sold <= no_houses -1)
  428. {
  429. houses[house_sold] = houses[no_houses - 1];
  430. no_houses--;
  431. cout << "house " << house_sold << " was removed sucessfully\n";
  432. }
  433. }
  434.  
  435. ///////////////////////////////////////////////////////////////////
  436. //**** FILE - main.cpp ****
  437. //////////////////////////////////////////////////////////////////
  438.  
  439. //#include "building.h";
  440.  
  441. void main()
  442. {
  443. building b;
  444. b.control();
  445. cout <<" Program Finised: " << endl;
  446. }
Code tags added. -Narue
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #2
Apr 25th, 2005
please help
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,579
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #3
Apr 25th, 2005
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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #4
Apr 25th, 2005
am sorry, thanks anywhere
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #5
Apr 26th, 2005
i really am in need of help
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #6
Apr 26th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: allows a user to put a maximum and minimum price and see all properties in that price

 
0
  #7
Apr 27th, 2005
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:
  1. building::searchPrice(int minPrice, int maxPrice)
  2. {
  3. //search for houses in the array
  4. //display houses found
  5. }
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.
Yeah... I'm lazy. Deal with it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC