Question: Create a new C++ project. Call OverloadedFunctionsDemo. Add standard includes and main function: #include #include using namespace std; int main() { return 0; } Add

  1. Create a new C++ project. Call OverloadedFunctionsDemo.
  2. Add standard includes and main function:

#include

#include

using namespace std;

int main()

{

return 0;

}

  1. Add Some Overloaded Functions
    1. Add the following functions:

void SayGoodnight()

{

cout << "Good night!" << endl;

}

void SayGoodnight(string name1)

{

cout << "Good night " << name1 << "!" << endl;

}

void SayGoodnight(string name1, string name2)

{

cout << "Good " << name1 << " and " << name2 << "!" << endl;

}

void SayGoodnight(int number)

{

for (int i = 0; i < number; ++i)

{

cout << "Good night! " << endl;

}

}

  1. Add function prototypes at top of program:

void SayGoodnight();

void SayGoodnight(string name1);

void SayGoodnight(string name1, string name2);

void SayGoodnight(int number);

  1. Call functions from main:
    1. Call the parameterless function:

SayGoodnight();

  1. Run with ctrl-F5
  2. Add a call to the one parameter function:

string name;

getline(cin, name);

SayGoodnight(name);

  1. Run with ctrl-F5
  2. Add a call to the two parameter function:

cout << "Name one: ";

string nameFirst;

getline(cin, nameFirst);

cout << "Name second: ";

string nameSecond;

getline(cin, nameSecond);

SayGoodnight(nameFirst,nameSecond);

  1. Run with ctrl-F5
  2. Add a call to the function that takes one int parameter:

cout << "Number: ";

int number;

cin >> number;

SayGoodnight(number);

  1. Run with ctrl-F5

Question: How does C++ differentiate between SayGoodnight(name); and SayGoodnight(number);?

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 Databases Questions!