Question

In: Computer Science

This is a straightforward program that will "draw" a rectangle using any character selected by the...

This is a straightforward program that will "draw" a rectangle using any character selected by the user. The user will also provide the width and height of the final rectangle. Use a nested for loop structure to create the output.

Input:

This program will draw a rectangle using your character of choice.
Enter any character: [user types: *]

Enter the width of your rectangle: [user types: 20]

Enter the height of your rectangle: [user types: 5]

Output:

********************
********************
********************
********************
********************

Notes and Hints:

1) You MUST use a nested For Loop in your solution

Starter Code:

// VARIABLES
  

// INPUT
std::cout << "This program will draw a rectangle using your character of choice.\n";
std::cout << "Enter any character: ";

std::cout << std::endl;

std::cout << "Enter the width of your rectangle: ";

std::cout << std::endl;

std::cout << "Enter the height of your rectangle: ";
  
  
std::cout << std::endl;

// DRAW RECTANGLE WITH NESTED LOOP

std::cout << YOUR_CODE;

std::cout << std::endl; // Creates new row after inner loop finishes all columns in the current row

Solutions

Expert Solution

Code:

// Online C++ compiler to run C++ program online
#include <iostream>

int main() {

// VARIABLES
    int width;
    int height;
    char ch;
    // INPUT
     std::cout << "This program will draw a rectangle using your character of choice.\n"; 
     std::cout << "Enter any character: ";
     std::cin>>ch;
     std::cout << std::endl;

     std::cout << "Enter the width of your rectangle: ";
     std::cin>>width;

     std::cout << std::endl;

     std::cout << "Enter the height of your rectangle: ";
     std::cin>>height;
  
     std::cout << std::endl;

    // DRAW RECTANGLE WITH NESTED LOOP
    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++ )
        {
            std:: cout<<ch;
        }
        std::cout << std::endl; // Creates new row after inner loop finishes all columns in the current row
    }

    return 0;
}

Screenshots:


Related Solutions

using C# Write a program named RectangleArea tocalculate the area of a rectangle with a...
using C# Write a program named RectangleArea to calculate the area of a rectangle with a length of 15.8 and a width of 7.9. The program should have two classes, one is theRectangleArea holding the Main(), and the other one is Rectangle. The Rectangleclass has three members: a property of length, a property of width, and a method with a name of CalArea() to calculate the area. You can invoke the auto-provided constructor or write a self-defined constructor to initialize...
Using the program below, overload the Multiply operator to the Rectangle class… this will multiple the...
Using the program below, overload the Multiply operator to the Rectangle class… this will multiple the widths for the 2 Rectangles and multiple the lengths of the two rectangles (similar to how the “+” operator added the widths and lengths of the 2 rectangles). Overload this operator using the non-member method. Please copy-paste code into MS Word document and then show some screenshots of you running and testing this method using your IDE. Using the program below, overload the Divide...
To begin, write a program to loop through a string character by character. If the character...
To begin, write a program to loop through a string character by character. If the character is a letter, print a question mark, otherwise print the character. Use the code below for the message string. This will be the first string that you will decode. Use the String class method .charAt(index) and the Character class method .isLetter(char). (You can cut and paste this line into your program.) String msg = "FIG PKWC OIE GJJCDVKLC MCVDFJEHIY BIDRHYO.\n"; String decryptKey = "QWERTYUIOPASDFGHJKLZXCVBNM";...
using any form of induction, that a binary string begins and ends with the same character...
using any form of induction, that a binary string begins and ends with the same character iff contains an even number of occurences of substrings from (01,10).
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
Write a program that will print out “W” using a character that a user provides. use...
Write a program that will print out “W” using a character that a user provides. use for loop statement. in java please
Show using the C4v point group character table the orthogonality of any two irreducible representations. Using...
Show using the C4v point group character table the orthogonality of any two irreducible representations. Using the same point group demonstrate the property of the character table that two irreducible representations can be used to deduce the characters for another (ex combinations of the irreducible representations for px and py can be used to determine the characters for the irreducible representation of dxy)
Using python: Given a string x, write a program to check if its first character is...
Using python: Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True"
Write a program that displays a single character at 100 random screen locations, using a timing...
Write a program that displays a single character at 100 random screen locations, using a timing delay of 100 milliseconds. Hint: Use the GetMaxXY procedure to determine the current size of the console window. How to code this program with a defined character 'A' (I do not want to write a character to get a single character in the output console)
Draw ? on a torus (or the schematic representation where opposite sides of a rectangle are...
Draw ? on a torus (or the schematic representation where opposite sides of a rectangle are identified.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT