Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago