// Zeinalipour-Yazti Demetrios // csyiazti // cs10xx - // Lab Sec#24 // lab10 /* Working with Arrays */ #include #include #include #include #include using namespace std; /* the number of stars found in the ratings.txt file*/ const int STARSIZE = 5; /* this procedure reads the file from disk and counts the number * of occurence of each "star pattern" */ void readData(int occurence[]) { string filename; string line; while (true) { /* get the filename */ cout << "Give me the name of the file: " ; cin >> filename; cout << "\nOpening \'" << filename << "\'..."; /* open file for input */ ifstream infilestream; infilestream.open(filename.c_str(), ios::in); if (infilestream) /* overload ! operator*/ { cout << "done\n"; while (!infilestream.eof()) { infilestream >> line; occurence[line.length()-1]++; } break; } else { cout << "failed\n"; cerr << "File could not be opened\n" << endl; infilestream.close(); } } } /* initialize the occurence array */ void initArray(int occurence[]) { for (int i=0; i< STARSIZE; i++) { occurence[i] = 0; } } /* output the result */ void printResults(int occurence[]) { const int COLSPAN = STARSIZE + 3; /* Print Header */ cout << "Rating" << " Count \n"; /* Print result and count */ for (int i=0; i< STARSIZE; i++) { for (int j=0; j