Question

In: Computer Science

A professor has constructed a 3-by-4 two-dimensional array of float numbers. This array currently contains the...

A professor has constructed a 3-by-4 two-dimensional array of float numbers. This array currently contains the lab grades, quiz grades and exam grades of three students in the professor’s class. Write a C++ program that calculate the final grade for each student and save it to the last column. You program should display the following output:             Lab    Quiz      Exam       Final    

Student 1          ## ## ## ##

Student 2          ## ## ## ##

Student 3          ## ## ## ##

The final grade consists of 30% lab grade, 30% quiz grade and 40% exam. For example, if lab grade is 95, quiz grade is 82 and exam grade is 87, the final grade is equal to 95∗0.3+82∗0.3+87∗0.4. Use random numbers between 40 and 100 for lab, quiz and exam grades.

Solutions

Expert Solution

#include <bits/stdc++.h>
using namespace std;

int main() {
// create an array for the grades
float a[3][4];
// save the percentage of each grade to consider
float percent[3] = {0.3, 0.3, 0.4};
// the grades lie between this range
int max = 100, min = 40;
// fill the array with random numbers
for(int i=0; i<3; i++){
int finalGrade=0;
for(int j=0; j<3; j++){
// taking modulus with max-min will make the random number generated lie between the
// given range and adding the min of the range gives the required number
a[i][j] = rand()%(max-min + 1) + min;
// also calulate the final grade for each student
finalGrade += a[i][j]*percent[j];
}
// update the final grade
a[i][3] = finalGrade;
}
  
// manipulate the output format of the grades
cout<<setw(14)<<"Lab"<<setw(6)<<"Quiz"<<setw(5)<<"Exam"<<setw(6)<<"Final"<<endl;
// print the grades for each student
for(int i=0; i<3; i++){
cout<<"Student "<<i<<setw(5)<<a[i][0]<<setw(5)<<a[i][1]<<setw(5)<<a[i][2]<<setw(5)<<a[i][3]<<setw(5)<<endl;
}
  
return 0;
}

Output:


Related Solutions

Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers.
Programing in Scala language: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parametersrow and col), set an element (given parametersrow, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.
In C an array Numbers is declared float Numbers[10][10]. Due to a bug, the program tried...
In C an array Numbers is declared float Numbers[10][10]. Due to a bug, the program tried to reference Numbers[11][-13]. Which element of Numbers will actually be accessed?
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we...
Create a “Main” method that contains two 2-Dimensional arrays of characters. The first array, which we will call our visible field, needs to be 5 by 5 and should initially hold the underscore character “_”.  This will be used in our game of minesweeper to represent the possible locations the player can check. The second array, which we will call our hidden field, should also be 5 by 5 but filled with the capital letter "S” which means safety. However, we...
In Java please Your program will sort a two dimensional array (5 * 4) based on...
In Java please Your program will sort a two dimensional array (5 * 4) based on the following: The entire array should be sorted using bubble sort based on the 1st column in ascending order and display the entire array. Reset the array to its original contents. The entire array should again be sorted using selection sort based on the 2nd column in descending order and display the entire array. Reset the array to its original contents. The entire array...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional array will be used to store the rows and columns of a multiplication and division table. Note that the table will start at 1 instead of zero, to prevent causing a divide-by-zero error in the division table! struct mult_div_values { int mult; float div; }; The program needs to read the number of rows and columns from the user as command line arguments. You...
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
Build a two dimensional array out of the following three lists. The array will represent a...
Build a two dimensional array out of the following three lists. The array will represent a deck of cards. The values in dCardValues correspond to the card names in dCardNames. Note that when you make an array all data types must be the same. Apply dSuits to dCardValues and dCardNames by assigning a suit to each set of 13 elements. dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14'] dSuits = ["Clubs","Spades","Diamonds","Hearts"] Once assigned your two dimensional array should resemble this : 2...
1.Declare a two-dimensional array of Strings namedchessboard.
1. Declare a two-dimensional array of Strings named chessboard.2. Declare a two-dimensional array of integers named tictactoe.3. Declare and create a two-dimensional array of chars,tictactoe, with 3 rows, each with 3 elements.4. Create a two-dimensional array of ints, plan, with 2 rows, and and 3 columns and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. Use member initializer syntax.
Create a game of Connect Four using a two dimensional array (that has 6 rows and...
Create a game of Connect Four using a two dimensional array (that has 6 rows and 7 columns) as a class variable. It should be user friendly and be a two person game. It should have clear directions and be visually appealing. The code MUST have a minimum of 3 methods (other than the main method). The player should be able to choose to play again. **Code must be written in Java**
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT