This week we are going to be working with arrays. The main goal for this is to read in numbers and store them in the array.
You are going to create an array of ints of size 10. You will then make a function with the following signature:
void readInts( istream& in, ostream& out );
and this needs to be declared in a header called:
lab8.h
The function will read one numbers per line from the input. The first number will simply be stored in the array at the next available location. If the array is full, then you do not add the number to the array.
Once all the data has been read in and possibly stored in the array, you will loop over the array and give me the index location and the value stored there.
Remember there are 3 things you need to "know" about the array.
1
2
3
4
Index Value
0 1
1 2
2 3
3 4
4 ?
5 ?
6 ?
7 3
8 ?
9 ?
You should not initialize your array and then print out ?'s Just print out the values in the array.
I used ? above to represent the value that I don't know. Since those locations didn't get a value C++ doesn't guarantee any value. I will check that the good values are set.
So when you print the array, go ahead and print the entire array, not just the locations that are filled.
It's always a good idea to test your code. I'll provide a real simple main you can use.
#include <iostream>
#include "lab8.h"
using std::cout;
using std::cin;
using std::endl;
int main()
{
readInts( cin, cout );
}
To turn this in and get it scored, zip up your lab5.h and any implementation file you wrote for this and turn it in to Web-CAT.