Question

In: Computer Science

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 % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches triangleHeight. Output a space after each user-specified character, including after the line's last user-specified character. (2 pts)

Example output for triangleChar = % and triangleHeight = 5:

Enter a character:
%
Enter triangle height:
5

% 
% % 
% % % 
% % % % 
% % % % % 

Solutions

Expert Solution

#include<iostream>
using namespace std;

int main()
{
   char ch;
   int n;
   //promtpt the user to enter a character
   cout<<"Enter a character:\n";
   cin>>ch;
   //prompt the user to enter triangle height
   cout<<"Enter triangle height:\n";
   cin>>n;
   //iterate until n
   for(int i = 1; i <= n;i++)
   {
       //for each value
       //print i number of character seperated by space
       for(int j = 1;j <= i;j++)
       {
           cout<<ch<<" ";
       }
       //print a newline
       cout<<endl;
   }

return 0;
}


Related Solutions

write a java program for area and perimeter of right triangle
write a java program for area and perimeter of right triangle
Find a b c of a right triangle. with a perimeter of 18.
Find a b c of a right triangle. with a perimeter of 18.
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides....
Assignment: Write an interactive C++·program to determine a type of a triangle based on three sides. Have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a...
a) The triangle △ ABC is right-angled with right angle at corner C and angle α...
a) The triangle △ ABC is right-angled with right angle at corner C and angle α at corner A. Calculate a = | BC |, given that c = | AB | = 8, and that tan α = 12. Calculate a= ? b) In the triangle △ ABC before the designations a = | BC |, b = | CA |, c = | AB |, and ∠A = α, ∠B = β and ∠C = γ. Find c,...
Write in c++ as simple as possible In a right triangle, the square of the length...
Write in c++ as simple as possible In a right triangle, the square of the length on one side is equal to the sum of the squares of the lengths of the other two sides.  Write a program that prompts the user to enter the length of three sides of the tringle (as doubles) and the outputs a message indication whether the triangle is a right triangle.  You should split this into two functions (but only one .cpp file).  One function is main()...
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...
Find the lengths of the arms of a right triangle whose hypotenuse has length c if...
Find the lengths of the arms of a right triangle whose hypotenuse has length c if these arms have a ratio of (a) 3;4 and c=15, (b) 5;12 and c=26, (c) 8;15 and c =170 and (d) 1;2 and c=10
ABC is an isoceles right-angled triangle in which ∠A = 90°. Find ∠B and ∠C.
ABC is an isoceles right-angled triangle in which ∠A = 90°. Find ∠B and ∠C.
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle,...
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. If the triangle is a right triangle, output It is...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT