Answer to Question #306401 in C++ for mark

Question #306401


  1. Your task is to define the sendApology() function with the following details:
  2. Return type - void
  3. Function name - sendApology
  4. Parameters - a character and an integer.
  5. The sendApology() function will first check if the character passed is either 's', 'o', 'r', or 'y'. If it is, print it based on the passed integer number of times. For example, if the passed integer is 5, then you need to print the character 5 times. Otherwise, just ignore it (i.e. don't do anything).

OUTPUT

sooorrrrrrrrryyyyy

Given Code Editor:

#include <iostream>

using namespace std;

void sendApology(char, int);

int main(void) {

sendApology('s', 2);

sendApology('f', 10);

sendApology('b', 3);

sendApology('o', 5);

sendApology('r', 12);

sendApology('m', 5);

sendApology('v', 2);

sendApology('y', 7);

 return 0;

}

void sendApology(char letter, int n) {

  // TODO: Implement the function definition  

}


1
Expert's answer
2022-03-05T13:02:20-0500
#include <iostream>

using namespace std;
void sendApology(char, int);

int main(void)
{
  sendApology('s', 2);
  sendApology('f', 10);
  sendApology('b', 3);
  sendApology('o', 5);
  sendApology('r', 12);
  sendApology('m', 5);
  sendApology('v', 2);
  sendApology('y', 7);
  return 0;
}

void sendApology(char letter, int n) {
  if (letter == 's' || letter == 'o' 
    || letter == 'r' || letter == 'y') {
    for (int i = 0; i < n; i++) {
      cout << letter;
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog