cp /usr/users/mdanfor/public_html/cs221-f08/array_example.cpp .Compile and run the program using the following commands:
g++ -o demo array_example.cpp ./demoYou should see how the variable i gets overwritten by using an invalid subscript for the array. This is why you, as the programmer, must keep track of the size of the array when accessing elements using the subscript operator.
Create a program that will read data from lab7.dat into arrays. You can copy the file over to your current directory using the following command:
cp /usr/users/mdanfor/public_html/cs221-f08/lab7.dat .Note that lab7.dat has the pattern of an integer followed by a double on each line. This means you will need two arrays, one for the integers and one for the doubles. Use a loop similar to that described in class on Monday to read data from the file and store the data in the arrays. You will need to alter the "fin >> values[size]" portion. Recall from the file I/O lecture that you can read a line at a time using chained input if you know the pattern of the line. So to read each line, you would replace "fin >> values[size]" with a chained input similar to the following (assuming the input file is called fileIn):
fileIn >> <int_variable> >> <double_variable>The <int_variable> will be an element in your integer array and the <double_variable> will be an element in your double array.
After reading the values in, use a for() loop to print the integers to the screen and then second for() loop to print the doubles to the screen. Your output should be similar to the following:
The integers are: 3 7 10 5 96 76 The doubles are: 4.5 9.823 2.4517 3.54 56.78 43.2Email lab7.cpp to me