// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 13: Nested loops // Date: January 12, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to practice two nested loops. // The problem is to read integers from an input file line by line. // find simple stats for each line. // // Compile and run your program. When everything is fine, // print your .cpp file and turn it to me or the TA. // ***************************************************************** #include < iostream > #include #include < string > #include < cstring > #include < cmath> #include #include using namespace std; int main( ) { //input file objects ofstream outFile; //output file ifstream inFile; //input file //variable declarations int number; //var to store an int value int sum, min, max, avg; //vars to store simple statistical info int counter; //a counter for controling the loop int size; //another counter int row, col; //loop variable for rows and columns /************************************************************ Part A. Create a data file data.txt in range of 0 to 9999 As assume 10 lines, each line with 8 random numbers in the range ************************************************************/ //use two nested for-loops to create the data file //open data.txt outFile.open("data.txt"); if (outFile.fail()) { cout<<"failed to open data.txt so break ...... "<>number; //get next number sum += number; if (number > max) max = number; if (number < min) min = number; } //show stats for each row cout<<" \nStatistical info about row " << row +1 <<" is "< (sum) / static_cast (size) << endl; } /************************************************************ Part C. This is for you: Re-do Part B with two nested while-loops ************************************************************/ /************************************************************ Part D. This is for you: Re-do Part B with two nested do-while-loops ************************************************************/ //well done and exit return 0; }