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.
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,...
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...
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...
7.24 LAB: Triangle area comparison (classes) Language: C++ Given class Triangle (in files Triangle.h and Triangle.cpp),...
7.24 LAB: Triangle area comparison (classes) Language: C++ Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant member functions. Ex: If the input is: 3.0 4.0 4.0 5.0 where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is: Triangle...
use c++ A right-angle triangle with integer sides a, b, c, such as 3, 4, 5,...
use c++ A right-angle triangle with integer sides a, b, c, such as 3, 4, 5, is called a Pythagorean triple. The condition is that hypotenuse to power of 2 is equal to adding of square of the 2 other sides. In this example 25 = 16 + 9. Use brute force approach to find all the triples such that no side is bigger than 50. For this you should first implement the following Triangle class and its methods. Then...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT