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

Write a program that takes two lists of 5 positive integers each, and place them

ID: 3695805 • Letter: W

Question

Write a program that takes two lists of 5 positive integers each, and place them in two arrays called "rowList" and "columnList". Afterwards, generate 5 rectangles of asterisks, each with dimensions taken from the previous two arrays provided. The 1st elements of "rowList" and "columnList" would generate the first rectangle, the 2nd elements of "rowList" and "columnList" would generate the second rectangle, and so on. The input values for "rowList" and "columnList" should only be between 2 and 7. The program must implement and use a function called "printRectangle", which takes two input parameters (one for row numbers, and one for column numbers), and generates a rectangle with the dimension specified by the parameters (row and column). The program must be run with 3, 7, -2, 5, 4, 4, 9, 7, 6, 2, 4, 2 input and the output matching the sampe run below.

SAMPLE RUN:

Enter 5 positive integers for rowList (2 to 7)

0: 3

1: 7

2: -2 Rejected!

2: 5

3: 4

4: 4

Enter 5 positive integers for columnList (2 to 7)

0: 9 Rejected!

0: 7

1: 6

2: 2

3: 4

4: 2

Rectangles generated

3 rows 7 columns

*******

*******

*******

7 rows 6 columns

******

******

******

******

******

******

******

5 rows 2 columns

**

**

**

**

**

4 rows 4 columns

****

****

****

****

4 rows 2 columns

**

**

**

**

NOTE: DO NOT USE GLOBAL VARIABLES!!!!!

Explanation / Answer

#include<iostream>

usingnamespacestd;

voidprintRectangle(int width, int height) {

       int rows = 0;

       int cols = 0;

       while (rows < height) {

              cols = 0;

              while (cols < width) {

                     cols = (cols + 1);

                     cout<<"*";

              }

              rows = (rows + 1);

              cout<<endl;

       }

}       

int main() {

       introwList[5];

       intcolumnList[5];

       intcurrentBox = 0;

       inttotalBoxes = 5;

       cout<<"Enter 5 positive integers for rowList (2 to 7)"<<endl;

       while (currentBox<totalBoxes) {

              cout<<currentBox<<": ";

              cin>>rowList[currentBox];

              while ((rowList[currentBox] < 2) || (rowList[currentBox] > 7)) {

                     cout<<" Rejected!"<<endl;

                     cout<<currentBox<<": ";

                     cin>>rowList[currentBox];

              }

              currentBox = (currentBox + 1);

       }

       cout<<endl;

       currentBox = 0;

       cout<<"Enter 5 positive integers for columnList (2 to 7)"<<endl;

       while (currentBox<totalBoxes) {

              cout<<currentBox<<": ";

              cin>>columnList[currentBox];

              while ((columnList[currentBox] < 2) || (columnList[currentBox] > 7)) {

                     cout<<" Rejected!"<<endl;

                     cout<<currentBox<<": ";

                     cin>>columnList[currentBox];

              }

              currentBox = (currentBox + 1);

       }

       cout<<endl;

       currentBox = 0;

       while (currentBox<totalBoxes) {

              cout<<rowList[currentBox] <<" rows "<<columnList[currentBox] <<" columns"<<endl;

              printRectangle(columnList[currentBox], rowList[currentBox]);

              cout<<endl<<endl;

              currentBox = (currentBox + 1);

       }

       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