[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can anyone help me with this question? Write a highestScore function

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 1

File: Mgspw-cecile-cosina-caminades.jpg (84KB, 600x1100px) Image search: [Google]
Mgspw-cecile-cosina-caminades.jpg
84KB, 600x1100px
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
Thread posts: 9
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.