Question

2. Overload a function "display" so that (a) if display is called with a string, it...


2. Overload a function "display" so that
(a) if display is called with a string, it prints the string 5 times and then returns the length of the string
(b) if it is called with an integer, n, it prints n, 2n, 3n and has no return value
(c) if it is called with a character, it prints the character on the first line, 2 of the character on the 2nd line, 3 of it on the 3rd line and returns its ASCII value

c++ language
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
int display(string s)
{
for(int i=0;i<5;i++)
{
cout<<s<<endl;
}
return s.length();
}
void display(int n)
{
cout<<n<<endl;
cout<<2*n<<endl;
cout<<3*n<<endl;
  
}
int display(char c)
{
cout<<c<<endl;
cout<<c<<c<<endl;
cout<<c<<c<<c<<endl;
return (int)(c);
}
int main()
{

display("hjfs");
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
2. Overload a function "display" so that (a) if display is called with a string, it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT