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

Parallelogram Problem: Write a program that prints the outline of a parallelogra

ID: 3641546 • Letter: P

Question

Parallelogram Problem:

Write a program that prints the outline of a parallelogram (in this case a rectangle), where the width of the parallelogram is twice the height. The program will accept to inputs from the console, one will be the height (as an integer) and the other will be a character (as a char) that will represent the border.

Submit a solution that has two or less total repetition statements (loops).
Program output should look like below:

1)
What is the height of you parallelogram?
What character do you want to print?

$$$$$$$$$$$$
$ $
$ $
$ $
$ $
$$$$$$$$$$$$

2)
What is the height of you parallelogram?
What character do you want to print?

3)
What is the height of you parallelogram?
What character do you want to print?

++++++++++++++++++++++++++++++++++++++++
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
++++++++++++++++++++++++++++++++++++++++

4)
What is the height of you parallelogram?
What character do you want to print?

@@@@
@@@@

5)
What is the height of you parallelogram?
What character do you want to print?

!!

Explanation / Answer

1)

#include <iostream>

using namespace std;

int main() {

       int height = 0;

       char symbol;

       cout << "What is the height of you parallelogram? ";

       cin >> height;

       cout << "What character do you want to print? ";

       cin >> symbol;

       for(int i = 0; i < height; ++i) {

              for(int j = 0; j < height / 2; ++j) {

                     cout << symbol;

              }

              cout << endl;

       }

}



2) From the way you posted the question, it seems that the program is supposed to ask for the components but then prints nothing, so here it is:

#include <iostream>

using namespace std;

int main() {

       int height = 0;

       char symbol;

       cout << "What is the height of you parallelogram? ";

       cin >> height;

       cout << "What character do you want to print? ";

       cin >> symbol;

}

3)

#include <iostream>

using namespace std;

int main() {

       int height = 0;

       char symbol;

       cout << "What is the height of you parallelogram? ";

       cin >> height;

       cout << "What character do you want to print? ";

       cin >> symbol;

       for(int a = 0; a < height * 2; ++a) {

              cout << symbol;

       }

       cout << endl;

       for(int i = 0; i < height - 2; ++i) {

              cout << symbol;

              for(int j = 0; j < height * 2 - 2; ++j) {

                     cout << " ";

              }

              cout << symbol;

              cout << endl;

       }

       for(int b = 0; b < height * 2; ++b) {

              cout << symbol;

       }

       cout << endl;

}

4)

#include <iostream>

using namespace std;

int main() {

       int height = 0;

       char symbol;

       cout << "What is the height of you parallelogram? ";

       cin >> height;

       cout << "What character do you want to print? ";

       cin >> symbol;

       cout << endl;

       for(int i = 0; i < height; ++i) {

              for(int j = 0; j < height * 2; ++j) {

                     cout << symbol;

              }

              cout << endl;

       }

}

5)

#include <iostream>

using namespace std;

int main() {

       int height = 0;

       char symbol;

       cout << "What is the height of you parallelogram? ";

       cin >> height;

       cout << "What character do you want to print? ";

       cin >> symbol;

       cout << endl;

       for(int i = 0; i < height / 2; ++i) {

              for(int j = 0; j < height; ++j) {

                     cout << symbol;

              }

              cout << endl;

       }

}