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
* * *
* * *
#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;
}
Comments
Leave a comment