#include <iostream.h> #include <string.h> #include <stdlib.h> //////////////////////////////////////////////////////////////////////////////// // room.h // class room { private : int floor_no; int type; // 1 = Office : 2 = Flat public : room(); void set_details(int floor_no, int type); void show_details(); }; //////////////////////////////////////////////////////////////////////////////// // room.cpp // //#include "room.h" room :: room() { floor_no = 0; //allocating memory type = 0; } void room::set_details(int fn, int ty) { floor_no = fn; type = ty; } void room::show_details() { cout<<"Floor number : " << floor_no << " Type : " << type << endl; } //////////////////////////////////////////////////////////////////////////////// // flat.h // //#include "room.h" class flat : public room { private : int bathrooms; int bedrooms; int price; int garden; public : flat(); void set_rooms(int bd, int ba, int pr, int gr); void show_rooms(); void show_all(); }; //////////////////////////////////////////////////////////////////////////////// // 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::show_rooms() { cout<<"Bedrooms : " << bedrooms << endl; cout<<"Bathrooms : " << bathrooms << endl; cout<<"price : " << price << endl; cout<<"number_of_gardens : " << garden << endl; } void flat::show_all() { show_details(); show_rooms(); } //////////////////////////////////////////////////////////////////////////////// // building.h // //#include "flat.h" class building { private : char address[200]; flat flats[20]; int no_flats; public : building(); void manage(); void add_flat(); void show_all_flats(); void remove_flat(); void price(); }; //////////////////////////////////////////////////////////////////////////////// // building.cpp // //#include "building.h" building :: building() { no_flats = 0; } void building::manage() { int option = -1; while (option != 0) { cout << " MAIN MENU " << endl; cout << " 0. Quit " << endl; cout << " 1. Add a Flat " << endl; cout << "\nEnter choice : "; cin >> option; switch(option) { case 1 : add_flat(); break; case 2: show_all_flats(); break; case 3: remove_flat(); 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; system("cls"); flats[no_flats].set_details(fn, 2); flats[no_flats].set_rooms(bd, bh, pr, gr); no_flats++; } 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::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 main() { building b; b.manage(); cout<<"\n\nProgram Complete\n\n"; }
void flat::show_all_with_gardens() { if(garden) { show_details(); show_rooms(); } } void flat::change_price() { cout<<"current price : " << price << "\nnew price? "; cin >>price; }
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::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::manage() { int option = -1; while (option != 0) { cout << " MAIN MENU " << endl; cout << " 0. Quit " << endl; cout << " 1. Add a Flat " << endl; cout << " 2. Show all Flats " << endl; cout << " 3. Remove a Flat " << endl; cout << " 4. Show all Flats with Gardens" << endl; cout << " 5. Change price " << endl; cout << "\nEnter choice : "; cin >> option; switch(option) { case 1 : add_flat(); break; case 2: show_all_flats(); break; case 3: remove_flat(); break; case 4: show_all_flats_with_gardens(); break; case 5: price(); break; } } }
MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 1 Enter Floor No : 1 Enter No bedrooms : 3 Enter No bathrooms : 2 Enter the price you wish to sell for :1000 enter number of gardens :1 MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 1 Enter Floor No : 2 Enter No bedrooms : 4 Enter No bathrooms : 2 Enter the price you wish to sell for :1500 enter number of gardens :0 MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 2 FLAT 0 ================== Floor number : 1 Type : 2 Bedrooms : 3 Bathrooms : 2 price : 1000 number_of_gardens : 1 FLAT 1 ================== Floor number : 2 Type : 2 Bedrooms : 4 Bathrooms : 2 price : 1500 number_of_gardens : 0 MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 4 FLAT 0 ================== Floor number : 1 Type : 2 Bedrooms : 3 Bathrooms : 2 price : 1000 number_of_gardens : 1 FLAT 1 ================== MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 5 Enter flat number to change price 0 - 1 : 1 current price : 1500 new price? 1250 MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 2 FLAT 0 ================== Floor number : 1 Type : 2 Bedrooms : 3 Bathrooms : 2 price : 1000 number_of_gardens : 1 FLAT 1 ================== Floor number : 2 Type : 2 Bedrooms : 4 Bathrooms : 2 price : 1250 number_of_gardens : 0 MAIN MENU 0. Quit 1. Add a Flat 2. Show all Flats 3. Remove a Flat 4. Show all Flats with Gardens 5. Change price Enter choice : 0 Program Complete
CAN SOME ONE PLEASE HELP, DAVE KINDLY HELP MEOUT ALOT, BUT I NEED SOME MORE HELP ESPECIALLY ON NUMBER 6 AND 3. I NEED TO HAND THIS WORK IN TODAY, IF I DON'T THERE WILL REDUCE 20 % OUT OF THE TOTAL MARK. PLEASE
////////////////////////////////////////////////////////////////////////////////// #include <iostream.h> #include <string.h> #include <stdlib.h> //////////////////////////////////////////////////////////////////////////////// class room { private : int floor_no; int type; // 1 = Office : 2 = Flat public : room(); void set_details(int floor_no, int type); void show_details(); };
//////////////////////////////////////////////////////////////////////////////// // room.cpp //#include "room.h" room :: room() { floor_no = 0; //allocating memory type = 0; } void room::set_details(int fn, int ty) { floor_no = fn; type = ty; } void room::show_details() { cout<<"Floor number : " << floor_no << " Type : " << type << endl; }
//////////////////////////////////////////////////////////////////////////////// // flat.h //#include "room.h" class flat : public room { private : int bathrooms; int bedrooms; int price; int garden; public : flat(); void set_rooms(int bd, int ba, int pr, int gr); void show_rooms(); void show_all(); void show_all_with_gardens(); void change_price(); };
//////////////////////////////////////////////////////////////////////////////// // 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::show_rooms() { cout<<"Bedrooms : " << bedrooms << endl; cout<<"Bathrooms : " << bathrooms << endl; cout<<"price : " << price << endl; cout<<"number_of_gardens : " << garden << endl; } void flat::show_all() { show_details(); show_rooms(); }
//////////////////////////////////////////////////////////////////////////////// // building.h //#include "flat.h" class building { private : char address[200]; flat flats[20]; int no_flats; public : building(); void manage(); void add_flat(); void show_all_flats(); void remove_flat(); void price(); void show_all_flats_with_gardens(); };
//////////////////////////////////////////////////////////////////////////////// // building.cpp //#include "building.h" building :: building() { no_flats = 0; } void building::manage() { int option = -1; while (option != 0) { cout << " MAIN MENU " << endl; cout << " 0. Quit " << endl; cout << " 1. Add a Flat " << endl; cout << " 2. Show all Flats " << endl; cout << " 3. Remove a Flat " << endl; cout << " 4. Show all Flats with Gardens" << endl; cout << " 5. Change price " << endl; cout << "\nEnter choice : "; cin >> option; switch(option) { case 1 : add_flat(); break; case 2: show_all_flats(); break; case 3: remove_flat(); break; case 4: show_all_flats_with_gardens(); break; case 5: price(); 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; system("cls"); flats[no_flats].set_details(fn, 2); flats[no_flats].set_rooms(bd, bh, pr, gr); no_flats++; } 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::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 flat::show_all_with_gardens() { if(garden) { show_details(); show_rooms(); } } void flat::change_price() { cout<<"current price : " << price << "\nnew price? "; cin >>price; } 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::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 main() { building b; b.manage(); cout<<"\n\nProgram Complete\n\n"; }
| DaniWeb Message | |
| Cancel Changes | |