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

I need help with this assignment that is due on Monday, March 12. This is on Par

ID: 3726567 • Letter: I

Question

I need help with this assignment that is due on Monday, March 12. This is on Parallel Arrays, using C++ only.

In class we used an example of parallel arrays that store the students name in an array of strings, their grades on the first exam in an array of ints and their grades on the second exam in an array of ints. Use the code we wrote in class, and the ideas explained in the slides, for the following exercises. Nick John Amy Ron Bob Jill Jane Joe Ryan Mike 76 82 85 Name 91 100 97 77 63 54 72 Exam 1 Exam 2 81 95 94 98 74 71 80 62 69 Exercise 1: Write a loop to figure out the name of the student who got the highest score on the first exam Your output should be in the format of: Ron scored the highest on the first exam and his grade was 100 Test your code to make sure it works no matter which array entry contains the highest value, and which score it was! Remember that each student's data is like a column and has the same index in all the parallel arrays. Name Exam 1 Exam 2 Nick John |Amy Ron Bob Jill Jane Joe Ryan Mike 76 85 82 91 100 97 63 54 72 81 95 94 98 74 7 1 80 62 69 Exercise 2: Create another palray called avg and store each student's average in it. Your program should calculate each student'saverage and store it in the array. Then go through the avg array to display a list of the students' names along with their averages. For our example the output begins as follows Nick: 80.5 John: 81.5 Amy: 93

Explanation / Answer

1) program stores the student name and two exam marks. sorts the exam1 mark and display the highest value of exam1.

Coding:

#include <cstdlib>

#include<iostream>

#include <string>

using namespace std;

int main(int argc, char** argv) {

int n =10;

//Declare and initialize the variables

//for name

string name[n]={"Nick","John","Amy","Ron","Bob","Jill","Jane","Joe","Ryan","Mike"};

int exam1[n]={76,82,91,100,97,77,63,88,54,72};

int exam2[n]={85,81,95,94,98,74,71,80,62,69};

  

int t;//temporary variable for storing the values while sorting

string temp;//temporary variable for storing the string while sorting

  

//sort the array values in parallel

for(int i=0; i<n; i++){

for(int j=0; j<n; j++){

if(exam1[i]<exam1[j]){//for swapping the numbers

//swap the exam1 values

t=exam1[i];

exam1[i]=exam1[j];

exam1[j]=t;

//swaps the name

temp=name[i];

name[i]=name[j];

name[j]=t;

//swaps the exam2

t=exam2[i];

exam2[i]=exam2[j];

exam2[j]=t;

  

  

}

}

}

//prints the result. array was in sorted list. so the last element holds the highest value of exam1

cout<<" "<<name[n-1]<<"scored the highest on the first exam and his grade was"<<exam1[n-1];

return 0;//end of the main

}

Sample Output:

Ron scored the highest on the first exam and his grade was 100
RUN SUCCESSFUL (total time: 241ms)

2) c++ program finds the average of two exams and stores in another array

Coding:

#include <cstdlib>

#include<iostream>

#include <string>

using namespace std;

int main(int argc, char** argv) {

int n =10;

//Declare and initialize the variables

//for name

string name[n]={"Nick","John","Amy","Ron","Bob","Jill","Jane","Joe","Ryan","Mike"};

int exam1[n]={76,82,91,100,97,77,63,88,54,72};

int exam2[n]={85,81,95,94,98,74,71,80,62,69};

  

//declare an new array variable for storing average

double avg[n];

  

int t;//temporary variable for storing the values while sorting

string temp;//temporary variable for storing the string while sorting

  

//sort the array values in parallel

for(int i=0; i<n; i++){

for(int j=0; j<n; j++){

if(exam1[i]<exam1[j]){//for swapping the numbers

//swap the exam1 values

t=exam1[i];

exam1[i]=exam1[j];

exam1[j]=t;

//swaps the name

temp=name[i];

name[i]=name[j];

name[j]=temp;

//swaps the exam2

t=exam2[i];

exam2[i]=exam2[j];

exam2[j]=t;

  

  

}

}

}

  

//prints the result. array was in sorted list. so the last element holds the highest value of exam1

cout<<" "<<name[n-1]<<" scored the highest on the first exam and his grade was "<<exam1[n-1]<<endl;

  

//execrise 2

cout<<"Average of the two exams are :"<<endl;

cout<<" Name Average";

for(int i=0; i<n; i++){

//stores the average

avg[i]=double(exam1[i]+exam2[i])/(double)2;

cout<<" "<<name[i]<<" : "<<avg[i];

}

return 0;//end of the main

}

Sample Run:

Ron scored the highest on the first exam and his grade was 100
Average of the two exams are :

Name Average
Ryan : 58
Jane : 67
Mike : 70.5
Nick : 80.5
Jill : 75.5
John : 81.5
Joe : 84
Amy : 93
Bob : 97.5
Ron : 97
RUN SUCCESSFUL (total time: 160ms)