Question


Design/Construct two related classes: House and HouseAddress, and these two classes must be related appropriately (3 points).

Please answer in C++. Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<cstring>
using namespace std;
class HouseAddress
{
int houseNo;
string city;
public:
//constructor
HouseAddress(int houseNo=0,string city="")
{
this->houseNo=houseNo;
this->city=city;
}
void show()
{
cout<<"House Number: "<<this->houseNo<<endl;
cout<<"City: "<<this->city<<endl;
}
};
//Every house has HouseAddress both are having aggregation relationship
class House
{
string houseName;
HouseAddress address;
public:
House(string houseName,HouseAddress address)
{
this->houseName=houseName;
this->address=address;
}
void display()
{
cout<<"House Name: "<<this->houseName<<endl;
address.show();
}
};
int main()
{
HouseAddress address(100,"Texas");
House house("Beautiful house",address);
house.display();
return 0;
}

Output

koushikhp@koushikhpnew:~$ g++ HouseTest.cpp
koushikhp@koushikhpnew:~$ ./a.out
House Name: Beautiful house
House Number: 100
City: Texas

Add a comment
Know the answer?
Add Answer to:
Please answer in C++. Thank you Design/Construct two related classes: House and HouseAddress, and these two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • Objective: The purpose of this lab project is to expose you to structures and classes. Problem...

    Objective: The purpose of this lab project is to expose you to structures and classes. Problem Specification: You are to write a program that will define a structure consisting of the following data members, “fields”: name hours worked hourly rate Use a structure to implement the following: You will use a function to read the name, hours and rate, passing them individually by reference to the main function. Call a function to print, this function accepts the entire structure by...

  • Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the...

    Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables...

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

  • Help with this coding assignment for C++! Add any comments for better understanding. Create a class...

    Help with this coding assignment for C++! Add any comments for better understanding. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • (Classes and Objects) Design a class named Box. The class should have the following private members:...

    (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • C++ Exercice Topic Cover: Class and main implementation 1. Created the class circle.h file 2. Create...

    C++ Exercice Topic Cover: Class and main implementation 1. Created the class circle.h file 2. Create the Circle. cpp 3. Create the main function and use the class Circle in your program (CircleClass) Create a class called circle in other to performing the calculation of the area, sectional area and circumference of any circle. Write a program to test your class. Circle Use double variables to represent the private data of the class. Provide a constructor that enables an object...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT