Question

For C++, This is part of a larger program but I only need help with writing...

For C++, This is part of a larger program but I only need help with writing and calling this function. I am having trouble finding information on calling a 2d vector.

Given :

const int NUM_STUDENTS =3; 
string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};

4. Write a function called displayGrades that takes the student array and grade vector as parameters and displays the grades in the format in the sample run below. (15 points).

Output: Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5
Tom 78 98 88 99 77
Jane 62 99 94    85 93
Jo 73 82 88 85 78

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <vector>
using namespace std;
const int NUM_STUDENTS =3;
void displayGrades(string students[], vector<int> grades[]) {
cout<<"Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5"<<endl;
for(int i=0;i<NUM_STUDENTS;i++) {
cout<<students[i]<<" ";
for(int j=0;j<grades[i].size();j++) {
cout<<grades[i][j]<<" ";
}
cout<<endl;
}
}

int main()
{
  
string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};
displayGrades(Students, grades);

return 0;
}

Output:

$g++ -o main *.cpp
$main
Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5
Tom 78 98 88 99 77 
Jane 62 99 94 85 93 
Jo 73 82 88 85 78 
Add a comment
Know the answer?
Add Answer to:
For C++, This is part of a larger program but I only need help with writing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a program that uses a function to read in the grades for four classes and...

    write a program that uses a function to read in the grades for four classes and then uses a function to calculate the average grade in each of the classes. input the grades for one student. we will name her Beverly. output how Beverly's grade differs from each classe average. Make sure that your output is very clear. Below is your data: English 90 70 85 45 95 95 82 97 99 65 History 63 94 60 76 83 98...

  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • USE R AND SHOW CODES!! The IQ was measured for 35 twins. Is there any difference...

    USE R AND SHOW CODES!! The IQ was measured for 35 twins. Is there any difference in IQ between twins? DATA Twin 1 Twin 2 113 109 94 100 99 86 77 80 81 95 91 106 111 117 104 107 85 85 66 84 111 125 51 66 109 108 122 121 97 98 82 94 100 88 100 104 93 84 99 95 109 98 95 100 75 86 104 103 73 78 88 99 92 111 108...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • Microsoft Excel Question. I'm having trouble using the vlookup function, I have calculated a final numerical...

    Microsoft Excel Question. I'm having trouble using the vlookup function, I have calculated a final numerical grade for a hypothetical course, and and trying to use a set of numerical grades with their corresponding letter grades to get a vlookup function to return the letter grade from the numerical grade. However the function for some reason only returns the lowest value out of the set grades, not the closest match. Projects Classwork Teamwork/Integrity 100 100 A+ 98 A+ 97 A...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT