In: Computer Science
C++ programming question class Address { public: Address(const std::string& street, const std::string& city, const std::string& state, const std::string& zip) : StreetNumber(street), CityName(city), StateName(state), ZipCode(zip) {} std::string GetStreetNumber() const { return StreetNumber; } void SetStreetNumber(const std::string& street) { StreetNumber = street; } std::string GetCity() const { return CityName; } void SetCity(const std::string& city) { CityName = city; } std::string GetState() const { return StateName; } void SetState(const std::string& state) { StateName = state; } std::string GetZipCode() const { return ZipCode; } void SetZipCode(const std::string& zip) { ZipCode = zip; } private: std::string StreetNumber; std::string CityName; std::string StateName; std::string ZipCode; };
If an array of Address objects, using the class definition above, were to be created using the line below, what would happen?
Address myAddresses[100];
A. |
The code would not compile. |
B. |
An array of 100 Address objects would be instantiated. |
C. The compiler would generate the necessary functions to create the objects.
This code makes no sense and it is not completely visible here.
Although i tried completing the snippet to this:
#include <string>
class Address { public: Address(const std::string& street, const std::string& city, const std::string& state, const std::string& zip) : StreetNumber(street), CityName(city), StateName(state), ZipCode(zip)};
int main(){
Address myAddresses[100];
}
i ran the program and this is what was shown:
So obviously this code does not run and if you carefully look at the last error defined in the red says, no function defined at all.
Therefore the answer should be A. The code won't compile.
unless this is not the code you meant. If there are changes in the code, post them in the comments and i'll get back to you.
If you are satisfied with the answer, please leave in a thumbs up. It really matters.
Thank you.