Write a C++ function display prototyped by int display(char ch, int n); that dis
ID: 3640970 • Letter: W
Question
Write a C++ function display prototyped byint display(char ch, int n);
that displays the character ch on the stdout device (screen) consecutively n times if n>0 and displays nothings if n=0. When n>0 and ch is not the blank character, the function will also display an additional newline at the end. The function display returns the actual number of characters (excluding the possible newline at the end) displayed.
Write a driver program, making use of the above specified function display, that line by line repeatedly display the character pattern
*
**
***
****
*****
******
*******
********
*********
**********
++++++++++
+++++++++
++++++++
+++++++
++++++
+++++
++++
+++
++
+
until a given nubmer of non-whitespace characters are displayed. In other words, the program will first ask the user to enter the total number, say target, of non-whitespace characters to be displayed, and then it will repeatedly display the above pattern until exactly target non-whitespace characters are displayed. For instance, if target is entered as 150, then the program will produce the following output (containing exactly 150 non-whitespace characters) afterwards:
*
**
***
****
*****
******
*******
********
*********
**********
++++++++++
+++++++++
++++++++
+++++++
++++++
+++++
++++
+++
++
+
*
**
***
****
*****
******
*******
********
****
Explanation / Answer
Hope this helps! Works perfectly. #include using namespace std; int display(char ch, int n) { if(n == 0) { return 0; } if(ch == ' ') { return 0; } while(1) //While there is still more to display... { for(int i = 0; i < 10; ++i) { for(int j = 0; jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.