Question

In: Computer Science

C++ programming question class Address { public: Address(const std::string& street, const std::string& city, const std::string& state,...

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.

Solutions

Expert Solution


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.


Related Solutions

#include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); #define BUFFLEN 10...
#include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); #define BUFFLEN 10 /*     This code closely mimics the Python hash table we created in class this     week. Each "person" is defined by their name, zipcode, and their pet's name.     Persons are hashed by their zipcode. */ //---------------------------------------------------------------------------- /* function declarations ------------------------*/ int computeKey(int); void add_to_buffer(string,int,string); void find_in_buffer(int); //---------------------------------------------------------------------------- /* define a "person" --------------------*/ class person{     public:     // variables that define a person     string name;     int zipcode;...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance);...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance); const string & getName() const; double getDistance() const; void setDistance(double); // Passes in the departure time (as minute) and returns arrival time (as minute) // For example: // 8 am will be passed in as 480 minutes (8 * 60) // 2:30 pm will be passed in as 870 minutes (14.5 * 60) virtual unsigned computeArrivalTime(unsigned minute) const = 0; }; #endif Derived Classes...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int LABSIZE = 10; const int PROJSIZE = 3; const int EXAMSIZE = 3; float getAverage(float arr[], int size) { float total = 0; for (int i = 0; i < size; i++) { total += arr[i]; } return total/size; } // the following main function do.... int main() { ifstream dataIn; string headingLine; string firstName, lastName; float quiz[QUIZSIZE]; float lab[LABSIZE]; float project[PROJSIZE]; float midExam[EXAMSIZE];...
Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment...
Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment number, a number of bedrooms, and a rent value for an apartment. Upon construction, throw an ApartmentException if any of the following occur: • The apartment number does not consist of 3 digits • The number of bedrooms is less than 1 or more than 4 • The rent is less than $500.00 or over $2500 Write a driver class that demonstrates creating valid...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary string and iteratively constructs a decimal value (val) and width of each binary pattern (separated by spaces), until a space or a null character ('\0') is encountered in the string. Once a space or a null character is found, this function should call the assembly code (decode_morse()) to obtain the corresponding ASCII value, for the current val and width, and place the ASCII value...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int,...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int, int); }; class line{ private: point ps; point pe; public: void print()const; void setf(int, int, int, int); }; class rectangle{ private: line length[2]; line breadth[2]; public: void print()const; void setf(int, int, int, int, int, int, int, int); }; int main(){ rectangle r1; r1.setf(3,4,5,6, 7, 8, 9, 10); r1.print(); system("pause"); return 0; } a. Write function implementation of rectangle, line and point. b. What is...
Previous Lab Code files: PersonType.h: #include <string> using namespace std; class personType { public: void print()...
Previous Lab Code files: PersonType.h: #include <string> using namespace std; class personType { public: void print() const; void setName(string first, string middle, string last);    void setLastName(string last);    void setFirstName(string first);    void setMiddleName(string middle);    bool isLastName(string last) const;    bool isFirstName(string first) const; string getFirstName() const;    string getMiddleName() const;    string getLastName() const; personType(string first = "", string middle = "", string last = ""); private: string firstName; string middleName; string lastName; }; PersonTypeImp: #include <iostream>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT