I'm currently working on an object oriented project for C++ programming. I have created a few objects:
int main()
{
Address address1 = Address("7732","cambie street","vancouver","BC","v5p3r3");
Author author1 = Author("Joe","Howe","joehow@hotmail.ca");
Publisher publisher1("candy",address1);
Book book1 = Book("sprite",author1,publisher1,"1995");
return 0;
}
and here are my 4 object constructors
Address::Address(string number, string name, string c, string crty, string pCode){
streetNumber = number;
streetName = name;
city = c;
country = crty;
postalCode = pCode;
}
Book::Book(string newTitle, Author author1,Publisher pub, string y){
ISBN++;
bookISBN = ISBN;
title = newTitle;
a = author1;
authorCount = 1;
d = pub;
year = y;
}
Author::Author(string fN, string lN, string e){
firstName = fN;
lastName = lN;
email = e;
}
Publisher::Publisher(string n, Address x){
name = n;
a = x;
}
when i call these functions in the main
cout << book1.getPublisher().getAddress().getCity() << endl;
book1.getPublisher().getAddress().set("washington",Address::CITY);
cout << book1.getPublisher().getAddress().getCity() << endl;
not sure if these are allowed in c++ i've done them in java,
i've also tried separating them and it would give me the desired results,
so my question becomes is this format allowed in c++ and if so what am i doing wrong.
my result displays
vancouver
vancouver
but my desired result would be
vancouver
washington
these are my get/set functions
Address Publisher::getAddress(){
return a;
}
Publisher Book::getPublisher(){
return d;
}
void Address::set(string value , int number){
switch(number)
{
case STREET_NUMBER:
streetNumber = value;break;
case STREET_NAME:
streetName = value;break;
case CITY:
city = value;break;
case COUNTRY:
country = value;break;
case POSTAL_CODE:
postalCode = value;break;
}
}
Thanks for the help