I started learning C++ recently and I'm having a problem with an assignment I need to write, my assignment requires that I will create a class constructor that has another variable of a different class type. my main class is 'person' and I have two other classes 'address and 'job', in my assignment I need to create setter and getter for each variable I have in the different classes, and in each setter and getter I have to print if the operation was successful or not. so here is the problem I haveing, when I call the 'person' parameter constructor in my main file its immediately call 'address' and 'job' default constructor which prints the default setter and getter in their constructors and that is something I want to avoid because I don't want it to print the default values, is there any way of avoiding the default constructor? unfortunately, I can't remove the printד from the setter and getter and I can't change the variables of the 'person' constructor, also I have to use the set and get in the default constructor
class person
{
private:
char *name;
char *phoneNumber;
char *email;
int savings;
address Address;
job Job;
public:
person();
person(const char *name, const char *phoneNumber, const char *email, address Address, job Job);
~person();}
address:
class address {
private:
char* street;
char* city;
int postalCode;
public:
address();
address(const char* street,const char* city, int postalCode);
~address();}
job:
class job {
private:
char* title;
int salary;
departmentEnum department;
public:
job();
job(const char* title, int salary, departmentEnum department);
~job();}
person constructor - it actually prints both the default values of 'address' and 'job' and the values I sent to the person constructor.
person::person(const char *nameP, const char *phoneNumberP, const char *emailP, address AddressP, job JobP)
{
setName(nameP);
setPhoneNumber(phoneNumberP);
setEmail(emailP);
Address.setCity(AddressP.getCity());
Address.setPostalCode(AddressP.getPostalCode());
Address.setStreet(AddressP.getStreet());
Job.setSalary(JobP.getSalary());
Job.setDepartment(JobP.getDepartment());
Job.setTitle(JobP.getTitle());
}
address default constructor
address::address()
{
setStreet("test");
setCity("test");
setPostalCode(12345);
}