Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions