Question
C++
Hey, I really need help with this lab. I don't understand the function part at all. It'll be great way for me to understand. Than you

Functions and loops: Write a program that will ask the user which type of triangle they would like to draw on the characters. The choices are screen with left-top-big left-bottom-big right-top-big right-bottom-big Get the users choice, ask how big it should be, and then draw the shape. After each successful drawing, ask the user if they would like to draw another one. Continue until they choose not to draw any more. All of the major tasks should be done in tunctions (7 in total The main program should only have a loop, a decision structure based on the menu choice and function calls. The following functions will be required (names can vary): menu0-ask the user for a number between 1 and 4 and read in their response. If their answer is anything outside the desired range, write out an error message and repeat the input. Return the legal integer menu choice. getsize0 ask the user for the maximum number of characters in the shape. The response must be an integer that is in the range of 1-10. If any input is outside this range, write an error message and have the user repeat the input untilavalid input is received. Return the legal integer size value. getRepeatChoice0 ask the user if they would like to draw another shape. Read their response into a char variable. their response is anything other than Y or N (upper or lower case) write outan emor and read in a new response until or N is found. Return the char response. leftTopBig0 receives the maximum size as a parameter and draws the specified shape. Returns nothing. leftBotBig0 receives the maximum size as a parameter and draws the specified shape. Returns nothing. rightTopBig0-receives the maximum size as a parameter and draws the specified Returns nothing. rightBotBig0 receives the maximum size as a parameter and draws the specified Returns nothing. Each function must be written with aprototype before the main program and a definition after the main program. name block comment before each function definition stating what it does. The following is a complete example of a sample run including error detection Which triangle do you want to draw? Left-Top-B Left Bottom-Big Big 4 Right-Bottom-Big
media%2F785%2F785fd90c-3f18-4b17-8123-f7
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for you:

#include <iostream>
using namespace std;
int menu()
{
cout<<"Which triangle do you want to draw?"<<endl;
cout<<"1 - Left-Top-Big"<<endl;
cout<<"2 - Left-Bottom-Big"<<endl;
cout<<"3 - Right-Top-Big"<<endl;
cout<<"4 - Right-Bottom-Big"<<endl<<endl;
int choice;
cin>>choice;
while(choice < 1 || choice > 4)
{
cout<<"Illegal choice, try again: ";
cin>>choice;
}
return choice;
}
int getSize()
{
cout<<"Please enter the maximum size (1-10): ";
int size;
cin>>size;
while(size < 1 || size > 10)
{
cout<<"size must be in range of 1 - 10, try again: ";
cin>>size;
}
return size;
}
char getRepeatChoice()
{
cout<<"Draw another? (Y/N) ";
char another;
cin>>another;
while(another != 'y' && another != 'Y' && another != 'n' && another != 'N')
{
cout<<"Please enter Y for yes or N for no: ";
cin>>another;
}
return another;
}
void leftTopBig(int max)
{
for(int i = 0; i < max; i++)
{
for(int j = 0; j < max-i; j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
void leftBotBig(int max)
{
for(int i = 0; i < max; i++)
{
for(int j = 0; j <= i; j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
void rightTopBig(int max)
{
for(int i = 0; i < max; i++)
{
for(int j = 0; j < i; j++)
cout<<" ";
for(int j = 0; j < max-i; j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
void rightBotBig(int max)
{
for(int i = 0; i < max; i++)
{
for(int j = 0; j < max-i-1; j++)
cout<<" ";
for(int j = 0; j <= i; j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
int main()
{
while(true)
{
int choice = menu();
int size = getSize();
switch(choice)
{
case 1:   leftTopBig(size); break;
case 2:   leftBotBig(size); break;
case 3:   rightTopBig(size); break;
case 4:   rightBotBig(size); break;
}
char again = getRepeatChoice();
if(again == 'n' || again == 'N')
return 0;
}
}

And the output screenshot is:

@ 1.05 GB曰 。 () 丶令 ー 《 Terminal Shell Edit View Window Help イ 4) 99% E帼. Tue 14 Feb 02:38 ANANDA KUMAR THUMMAPUDI HomeworkLibCPP_-b

Add a comment
Know the answer?
Add Answer to:
C++ Hey, I really need help with this lab. I don't understand the function part at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • (Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by...

    (Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by the user. You will ask the user for the number of rows then number of columns, and generate an HTML table of the appropriate size. The top left cell should contain the result of 1 x 1, and the bottom right cell should contain the result of num_rows x num_cols. Each row and column may be an integer value between 1 and 12 inclusive...

  • Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to...

    Using C++ language please not matlab a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...

  • Hi I need help doing this problem *The program must re-prompt as long as invalid input...

    Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...

  • Can you send the code and the screenshot of it running? 1) Create a PYHW2 document...

    Can you send the code and the screenshot of it running? 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both flowchart and pseudocode forms for the following two functions: A. Write a Python function that receives a real number argument representing the sales amount for videos rented so far this month The function asks the user for the number...

  • In C++ Write a function that receives an integer array with its size and determines whether...

    In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.

  • In C++ Write a function that receives an integer array with its size and determines whether...

    In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Hi. Could you help me write the below program? Please don't use any header other than...

    Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT