Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class Room
  5. {
  6. private:
  7. double width, length, height;
  8. public:
  9. Room(): width(3), length(3), height(3) {}
  10. Room(double w, double l, double h): width(w), length(l), height(h) {}
  11. double area_to_paint()
  12. {
  13. double area = (width*length)+2*(width*height)+2*(length*height);
  14. return area;
  15. }
  16. };
  17. class Person
  18. {
  19. private:
  20. string name;
  21. string email;
  22. public:
  23. Person(): name(), email("") {}
  24. Person(string name_p, string email_p): name(name_p), email(email_p) {}
  25. friend ostream& operator << (ostream&os, Person&p){
  26. os << p.name << " " << p.email << " ";
  27. return os;
  28. }
  29.  
  30. };
  31. class House
  32. {
  33. private:
  34. Person* owner;
  35. int room_amount;
  36. Room *rooms;
  37. public:
  38. House(Person* o, int amount)
  39. {
  40. owner = o;
  41. room_amount = amount;
  42. rooms = new Room[room_amount];
  43. }
  44. Person get_owner(){ return *owner; }
  45. double area_to_paint()
  46. {
  47. double summary_area = 0;
  48. for(int i=0; i<room_amount; i++)
  49. {
  50. summary_area += rooms[i].area_to_paint();
  51. }
  52. return summary_area;
  53. }
  54. double cash_for_house(double price)
  55. {
  56. return price* area_to_paint();
  57. }
  58. ~House()
  59. {
  60. delete[]rooms;
  61. }
  62. };
  63. void main()
  64. {
  65. Person first("Vlad", "vlad@yahoo.com");
  66. Person second("Max", "max@yahoo.com");
  67. Person third("Sofia", "vlad@yahoo.com");
  68. House h1(&first, 4);
  69. House h2(&second, 2);
  70. House h3(&third, 3);
  71. House h4(&second, 5);
  72. cout << "Enter the price for 1 sq. meter for each house:\n";
  73. double price;
  74. cin >> price;
  75. cout << h1.get_owner() << h1.cash_for_house(price) << endl;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement