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...
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...
#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];...
#ifndef CONTAINER_H #define CONTAINER_H using namespace std; class container { public: // CONSTRUCTOR container(); ~container(); container(const...
#ifndef CONTAINER_H #define CONTAINER_H using namespace std; class container { public: // CONSTRUCTOR container(); ~container(); container(const container& c); container& operator=(const container& c) // MEMBER FUNCTIONS bool lookup(const int& target); void remove(const int& target); void add(const int& target); private: struct node{ int key; node *next; }; node* head; node* tail; }; #endif For a linked list based implementation of a container class shown above, implement the constructor, copy constructor, destructor and copy assignment functions.
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...
C++ QUESTION ABOUT FIXING CODE AND RUNNING TESTS: class SpeakerSystem { public: void vibrateSpeakerCones(unsigned signal) const...
C++ QUESTION ABOUT FIXING CODE AND RUNNING TESTS: class SpeakerSystem { public: void vibrateSpeakerCones(unsigned signal) const { cout << "Playing: " << signal << "Hz sound..." << endl; cout << "Buzz, buzzy, buzzer, bzap!!!\n"; } }; class Amplifier { public: void attachSpeakers(const SpeakerSystem& spkrs) { if(attachedSpeakers) cout << "already have speakers attached!\n"; else attachedSpeakers = &spkrs; }    void detachSpeakers() { // should there be an "error" message if not attached? attachedSpeakers = nullptr; }    void playMusic( ) const...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string t, string a, double d); //parametrized constructor string getTitle()const; // return title string getAuthor()const; // return author double getDurationMin() const; // return duration in minutes double getDurationSec() const; // return song's duration in seconds void setTitle(string t); //set title to t void setAuthor(string a); //set author to a void setDurationMin(double d); //set durationMin to d private: string title; //title of the song string author;...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT