In this lab, we will have more practice on programming C++ with while loop, nest
ID: 3852069 • Letter: I
Question
In this lab, we will have more practice on programming C++ with while loop, nested while loop and user defined functions. Develop two programs for the following two tasks Programming Problem One Write a C++ program, named draw.cc, that 1. Reads in from user two pieces of information: 1. the height of a triangle to draw, and 2. the character used to draw the triangle and 2. 2. Draws the one right triangle of the 'height" given in the "character" entered, and another right triangle that flips vertically from the first trianlge First, create a director "CLASB" under the "CLA" directory. Use "cd" command to change directory to the "CLA5B" directory. Use scite to write the program named draw.cc. $scite draw.cc & Compile the program with $aCc draw.cc Programming Requirements void function "GetUserinput" will prompt the user to get the two pieces of information. The input entered by user should be sent back to the calling function using the parameters passed by reference void function "DrawTriangle" will draw the triangle based on the user input values Here are example runs of the program. The output of the program should look like this:Explanation / Answer
#include <iostream>
using namespace std;
void GetUserInputs(int &height, char &symbol) {
cout<<"Enter the height of the triangle to draw: ";
cin >> height;
cout<<"Enter the character to be used for drawing the triangle: ";
cin >> symbol;
}
void DrawTriangle(int height, char symbol) {
int i=1;
while(i<=height) {
int j=1;
while(j<=i){
cout<<symbol;
j++;
}
cout<<endl;
i++;
}
i=height;
while(i>0) {
int j=1;
while(j<=i){
cout<<symbol;
j++;
}
cout<<endl;
i--;
}
}
int main()
{
int height;
char symbol;
GetUserInputs(height, symbol);
DrawTriangle(height, symbol);
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the height of the triangle to draw: 5
Enter the character to be used for drawing the triangle: $
$
$$
$$$
$$$$
$$$$$
$$$$$
$$$$
$$$
$$
$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.