Question: C + + Define a default constructor that initializes the data members, integer areaCode, integer number, and string name, with the default values - 1

C++
Define a default constructor that initializes the data members, integer areaCode, integer number, and string name, with the default
values -1,1, and "Unknown", respectively.
Ex: If the input is 5859327263 Ken, then the output is:
Area code: -1, Number: 1, Name: Unknown
Area code: 585, Number: 9327263, Name: Ken
Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.
Define a default constructor that initializes the data members, integer areaCode, integer number, and string name, with the default values -1,1, and "Unknown", respectively.
Ex: If the input is 5859327263 Ken, then the output is:
Area code: -1, Number: 1, Name: Unknown
Area code: 585, Number: 9327263, Name: Ken
Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.
#include
#include
using namespace std;
class Message {
public:
Message();
void SetAreaCode(int messageAreaCode);
void SetNumber(int messageNumber);
void SetName(string messageName);
void Print();
private:
int areaCode;
int number;
string name;
};
/* Your code goes here */
void Message::SetAreaCode(int messageAreaCode){
areaCode = messageAreaCode;
}
void Message::SetNumber(int messageNumber){
number = messageNumber;
}
void Message::SetName(string messageName){
name = messageName;
}
void Message::Print(){
cout "Area code: " areaCode ", Number: " number ", Name: " name endl;
}
int main(){
int newAreaCode;
int newNumber;
string newName;
Message myMessage;
myMessage.Print();
cin >> newAreaCode;
cin >> newNumber;
cin >> newName;
myMessage.SetAreaCode(newAreaCode);
myMessage.SetNumber(newNumber);
myMessage.SetName(newName);
myMessage.Print();
return 0;
}
C + + Define a default constructor that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!