Write a function to accept a vector of test scores (values of type double betwee
ID: 3918689 • Letter: W
Question
Write a function to accept a vector of test scores (values of type double between 0.00 and 100.00) and an empty vector of type char. The function should fill the second vector with the appropriate letter grade for each score in the first vector. So, if the first score were 75, the first letter grade would be C. The scale is 90 A, 80 B, 70 C, 65 D, 65 F O void calcLetter(const vector &V1;, vector &V2;) for(int i 0;i= 90.0) else if (V1li80.0 lg = 'B'; else if (V1il70.0 lg = 'C'; else if (V1lil 65.0 else V2.[i]=Ig;Explanation / Answer
Correct option is B.
Execute the below code..
// C++ program to demonstrate how vectors
// can be passed by reference.
#include<bits/stdc++.h>
using namespace std;
void func(vector<int> &v1, vector<int> &v2)
{
for(int i=0; i<v1.size(); i++){
char lg;
if(v1[i]>=90.0){
lg = 'A';
}
else if(v1[i]>=80.0){
lg='B';
}
else if(v1[i]>=70.0){
lg='C';
}
else if(v1[i]>=65.0){
lg = 'D';
}
else{
lg='F';
}
v2.push_back(lg);
}
for (int i=0; i<v2.size(); i++)
cout << (char)v2[i] << " ";
}
int main()
{
vector<int> vect,vect1;
vect.push_back(95);
vect.push_back(85);
vect.push_back(75);
vect.push_back(65);
vect.push_back(55);
vect.push_back(70);
vect.push_back(10);
vect.push_back(20);
func(vect,vect1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.