Answer to Question #220508 in C++ for Faizee

Question #220508

A point on a two-dimensional space has two numbers: an ‘X’ coordinate and a ‘Y’

coordinate such as (4, 5). Write a program that uses a structure called ‘point’ to model a

point and draw a rectangle of ‘*’ based on the entered height and width of the rectangle.

Sample Run:

Enter the point coordinates: (x, y)

3 2

Enter width of the rectangle: 3

Enter Height of the rectangle: 2

* * *

* * *


1
Expert's answer
2021-07-25T13:17:56-0400
#include <iostream>
#include <string>
using namespace std;


struct point{
	int x;
	int y;
};
int main(){
	struct point newPoint;
	int width;
	int height;
	newPoint.x;
	newPoint.y;
	cout<<"Enter the point coordinates: (x, y)\n";
	cin>>newPoint.x>>newPoint.y;
	cout<<"Enter width of the rectangle: ";
	cin>>width;
	cout<<"Enter height of the rectangle: ";
	cin>>height;
	newPoint.x--;
	newPoint.y--;
	for(int y=0;y<newPoint.y;y++){
		cout<<"\n";
	}
	for(int y=0;y<height;y++){
		for(int x=0;x<newPoint.x;x++){
			cout<<" ";
		}
		for(int x=0;x<width;x++){
			cout<<"*";
		}
		cout<<"\n";
	}


	int pause;
	cin>>pause;
	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS