Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question about my C++ code. It is saying identifier x and y are undefined under //Cleanup Memory. Also visual studios has a problem with my

Question about my C++ code. It is saying identifier "x" and "y" are undefined under //Cleanup Memory. Also visual studios has a problem with my closing } bracket. The error about the } bracket says expected a ';' but not sure why.

Code:

#include #include #include "graph1.h"

using namespace std;

//Protoypes int getNoObjects(); int* getXCoords(int no_objects); int* getYCoords(int no_objects); void displayObjects(int* x_coords, int* y_coords, int no_objects);

int main() { //Variable Declaration/Initialization int no_objects = 0; int* x_coords = NULL; int* y_coords = NULL;

//Initialize seed srand(time(0));

//Display graphics displayGraphics();

//1. Get the number of objects to be displayed no_objects = getNoObjects();

//2. Generate the x-coords for each object x_coords = getXCoords(no_objects);

//3. Generate the y-coords for each object y_coords = getYCoords(no_objects);

//4. Display the objects at the randomly generated coordinates void displayObjects(int* x_coords, int* y_coords, int no_objects);

//Cleanup memory delete[] x; delete[] y;

return 0; }

//Implement functions below int getNoObjects() { //Variable declaration/initialization int no_objects = 0;

//Prompt for # objects should be between 2 and 30 inclusive //Perform data validation cout << "";

return no_objects;

}

int* getXCoords(int no_objects) { //Variable declaration/initialization int i = 0;

//Dynamically allocate the array for x-coords int* x = new int[no_objects];

//Generates x-coords for each object randomly rand() % 601;

}

int* getYCoords(int no_objects) { //Variable declaration/initialization int i = 0; int* y = NULL;

//Dynamically allocate the array for y-coords y = new int[no_objects];

//Generates y-coords for each object randomly

}

void displayObjects(int* x_coords, int* y_coords, int no_objects) { //Variable declaration/initialization int i = 0; int* y = NULL;

//Display all objects at x/y random positions stored in x_coords/y_coords if (i % 2 == 0) displayPNG("even.PNG", x_coords[i], y_coords[i])

}

i was able to fix it

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_2

Step: 3

blur-text-image_3

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions