Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program that does the following: 1. The program asks user t

ID: 645708 • Letter: W

Question

Write a complete C++ program that does the following:

1. The program asks user to enter a positive integer n < 10. If the input value is incorrect, the program repeatedly force user to input value until n is within the expected value.

2. The program then invoke (calls) function fun1( ) that does the following :

i. The heading of the function is void fun1(int n)

ii. The function prints a square with n rows and n columns using the letter X on or above the main diagonal and the letter O below it. For example, if the user enters 4 for n the output is as follows:

XXXX

OXXX

OOXX

OOOX

Explanation / Answer

#include <iostream>

using namespace std;

intmain()

{

intn;

cout<< "Enter a positive integer n:";

cin>> n;

if (n <= 0) return 0;

for (int r = 1; r <= n; r++)

{

for (intc = 1; c <= n; c++)

if (c < r) cout<< "O";

else cout<< "X";

cout<< endl;

}return 0;}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote