Question

In: Computer Science

IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers...

IN C++ PLEASE

Requirements

Write a program that takes in user input of two integer numbers for height and width and uses a nested for loop to make a rectangle out of asterixes. The creation of the rectangle (i.e. the nested for loop) should occur in a void function that takes in 2 parameters, one for height and one for width. Make sure your couts match the sample output (copy and paste from those couts so you don't make a simple error). The Pre and Post condition should be a comment above the prototype; it should specify invalid input (there is no requirement for output on invalid input and it is not tested).

Rubric

-void function prototype, pre post comment, and definition matching prototype, and function called correctly 3 pts

-user input prompted and input accepted 2 pts

-correct bounds on the nested for loop 2 pts

-correct output 3 pts

Sample output (output in bold, input in nonbold):

What height do you want your rectangle?

5

What width do you want your rectangle?

5

*****

*****

*****

*****

*****

What height do you want your rectangle?

3

What width do you want your rectangle?

10

**********

**********

**********

What height do you want your rectangle?

6

What width do you want your rectangle?

2

**

**

**

**

**

**

What height do you want your rectangle?

10

What width do you want your rectangle?

7

*******

*******

*******

*******

*******

*******

*******

*******

*******

*******

Solutions

Expert Solution

/*program that creates a rectangle using asterixes(*) of the

size as input from the user*/

#include<iostream>

using namespace std;

/*function prototype or function declaration

two parameters are passed height and width which are of

integer type and the return type of the function is void*/

void rectangle(int ,int ); //function declaration

int main()

{

//declration of two variables which will be passed as parameter

int height,width;

cout<<"What height do you want your rectangle?"<<endl;

//taking user input for the height of rectangle required

cin>>height;

cout<<"What width do you want your rectangle?"<<endl;

//taking user input for the width of rectangle required

cin>>width;

//function call two parameters height and width is passed

rectangle(height,width);

return 0;

}

/*function defination

pre and post comments if the parameters passed to the function

is not of the type integer than the input will be considered as

a invalid input like the passed parameter shoul not be of type

float or char or double it must be of type integer

the function will behave properly if the passed parameter is

of type integer else not*/

//in these function height and width is passes as paramter

//which is type int and return type of funcion is void

void rectangle(int h,int w)

{

//outer loop will extecute till i is less than height

for(int i=0;i<h;i++)

{

//this loop will execute till j is less than width

for(int j=0;j<w;j++)

{

cout<<"*";

}

cout<<endl;

}

}

//If have any doubt please ask through comments.

//Please give a review if your doubt was cleared.Thank You.

//Thank you.

//Screen Shots

//Outputs


Related Solutions

Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
Write a program to find the prime numbers IN JAVA Ask user to input the integer...
Write a program to find the prime numbers IN JAVA Ask user to input the integer number test the number whether it is a prime number or not Then, print “true” or “false” depending on whether the number is prime or isn’t. Hint: number is prime when is has exactly 2 factors: one and itself. By this definition, number 1 is a special case and is NOT a prime. Use idea of user input, cumulative sum, and loop to solve...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Please code C# 8. Write a program that prompts the user to enter an integer. The...
Please code C# 8. Write a program that prompts the user to enter an integer. The program then determines and displays the following: Whether the integer is divisible by 5 and 6 Whether the integer is divisible by 5 or 6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT