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 here is the example 7.14. it's incomplete that's why we have to complete it. //DISPLAY 7.4 Function with an Array Parameter //Function Declaration #include const int SIZE = 3; void fill_up(int a[], int size); //Precondition: size is the declared size of the array a. //The user will type in size integers. //Postcondition: The array a is filled with size integers //from the keyboard. // Driver to test function fill_up int main() { using namespace std; int myArray[SIZE], number; //Invokes function fill_up to populate the array, passing in the entire array fill_up(myArray, SIZE);//NOTE: fill_up is a void function //iterates through the array displaying the updated vacation days cout << "Array contents are:\n"; for (number = 0; number < SIZE; number++) cout << "Element Number " << number << " is " << myArray[number] << endl; return 0; } //Function Definition //Uses iostream: void fill_up(int a[], int size) { using namespace std; cout << "Enter " << size << " numbers:\n"; for (int i = 0; i < size; i++) cin >> a[i]; size--; cout << "The last array index used is " << size << endl; } tip : Both functions will be structured in a similar fashion to the “computeStAve” Sample Dialog for the loadArray function (The dialog for the loadFromFile function will provide the same output table but no prompts for the user because the data is coming from a file). Label and copy the test run for both functions to the bottom of your source file. Enter quiz grade # 1 for student # 1 10 Enter quiz grade # 2 for student # 1 10 Enter quiz grade # 3 for student # 1 10 Enter quiz grade # 1 for student # 2 2 Enter quiz grade # 2 for student # 2 0 Enter quiz grade # 3 for student # 2 1 Enter quiz grade # 1 for student # 3 8 Enter quiz grade # 2 for student # 3 6 Enter quiz grade # 3 for student # 3 9 Enter quiz grade # 1 for student # 4 8 Enter quiz grade # 2 for student # 4 4 Enter quiz grade # 3 for student # 4 10 Total Number of Quizzes entered is 12 Student Ave Quizzes 1 10.0 10 10 10 2 1.0 2 0 1 3 7.7 8 6 9 4 7.3 8 4 10 Quiz averages = 7.0 5.0 7.5 Press any key to continue ...
- 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
here is the example 7.14. it's incomplete that's why we have to complete it.
//DISPLAY 7.4 Function with an Array Parameter
//Function Declaration
#include <iostream>
const int SIZE = 3;
void fill_up(int a[], int size);
//Precondition: size is the declared size of the array a.
//The user will type in size integers.
//Postcondition: The array a is filled with size integers
//from the keyboard.
// Driver to test function fill_up
int main()
{
using namespace std;
int myArray[SIZE], number;
//Invokes function fill_up to populate the array, passing in the entire array
fill_up(myArray, SIZE);//NOTE: fill_up is a void function
//iterates through the array displaying the updated vacation days
cout << "Array contents are:\n";
for (number = 0; number < SIZE; number++)
cout << "Element Number " << number
<< " is " << myArray[number] << endl;
return 0;
}
//Function Definition
//Uses iostream:
void fill_up(int a[], int size)
{
using namespace std;
cout << "Enter " << size << " numbers:\n";
for (int i = 0; i < size; i++)
cin >> a[i];
size--;
cout << "The last array index used is " << size << endl;
}
tip : Both functions will be structured in a similar fashion to the “computeStAve”
Sample Dialog for the loadArray function (The dialog for the loadFromFile function will provide the same output table but no prompts for the user because the data is coming from a file). Label and copy the test run for both functions to the bottom of your source file.
Enter quiz grade # 1 for student # 1 10
Enter quiz grade # 2 for student # 1 10
Enter quiz grade # 3 for student # 1 10
Enter quiz grade # 1 for student # 2 2
Enter quiz grade # 2 for student # 2 0
Enter quiz grade # 3 for student # 2 1
Enter quiz grade # 1 for student # 3 8
Enter quiz grade # 2 for student # 3 6
Enter quiz grade # 3 for student # 3 9
Enter quiz grade # 1 for student # 4 8
Enter quiz grade # 2 for student # 4 4
Enter quiz grade # 3 for student # 4 10
Total Number of Quizzes entered is 12
Student Ave Quizzes
1 10.0 10 10 10
2 1.0 2 0 1
3 7.7 8 6 9
4 7.3 8 4 10
Quiz averages = 7.0 5.0 7.5
Press any key to continue ...
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images