This exercise give you practice working with a two-dimensional array. the Example 7.14 on two-dimensional arrays, recall that I loaded the array using an Initializer list. Modify Example 7.14. Instead of using an initializer list to load the array, create 2 functions: loadArray – function “loadArray“ will have 1 parameter which will be the grade array. The function will allow the user to enter 12 quiz grades (3 for each student), store each quiz grade in the appropriate element of the grade array, and return an int representing the number of quizzes entered (12). “loadArray” will use nested loops to prompt the user to enter the 12 grades. It will count each grade entered and return the number of quizzes entered. loadFromFile – function “loadFromFile” will have 1 parameter which will be the grade array. The function will return an int representing the number of quizzes read(12). “loadFromFile” will use nested loops to read the values from the file and store each quiz grade in the appropriate element of the grade array. It will count each grade read and return the number of quizzes entered. I have include file “txt” in the Module 14 download. Define both functions in your modified version of example 7.14. For testing purposes, invoke both functions, but always leave one of those functions calls commented out This is what I have so far //load from file loadFromFile(int myGrade[ ] [NUMBER_QUIZZES]) using namespace std; ifstream fin; ofstream fout; fin.open("quizzes.txt"); if (fin.fail()) cout << "Input file opening failed. \n"; exit(1); //Load from keyboard int loadArray(int grade[ ] [NUMBER_QUIZZES]) using namespace std; int next=0, index = 0; cout << "Enter quiz grade " << grade << " for student # " << index << ". \n"; cin >> next; while ((next >= 0) && (index < NUMBER_QUIZZES) ) index++; cin >> next; return 0; }
- This exercise give you practice working with a two-dimensional array. the Example 7.14 on two-dimensional arrays, recall that I loaded the array using an Initializer list. Modify Example 7.14. Instead of using an initializer list to load the array, create 2 functions:
- loadArray – function “loadArray“ will have 1 parameter which will be the grade array. The function will allow the user to enter 12 quiz grades (3 for each student), store each quiz grade in the appropriate element of the grade array, and return an int representing the number of quizzes entered (12). “loadArray” will use nested loops to prompt the user to enter the 12 grades. It will count each grade entered and return the number of quizzes entered.
- loadFromFile – function “loadFromFile” will have 1 parameter which will be the grade array. The function will return an int representing the number of quizzes read(12). “loadFromFile” will use nested loops to read the values from the file and store each quiz grade in the appropriate element of the grade array. It will count each grade read and return the number of quizzes entered. I have include file “txt” in the Module 14 download.
Define both functions in your modified version of example 7.14. For testing purposes, invoke both functions, but always leave one of those functions calls commented out
This is what I have so far
//load from file
loadFromFile(int myGrade[ ] [NUMBER_QUIZZES])
using namespace std; ifstream fin; ofstream fout; fin.open("quizzes.txt"); if (fin.fail())
cout << "Input file opening failed. \n"; exit(1);
//Load from keyboard int loadArray(int grade[ ] [NUMBER_QUIZZES])
using namespace std; int next=0, index = 0;
cout << "Enter quiz grade " << grade << " for student # " << index << ". \n";
cin >> next;
while ((next >= 0) && (index < NUMBER_QUIZZES) )
index++; cin >> next;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images