need help fixing my program, structs and arrays

hi,

i am suppose to write a program that calculates measurements of shapes inputed from a txt file. i did that and wrote arrays for each measurement in a struct, but i am kind of confused on what i am supposed to change in my program, my professor couldn't explain it clear enough. i guess i am suppose to have one dynamic array for all shapes and its measurements instead of having an array of doubles for each measurement of the shape.

how would i go about doing this because i am not to sure.

i cut the code down because it's really lengthy, and i only put in one shape (rectangle) so it will be easier to read.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::ios;

#include <iomanip>
using std::setprecision;

#include <fstream>
using std::ifstream;

#include <cmath>

#include <cstring>
using std::strtok;
using std::strcmp;

#include <cstdlib>

const int MAX_CHARS_PER_LINE = 50;
const int MAX_TOKENS_PER_LINE = 4;
const char* DELIMITER = " ";

// structs of of shapes with array of the required information for those shapes
struct Rectangle
{
double length[100];
double width[100];
};

// void functions that allow for calculation of the shapes measurements
void rectangleCalc(double, double);

int main()
{
//measurements come from an input file
ifstream fin;
fin.open("geo.txt");
if(!fin.good())
return 1;

// sets up a char array
char* token[MAX_TOKENS_PER_LINE] = {0};

//sets a variable to the struct shape, allowing it to be accessed
Rectangle shapeR;

// counter of all valid shapes in text file
int validRectangles = 0;

// while statement that tokenizes the txt file, and also validates if the shape is valid
while(!fin.eof())
{
char buf[MAX_CHARS_PER_LINE];
fin.getline(buf, MAX_CHARS_PER_LINE);

int n = 0;

token[0] = strtok(buf, DELIMITER);

if(token[0])
{
for(n = 1; n < MAX_TOKENS_PER_LINE; n++)
{
token[n] = strtok(0, DELIMITER);
if(!token[n]) break;
} //for

if((strcmp(token[0], "RECTANGLE") == 0))
{
if(n != 3)
cout << token[0] << " Invalid Object" << endl;
else
{
shapeR.length[validRectangles] = atof(token[1]);
shapeR.width[validRectangles] = atof(token[2]);
validRectangles++;
} //else
} //if
} //while

cout << endl;

// calculates the measurements and then prints out the measurements of each valid shape
for(int i = 0; i < validRectangles; i++)
rectangleCalc(shapeR.length[i], shapeR.width[i]);

cout << endl;
cout << "Press Enter to continue..." << endl;
cin.get();

return 0;
} //main

// void functions with calculation and print out statements for each shape

void rectangleCalc(double side1, double side2)
{
double perimeter;
double area;

perimeter = (side1 * 2) + (side2 * 2);
area = side1 * side2;

cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(1);
cout << "RECTANGLE side1=" << side1 << " side2=" << side2;
cout << " perimeter=" << perimeter << " area=" << area;
cout << endl;
} //rectangleCalc 


the input file would be like this:
RECTANGLE 10 20
Topic archived. No new replies allowed.