Im c This program outputs a downwards facing arrow composed

I\'m c++
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. (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) the given program to use a loop to output an arrow head of width arrowHead 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 s larger than the arrow base width. Use a loop to continue prompting the user the arrow base width. (1 pt)

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files
#include <string>

using namespace std;

int main() // driver method
{
   int arrowBaseHeight = 0; // required initialisations
   int arrowBaseWidth = 0;
   int arrowHeadWidth = 0;
   int i = 0;

   cout << \"Please Enter the desired arrow base height: \"; // prompt to enter the data
   cin >> arrowBaseHeight; // getting the data

   cout << \"Please Enter the desired arrow base width: \"; // prompt to enter the data
   cin >> arrowBaseWidth; // getting the data

   while (arrowHeadWidth <= arrowBaseWidth) { // checking for the condition
       cout << \"Please Enter the desired arrow head width: \"; // prompt to enter the data
       cin >> arrowHeadWidth; // getting the data
   }

   string ast = \"\"; // ast will contain how many asterisk we want for the base width;

   int tempBaseHeight = arrowBaseWidth; // temporary variable
   for (int x = 1; x <= arrowBaseHeight; x++) //iterating to form the base width of the arrow
   {
       for(int y = 1; y <= tempBaseHeight; y++)
       {
           cout << \"*\"; // printing the asterisks
       }
       cout << endl;
   }

   for (i = 1; i <= arrowBaseHeight; i++)
   {   
       cout << ast; //Printing the base width
   }

   int tempHeadWidth = arrowHeadWidth;
   for (int y = 1; y <= arrowHeadWidth; y++)
   {
       for(int z = tempHeadWidth; z > 0; z--) // iterating to print the number of asterisks we need per line in the arrowHead
       {
           cout << \"*\";
       }
       tempHeadWidth -= 1; // decrementing the value to run the code till the head width

       cout << endl; // it makes a new line to keep adding more asterisks for the next row
   }
}


OUTPUT :

CASE 1 :

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


CASE 2 :

Enter arrow base height: 5
Enter arrow base width: 3
Enter arrow head width: 1
Enter arrow head width: 2
Enter arrow head width: 3
Enter arrow head width: 4
***
***
***
***
***
****
***
**
*


Hope this is helpful.

I\'m c++ This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow ba
I\'m c++ This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow ba

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site