﻿ Hmwk 3

## Homework 3 - Rosettes

A rosette is formed by drawing a line from each vertex of a regular polygon to every other vertex. Here is a rosette based on a regular nonagon:

### Output Requirements

Your application should draw rosettes in the graphics window.

### Input Requirements

The user enters the number of sides, the center point coordinates, and the radius of the polygon on the console window. The program terminates when the user enters a value of 2 or less for the number of sides.

### Process Requirements

Create an array containing the coordinates of the vertices of the regular polygon and use the array to draw the corresponding rosette.

### Miscellaneous Requirements

The graphics window should be 401 pixels wide and 401 pixels high. The title of the graphics window should be "Rosette".

1. Write a function to create the array of vertices. This program makes use of dynamic memory allocation. The out parameter passed to this function to store the vertex coordinates is a pointer to an integer. This function dynamically allocates just enough memory to store the list of vertex coordinates and then fills the array with the appropriate integer values. If this pointer variable is not NULL, then the memory previously allocated for the array of vertex coordinates (by the previous invocation of this function) should be returned to the operating system before allocating memory for the new list of coordinates. Here is the function prototype:

//---------------------------------------------------------
// makePolygon
//
// Pre-condition: n >= 3
//
// Generate the vertices of a regular n-sided polygon of
// radius r centered at (h, k).
//
// In parameters: n, r, h, k
// Out parameter: v (the one-dimensional array of vertices)
//
// The coordinates of each vertex will be integers.
//
// Each successive pair of values in v represents the
// coordinates of a new vertex. If v is not NULL, the memory
// previously allocated for v will be returned to the
// operating system. In any case, exactly enough memory will
// be allocated to v to store 2 * n coordinate values.
//---------------------------------------------------------
void makePolygon(int n, double r, double h, double k, int* & v)

2. Write a function to draw the rosette. Here is the function prototype:

//---------------------------------------------------------
// drawRosette
//
// Pre-condition: n >= 3
//
// Given an array of coordinates for n points, this function
// draws line segments from each point to every other point.
//
// In parameters: n, v
//---------------------------------------------------------
void drawRosette(int n, int v[])

### Sample Run

A sample run showing both the console window and the resulting graphics window is illustrated below:

### Project Files

You'll need to create your own project file. It should be named "Hmwk03.PRJ". Download the file Hmwk03.cpp and add it to your project. I've done a lot of the grunt work for you. You'll need to initialize the graphics window in main and implement the makePolygon and drawRosette functions.

### File Submission

Email me your Hmwk03 project file (PRJ) and your completed program file (Hmwk03).