Can anyone help me with this question?
Write a highestScore function to find out the index of the array member whose value is the highest.
Declareand initializeone score array and one name array(The two arrays have the same size). The same index number in these two arrays represent the record of the sameperson. For instance, if name[2] = “Mike”and score[2] = 82, it means that Mike’s score is 82.b.Call the highestScore functionto find the index. Then print out the name andscore of the person with the highest score.
Current code
/*Beginning Comment
* ScoreReport.cpp
* Write a highestScore function to find out the index of the array member
whose value is the highest
* Author:
* Created on: 1/18/2017
*/
#include<string>
#include<iostream>
using namespace std;
//function prototype
int main(){
//Declare a name array and initialize it at the same time
const int SIZE = 3;
string nameList[SIZE] = {"Sam", "Bob", "Chris"};
//Declare a score array and initialize it at the same time
int scoreList[2] = {70,30,93};
}
>>8624977
CS 1400 homework thread?
>>8624977
function val = highestScore(arr)
val = find(arr, max(arr));
end
this is sad
>>8625033
Learning is sad? I'm just trying to learn. I appreciate help but don't think I'm not trying to do this myself
>>8625033
I also put this on the wrong thread so sorry about that.
>>8625057
Youre gonna want to find a different major... This is highschool programming class tier. If you cant figure this one out with notes and a textbook, gender studies is more up your alley.
>>8624977
template<typename T>
size_t highestScore(const T* const scoreList, const int SIZE){
size_t index=0;
auto max=scoreList[0];
for(size_t i= 1; i<SIZE; i++)
if(scoreList[i]>max){
index=i;
max=scoreList[i];
}
}
return index;
}
//... back in main
auto index = highestScore(scoreList, SIZE);
cout<<nameList[index]<<"'s score is "<<scoreList[index];
return 0;
}// end of main
>>8625139
>not doing it all in main
Pleb/10
/*Beginning Comment
* ScoreReport.cpp
* Write a highestScore function to find out the index of the array member
whose value is the highest
* Author: Anonymous
* Created on: 1/18/2017
*/
#include<string>
#include<iostream>
using namespace std;
//function prototype
int main(){
//Declare a name array and initialize it at the same time
const int SIZE = 3;
string nameList[SIZE] = {"Sam", "Bob", "Chris"};
//Declare a score array and initialize it at the same time
int scoreList[2] = {70,30,93};
//Declaring a highestScore function to find out the index of the array member
whose value is the highest
auto highestScore = [&](){
size_t index=0;
auto max=scoreList[0];
for(size_t i= 1; i<SIZE; i++)
if(scoreList[i]>max){
index=i;
max=scoreList[i];
}
}
return index;
};
auto index = highestScore();
cout<<nameList[index]<<"'s score is "<<scoreList[index];
//Returning 0 to end the main function
return 0;
}// end of main