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.
#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;
}
Comments
Leave a comment