Answer to Question #326781 in C++ for ItsmeZee

Question #326781

 Create an Address class, which contains street#, house#, city and code (all of type char*).

Create another class Person that contains an address of type Address. Give appropriate get

and set functions for both classes. Test class person in main.


1
Expert's answer
2022-04-11T12:12:58-0400
#include <iostream>
#include <string>
using namespace std;


class Address
{
protected:
	char street[50];
	char house[50];
	char city[50];
	char code[50];


public:
	Address() {};


	Address(char* _street, char* _house, char* _city, char* _code)
	{}


	virtual void printInfo() = 0;


	virtual ~Address() {};
};


class Person : public Address
{
public:


	Person(char* _street, char* _house, char* _city, char* _code) : Address(_street, _house, _city, _code) {}


	void printInfo()
	{
		cout << street << endl;
		cout << house << endl;
		cout << city << endl;
		cout << code << endl;
	}
};


int main()
{
	Person* p = new Person("Street no.1", "House no.9", "New York", "140114");


	p->printInfo();


	delete p;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS