Answer to Question #320805 in C++ for Magisk

Question #320805



Your task is to define the sendApology() function with the following details:




a. Return type - void




b. Function name - sendApology




c. Parameters - a character and an integer.




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).




Do not edit the main() code.





This is the given code:





#include <iostream>




using namespace std;





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-30T02:51:15-0400
#include<iostream>

using namespace std;

void sendApology(char letter, int n);

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;
		}
		cout << endl;
	}
}

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