In: Computer Science
So let's say I got 60% in test. then we have to divide that into 2 so now I got 30% and then we have to add 50% to it. So my final test marks is 80%.
write a function in C++ that takes a map<string, int>
which represents a students name to their test marks and returns a
map<string, double> which represents the upgraded
marks.
Please write this function named "upgraded_marks" without using any
for or while loops.
Example:
Input: {{"Ved", 10}, {"Mike", 80}, {"Jack", 20}, {"Smith", 25}}
Output: {{"Ved", 55}, {"Mike", 90}, {"Jack", 60}, {"Smith", 62.5}}
Code in C++ ONLY, without using any LOOPS.
Thank you!
PROGRAM :
#include <iostream>
#include <iterator>
#include <map>
using namespace std;
map<string, int> mark;
map<string,double> m2;
map<string, int>::iterator itr;
//HERE IS THE FUNCTION
map<string,double> marks_upgrades()
{
if (itr==mark.end())
{
return m2;
}
else
{
m2[itr->first]=(double)itr->second/2+50.0;
itr++;
m2= marks_upgrades();
return m2;
}
}
int main()
{
mark.insert(pair<string, int>("Ved", 10));
mark.insert(pair<string, int>("Mike", 80));
mark.insert(pair<string, int>("Jack", 20));
mark.insert(pair<string, int>("Smith", 25));
itr=mark.begin();
//FUNCTION CALL TO MAKE THE CHANGES IN THE MARKS
m2=marks_upgrades();
itr=mark.begin();
cout<<"\n";
for (itr = mark.begin(); itr != mark.end(); ++itr) {
cout << itr->first
<< '\t' << itr->second << '\n';
}
map<string, double>::iterator itr1;
cout<<"\n";
for (itr1 = m2.begin(); itr1 != m2.end(); ++itr1) {
cout << itr1->first
<< '\t' << itr1->second << '\n';
}
return 0;
}
OUTPUT :