Question
Write a C++ program that processes information for rectangles, functions required. The program should perform the following: 1. Prompt the user for the number of
Write a C++ program that processes information for rectangles, functions required. The program should perform the following:
1. Prompt the user for the number of rectangles to process
2. Prompt the user for the x coordinates for each rectangle
3. Prompt the user for the y coordinates for each rectangle.
4. Return dynamically allocated arrays for the x/y coordinates from corresponding functions
Example prompts for this data are shown below:
1.# of rectangles to process
(Enter # of boxes: 5)
2.x-coord data entered for each box
(Enter # of boxes: 5
Enter x-coord for box# 1: 100
Enter x-coord for box# 2: 200
Enter x-coord for box# 3: 300
Enter x-coord for box# 4: 400
Enter x-coord for box# 5: 500)
3.y-coord data entered for each box
(Enter y-coord for box# 1: 100
Enter y-coord for box# 2: 200
Enter y-coord for box# 3: 300
Enter y-coord for box# 4: 400
Enter y-coord for box# 5: 500)
The first prompt is implemented from the
void getData(int* no_rects);
The function call in main for getData is shown below:
getData(&no_rects);
Where the declaration in main for no_rects is as follows:
int no_rects = 0;
The second set of prompts is implemented from
int* getXCoords(int no_rects);
And a dynamically allocated array of integers containing the x-coord for each rectangle is returned.
The third set of prompts is implemented from
int* getYCoords(int no_rects);
And a dynamically allocated array of integers containing the y-coord for each rectangle is returned.
4. Display the rectangles with rgb color (255,0,0) at their x/y coordinate. The width for each rectangle is 50 while the height is 25. Each even numbered box is displayed as red. Each odd numbered block is displayed as blue.
The function that displays the rectangles is shown below:
void displayRectangles(int no_rects, int* x, int* y);
Where no_rects is the total number of rectangles to display, x is the dynamically allocated array containing the x-coords, and y is the dynamically allocated array containing the y-coords.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started