Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to write a C++ program that searches the array grades for a specific

ID: 3686068 • Letter: I

Question

I need help to write a C++ program that searches the array grades for a specific targetID located in the first column. The array grades has 4 columns and 5 rows. The first column holds the Student ID, the second, third and fourth columns hold quiz grades. Each row represents a single student. The program searches the first column of the array for the targetID , then displays the ID, the grades and then calculates and prints the average of the grades to screen.

For example, for the following array and targetID: 444

111

10

9

10

222

8

10

10

333

9

7

8

444

3

5

7

555

5

9

7

The program will display to screen:

ID:                      444

Quiz 1:                3

Quiz 2:                5

Quiz 3:                7

Average:              7.5

Thank You!!

111

10

9

10

222

8

10

10

333

9

7

8

444

3

5

7

555

5

9

7

Explanation / Answer

Solution.cpp

#include <iostream>//input output function header file
#include <iomanip>//for setting precision
using namespace std;//links std name space to the compiler

int main ()
{//main function
// an array with 5 rows and 2 columns.
int a[5][4] = { {111,10,9,10}, {222,8,10,10}, {333,9,7,8}, {444,3,5,7},{555,5,9,7}};
int targetid;
double average;
cout<<"enter the target id"<<endl;
cin>>targetid;//hey board inputting

if(targetid==111)
{//if else else if statements
cout<<"ID :"<<a[0][0]<<endl;
cout<<"QUIZ1 :"<<a[0][1]<<endl;
cout<<"QUIZ2 :"<<a[0][2]<<endl;
cout<<"QUIZ3 :"<<a[0][3]<<endl;
cout << setprecision(2) <<fixed;//setting precision values using setprecision function
average=((double)a[0][1]+(double)a[0][2]+(double)a[0][3])/3;
  
cout<<"Average :"<<average<<endl;
}
else if(targetid==222)
{
cout<<"ID :"<<a[1][0]<<endl;
cout<<"QUIZ1 :"<<a[1][1]<<endl;
cout<<"QUIZ2 :"<<a[1][2]<<endl;
cout<<"QUIZ3 :"<<a[1][3]<<endl;
cout << setprecision(2) <<fixed;
average=((double)a[1][1]+(double)a[1][2]+(double)a[1][3])/3;
  
cout<<"Average :"<<average<<endl;
}
else if(targetid==333)
{
cout<<"ID :"<<a[2][0]<<endl;
cout<<"QUIZ1 :"<<a[2][1]<<endl;
cout<<"QUIZ2 :"<<a[2][2]<<endl;
cout<<"QUIZ3 :"<<a[2][3]<<endl;
cout << setprecision(2) <<fixed;
average=((double)a[2][1]+(double)a[2][2]+(double)a[2][3])/3;
  
cout<<"Average :"<<average<<endl;
}
else if(targetid==444)
{
cout<<"ID :"<<a[3][0]<<endl;
cout<<"QUIZ1 :"<<a[3][1]<<endl;
cout<<"QUIZ2 :"<<a[3][2]<<endl;
cout<<"QUIZ3 :"<<a[3][3]<<endl;
cout << setprecision(2) <<fixed;
average=((double)a[3][1]+(double)a[3][2]+(double)a[3][3])/3;
  
cout<<"Average :"<<average<<endl;
}
else if(targetid==555)
{
cout<<"ID :"<<a[4][0]<<endl;
cout<<"QUIZ1 :"<<a[4][1]<<endl;
cout<<"QUIZ2 :"<<a[4][2]<<endl;
cout<<"QUIZ3 :"<<a[4][3]<<endl;
cout << setprecision(2) <<fixed;
average=((double)a[4][1]+(double)a[4][2]+(double)a[4][3])/3;
  
cout<<"Average :"<<average<<endl;
}
else
{
cout<<"Target id is not present please try again";
}
return 0;
}

output

enter the target id                                                                                                                                                             

333                                                                                                                                                                             

ID      :333                                                                                                                                                                    

QUIZ1   :9                                                                                                                                                                      

QUIZ2   :7                                                                                                                                                                      

QUIZ3   :8                                                                                                                                                                      

Average :8.00

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote