Question

In: Computer Science

4.24 LAB*: Program: Drawing a half arrow This program outputs a downwards facing arrow composed of...

4.24 LAB*: Program: Drawing a half arrow

This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width.

(1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt)

(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base. (1 pt)

(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head. (2 pts)

(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt)

while (arrowHeadWidth <= arrowBaseWidth) {
    // Prompt user for a valid arrow head value
}

Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:

Enter arrow base height:
5
Enter arrow base width:
2
Enter arrow head width:
4

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

Solutions

Expert Solution

Code as it is not mentioned in which programming language is to be done so I coded in C++ language. And it is self explanatory in itself and for more clarification comments have been added.

CODE:

#include <iostream>
using namespace std;

int main() {
   // your code goes here
   int arrowBaseHeight, arrowBaseWidth, arrowHeadWidth;
   cout<<"Enter arrow base height:";
   cin>>arrowBaseHeight;
   cout<<"Enter arrow base width:";
   cin>>arrowBaseWidth;
   cout<<"Enter arrow head width:";
   cin>>arrowHeadWidth;
   cout<<endl;
   //prompting user until arrow head width is greater than arrow base width
   while (arrowHeadWidth <= arrowBaseWidth) {
       cout<<"Please enter arrow head width greater than arrow base width :";
       cin>>arrowHeadWidth;
   }
   for(int i=0;i<arrowBaseHeight;i++){
       for(int j=0;j<arrowBaseWidth;j++){
           cout<<"*";
       }
       cout<<endl;
   }
   for(int i=arrowHeadWidth;i>0;i--){
       for(int j=0;j<i;j++){
           cout<<"*";
       }
       cout<<endl;
   }
   return 0;
}

OUTPUT:

Enter arrow base height:5                                                                                                                       

Enter arrow base width:2                                                                                                                        

Enter arrow head width:4                                                                                                                        

                                                                                                                                                

**                                                                                                                                              

**                                                                                                                                              

**                                                                                                                                              

**                                                                                                                                              

**                                                                                                                                              

****                                                                                                                                            

***                                                                                                                                             

**                                                                                                                                              

*                                                                                                                                               

                                                                                                                                                

                                                                                                                                                

...Program finished with exit code 0                                                                                                            

Press ENTER to exit console.   


Related Solutions

17.18 LAB 8A: Input and formatted output: Left-facing arrow You will be working on generating a...
17.18 LAB 8A: Input and formatted output: Left-facing arrow You will be working on generating a formatted output using characters such as *, #, -, +. You need to prompt the user for a character for the arrowhead, and a character for the arrow body, and then print a left-facing arrow. Your prompts should be exactly "Enter a character for the arrowhead:" and "Enter a character for the arrow body:", as shown below. Ex: If the user inputs a *...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT