code errors

need some help with my code, eyes are getting crossed any help is appreceated

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
ifndef H_listType
 #define H_listType

 #include <cstdlib>
 #include <iostream>
 #include <cassert>

 using namespace std;

 template <class elemType>
 class listType
 { //class template to create an array and perform various functions
 public:
 bool isEmpty() const;
 bool isFull() const;
 int getLength() const;
 int getMaxSize() const;
 void sort();
 void print() const;
 void insertAt(const elemType& item, int position);
 listType(int listSize = 50);
 ~listType();

 protected:
 int maxSize;
 int length;
 elemType *list;
 };

 template <class elemType>
 bool listType<elemType>::isEmpty() const
 { //function to check if array is empty
 return (length == 0);
 }

 template <class elemType>
 bool listType<elemType>::isFull() const
 { //function to check if array is full
 return (length == maxSize);
 }

 template <class elemType>
 int listType<elemType>::getLength() const
 { //function to get length
 return length;
 }

 template <class elemType>
 int listType<elemType>::getMaxSize() const
 { //function to get maxSize
 return maxSize;
 }

 template <class elemType>
 listType<elemType>::listType(int listSize)
 { //default constructor
 maxSize = listSize;
 length = 0;
 list = new elemType[maxSize];
 }

 template <class elemType>
 listType<elemType>::~listType()
 { //destructor
 delete [] list;
 }

 template <class elemType>
 void listType<elemType>::sort()
 { //sort function
 int i, j;
 int min;
 elemType temp;

 for(i = 0; i < length; i++)
 {
 min = i;
 for(j = i; j < length; ++j)
 if (list[j] < list[min])
 min = j;
 temp = list[i];
 list[i] = list[min];
 list[min] = temp;
 }
 }

 template <class elemType>
 void listType<elemType>::print() const
 { //print function
 int i;
 for(i = 0; i < length; ++i)
 cout << list[i] << " ";
 cout << endl;
 }

 template <class elemType>
 void listType<elemType>::insertAt(const elemType& item, int position)
 { //insert function
 assert(position >= 0 && position < maxSize);
 list[position] = item;
 length++;
 }

 #endif
//stockType.h
#include <iostream>
#include <ostream>
#include "listType.h"
using namespace std;
class stockType
 {
 public:
 string stockSymbol;
 double open;
 double close;
 double high;
 double low;
 double previousClose;
 double percentGain;
 double volume;

 };



class stockListType: public listType<stockType>
 {
 public:
void arrayInput (int);
void sortTndices();
void printIndices (int);
 
int counter;
int myArray[7];
int mystock;
};
void arrayInput (int myArray)
 {
 
	 int counter = 0;
 int arrayOfStruct = [myArray]
 

 for(counter = 0; counter < 50; counter++;)
 {
	 infile >> arrayOfStruct[counter].stockSymbol;
 infile >> arrayOfStruct[counter].open;
 infile >> arrayOfStruct[counter].close;
 infile >> arrayOfStruct[counter].high;
 infile >> arrayOfStruct[counter].low;
 infile >> arrayOfStruct[counter].previousClose;
 infile >> arrayOfStruct[counter].percentGain;
 infile >> arrayOfStruct[counter].volume;
 }
 }

 void sortTndices ()
 {
 int i = 0;

 for (i = 0; i < 50; i++);
 if (myArray[i] < myArray[i++]);

 }

 void printIndices ()
 {
 int i = 0;
 for(i = 0; i < 50; i++)
 cout << stockType.stocksymbol << stockType.open;
 cout << stockType.close << stockType.high;
 cout << stockType.low << stockType.previousClose;
 cout << stockType.percentGain << stockType.volume << endl;
 };
//main program
#include <ostream>
 #include <string>
#include "stockType.h"

 using namespace std;

 int main ()
 {
 //need a test program here
 
 system ("pause");
 return 0;
 }

 

Last edited on
First off, use code tags please.
2nd, What errors are you getting and where?
not sure what you mean by code tags

two examples of errors
left of '.percentGain' must have class/struct/union
'infile' : undeclared identifier

I already did this but I can seem to get the error to go away.

I see that my post was maked as abusive, sorry this is my first post and I'm unsure exactly how this works
When you type something new, there is a little box to the right that says Format:

Under that is your formatting options, one is code tags, look like <>.
When you mouse over it it says source code.


Line numbers would also be helpful, which you get for free with the code tags.
If you actually read your compiler errors, paying attention to the line numbers in them, I'm sure you'll soon see where your code is incorrect.

For example, at line 141, your declaration of arrayOfStruct doesn't even look like legal C++. I bet your compiler's giving you an error about that.

Compiler errors can be a bit cryptic, and can occasionally be a bit misleading. But a lot of the time, they tell you exactly what's wrong with your code, and exactly where the problem is. If you take the time to read them and understand them, you'll be much more able to fix your code.
Last edited on
Topic archived. No new replies allowed.