I have missed the last week of my Computer Science class with a stomach bug, and as it turns out, i missed the entire introduction to Arrays and now I have a lab assignment on them. Anybody care to give me a hand with this, as I read the tutorial on this site for Arrays, but I'm not really sure what it's purpose is. Anyways, the lab assignment is to read numeric values from an external file, and output them in order. In addition to that, I must output the maximum and minimum values to show it's range. Since I am still struggling with functions as well, I'm looking for help with the MAX/MIN part as well. But we'll get to that later. So far, here is what I have:
#include <iostream>
#include <fstream>
usingnamespace std;
void readValues(double a[], int& nValues, string filename);
// Reads values from the file filename and stores them in the
// array a.
// Returns nValues, the number of values stores in mthe array a.
constint MAX_VALUES = 10;
int main()
{
double values[MAX_VALUES];
int i, numValues;
readValues(values, numValues, "lab9.dat");
// Write the marks to standard output.
for (i = 0; i < numValues; i++)
{
cout << "Value #" << i
<< " is " << values[i] << endl;
}
cout << "\nNormal exit.\n";
return 0;
}
//--------------------------------------------------
void readValues(double a[], int& nValues, string filename)
{
}
That's what was given to me in the lab handout, and I'm not really sure what to do from there. IM NOT ASKING FOR THE COMPLETED CODE, I am simply asking for some help on the issue, since I dont quite understand Arrays. Any help would be appreciated (maybe a simplified explanation of Arrays to start with? (: )
Thats the thing though, I'm not sure what to do with the Arrays, the code i posted was provided to me as a start from my instructor. I know how to open a file and read an integer from it, yes (using fin.open/ fin.close/ etc...). However, in the .dat file provided, there is a line of text that needs to be ignored and then the integers are on the lines after that. Is there a certain code I need to include to ignore the text, or will just putting "int" be enough? It seems to me that the program should automatically ignore the characters, but I just need to make sure.
Sorry if i seem a little slow, I've never programmed before this semester. It seems to me that Arrays are just groups of declarations (ie. ints, chars, doubles, etc.) Is that correct? Is the whole purpose of Arrays to group together variable declarations to call upon them easier later?
OK thank you, thats what was getting me confused, I didnt really understand what the point of it was, but i suppose the goal is to write a program with as little text as possible, and this certainly cuts down the working time. I will get to work on this program now that I understand Arrays (if only the basic concept of it), and will post if I have any further problems with parts of the coding.