Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Room
- {
- private:
- double width, length, height;
- public:
- Room(): width(3), length(3), height(3) {}
- Room(double w, double l, double h): width(w), length(l), height(h) {}
- double area_to_paint()
- {
- double area = (width*length)+2*(width*height)+2*(length*height);
- return area;
- }
- };
- class Person
- {
- private:
- string name;
- string email;
- public:
- Person(): name(), email("") {}
- Person(string name_p, string email_p): name(name_p), email(email_p) {}
- friend ostream& operator << (ostream&os, Person&p){
- os << p.name << " " << p.email << " ";
- return os;
- }
- };
- class House
- {
- private:
- Person* owner;
- int room_amount;
- Room *rooms;
- public:
- House(Person* o, int amount)
- {
- owner = o;
- room_amount = amount;
- rooms = new Room[room_amount];
- }
- Person get_owner(){ return *owner; }
- double area_to_paint()
- {
- double summary_area = 0;
- for(int i=0; i<room_amount; i++)
- {
- summary_area += rooms[i].area_to_paint();
- }
- return summary_area;
- }
- double cash_for_house(double price)
- {
- return price* area_to_paint();
- }
- ~House()
- {
- delete[]rooms;
- }
- };
- void main()
- {
- Person first("Vlad", "vlad@yahoo.com");
- Person second("Max", "max@yahoo.com");
- Person third("Sofia", "vlad@yahoo.com");
- House h1(&first, 4);
- House h2(&second, 2);
- House h3(&third, 3);
- House h4(&second, 5);
- cout << "Enter the price for 1 sq. meter for each house:\n";
- double price;
- cin >> price;
- cout << h1.get_owner() << h1.cash_for_house(price) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement