In: Computer Science
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
*******
*******
*******
*******
*******
*******
*******
*******
*******
*******
/*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