Question

In: Computer Science

So let's say I got 60% in test. then we have to divide that into 2...

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!

Solutions

Expert Solution

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 :


Related Solutions

So let's say I got 60% in test. then we have to divide that into 2...
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 without using any for or while loops. Example: Input: {{"Ved",...
Let's say that I am the marketer for a medical solution Company. We are trying to...
Let's say that I am the marketer for a medical solution Company. We are trying to enter the market with a medical product (Device) that Alleviates Feet pain and heals Heel Cracks To make you feel relaxed. This product is mainly Targeting People Age 22 To 40 Those who usually suffer from Feet pain and feet cracks. Currently, we are targeting the US market only. So I wanted to know how can I differentiate my product from my competitors and...
I tried this sight before to find filtering options and got fantastic results, so let's try...
I tried this sight before to find filtering options and got fantastic results, so let's try again! I am setting up an experiment that requires light of two different frequencies (445nm and 350nm). The light ultimately needs to be focused on a small area. I can think of two good ways to make this happen: Get a broad spectrum light source that emits over this range - maybe a halogen lamp? - and buy two filters: A high pass that...
So let's say you have a beaker that contains 6.02g ammonium chloride and to this you...
So let's say you have a beaker that contains 6.02g ammonium chloride and to this you add 300.0mL of 0.450 M calcium hydroxide according to the following chemical equation: Ca(OH)2 (aq)+2NH4Cl(s) ---> CaCl2(aq)+2H2O(l)+2NH3    A) Draw the beaker at the end of the reaction - what would e in the beaker and/or around it. What would the products look like on a molecular/atom/ion level? B) How many moles of each reactant does the reaction start with? C)At STP, how many...
Let's say that we have two variables X and Y. We calculate their correlation value to...
Let's say that we have two variables X and Y. We calculate their correlation value to be r = -.8012. What is the interpretation of this value?
Let's say we have the following lines of pseudo-code in a program. What type of malware...
Let's say we have the following lines of pseudo-code in a program. What type of malware is in this code? username = get_username(); password = get_password(); if username is "l33t h4ck0r": return PERMIT_ENTRY if username and password are valid: return PERMIT_ENTRY else return DENY_ENTRY rootkit spyware trojan horse backdoor
Let's say that I have a set of ten linear, simulateous equations for 6 unknowns. What...
Let's say that I have a set of ten linear, simulateous equations for 6 unknowns. What MATLAB code could I write to see how many of the variables could be solved in a numerical solution?
Let's say I have two different reactions, each with their own unique rectant. In both rections,...
Let's say I have two different reactions, each with their own unique rectant. In both rections, the concentration and recation contants are equal. The only differnce between the two reactions is the tempature of the system as in the first system the tempature is lower than that of the second. Can you determine from this infomation which reaction will have a larger activation energy barrier?
Let's now say we have $50 in a bank account and we deposit an additional $10 per month for 5 years.
Let's now say we have $50 in a bank account and we deposit an additional $10 per month for 5 years. The annual interest rate is 10%, compounded monthly. How much will we have in the account after 5 years rounded to the nearest dollar? A) $887 B) $692 C) $857 D) $665
Let's say for a chlorophyll solution we found the absorbance, and use d that with Beer's...
Let's say for a chlorophyll solution we found the absorbance, and use d that with Beer's law to find the concentration. How come that concentration is different if we find the concentration of the same chlorophyll solution using the fluorescence?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT