I have a level 2 programming class i have to take for my major, even though i'm on the IT track and not programming. I struggle alot with programming and was looking to get pointed in the right direction. Below is the directions for my assignment but i honestly have no clue where to start. I passed my intro programming class with a B because my prof gave us 20 min. in class everytime to write code and ask questions as he helped debugg. Can anyone help or point me in the right direction as to what to do with this program? Thanks alot!


Write a program that declares a struct to hold the data of one regular polygon. Since a regular polygon is completely defined by its
number of sides and the length of each of those sides, your struct type, which is to be given a meaningful name, will have two
members; an int for number of sides, and a double for the length of the sides. In your main routine, you will declare an array of your structure type, meaningfully named, with a capacity of 10 elements. Your program will prompt the user for a file name and, if the file is found, it will input the data, which consists of zero or more polygons. Data input will terminate when the end of the file is
encountered or the 10th polygon is input. If the file is not found, the user will be informed, and the program will terminate.

Once the program has input data, it will present a menu to the user which will permit them to perform specific
operations. The L)ist option will print each polygon, one to a line, in tabular form, with appropriate column headers and clean, crisp
margins. For each polygon, list which shape it is, as a string, the lengths of its sides, its area, and perimeter, If the user chooses A)rea or P)erimeter, input which polygon by number, error checking the number (between 0 and the number of polygons minus one) even if you give the user the acceptable range. Output the shape and the value, labeling the value. If the user chooses to quit, prompt them if they really want to quit, and exit only if they confirm.

You must write a fully modular program, where the main routine does little more than call other functions. You must implement functions in your program to perform the following:

 Set the number of sides of a polygon
 Arguments: Polygon number, number of sides
 Set the length of a polygon
 Arguments: Polygon number, side length
 Get the number of sides: Return number of sides of a polygon
 Argument: Polygon number
 Get the length of a side: Return side length of a polygon
 Argument: Polygon number
 Compute and return perimeter: Returns the perimeter of a polygon
 Argument: Polygon number
 Compute and return the area: Returns the area as a double
 Argument: Polygon number
 toString: Returns the name of the shape, based on its number of sides (3-8)
 Argument: Number of sides
 readFile: Inputs the file into the array of Polygon. Reads each polygon's data and fills in a struct element using the functions for
performing those operations.
 Argument:s: iostream handle of the data file (must be by reference; why?), array of Polygon, number of Polygons

I can't see the image?

Looks like this but with a straight border

**************************
* Select: *
* L)ist Polygons *
* A)rea of a Polygon *
* P)erimeter of a Polygon *
* Q)uit *
**************************

First of all, for file I/O, read a good tutorial on file streams (and streams in general). Just check Google.

You should know how to define a function already. Here's an example just in case:

/* Sample function that adds two integers */
int add(int a, int b)
{
    return (a+b);
}

int main(int argc, char *argv[])
{
    /* Declare integer variable c */
    int c;
    
    /* Assign c the value of 3 + 5 using our function */
    c = sum(3, 5);

    return 0;
}

Finally, structures.

I won't write the structure for you, but I will show you how to write a structure.

You create a structure with the following syntax:

struct example_s {
    int a;
    char b;
};

This creates a structure with two data fields, referred to as a and b.

To use this structure, do something like the following:

int main(int argc, char *argv[])
{
   /* Make an instance of our structure, as defined above */
    example_s data1;
    
    /* Assign a value to the 'a' field of data1 */
    data1.a = 5;

    /* Same, but for 'b' field, which is a char */
    data1.b = 'c';

    return 0;
}

You can basically use your struct like a new data type. The difference is that it has 'fields', denoted by the names you created when you defined your structure. You can make arrays of structures just as you would make arrays of ints or chars.

I would recommend reading a tutorial on structures before using them in an assignment. There are lots of good tutorials out there!

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.