1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mariana [72]
3 years ago
10

Vector testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full cr

edit is 100, so anything over 100 is extra credit.
Computers and Technology
1 answer:
astraxan [27]3 years ago
8 0

<em>Question:</em>

<em>Vector testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8. </em>

<em>#include <iostream> </em>

<em>#include <vector> </em>

<em>using namespace std;  </em>

<em>int main() { </em>

<em>   const int NUM_VALS = 4; </em>

<em>   vector<int> testGrades(NUM_VALS); </em>

<em>   int i = 0; </em>

<em>   int sumExtra = -9999; // Assign sumExtra with 0 before your for loop  </em>

<em>   testGrades.at(0) = 101; </em>

<em>   testGrades.at(1) = 83; </em>

<em>   testGrades.at(2) = 107; </em>

<em>   testGrades.at(3) = 90; </em>

<em>    /* Your solution goes here  */ </em>

<em>   cout << "sumExtra: " << sumExtra << endl; </em>

<em>   return 0; </em>

<em>}</em>

Answer:

Replace /* Your solution goes here  */  with the following lines of code

sumExtra = 0;

do{

if(testGrades.at(i) > 100){

sumExtra = sumExtra + (testGrades.at(i) - 100);

}

i++;

}

while(i<NUM_VALS);

Explanation:

In the complete question posted,  the variables sumExtra and i have already been declared an initialized.

So, the first thing we do in the solution is:

set  sumExtra to 0 using <em>sumExtra = 0; </em>

Then iterate through vector testGrades using i as the iterating variable

Here, I made used of a do while loop and the explanation is as follows:

do{

This line checks if current element of the vector is greater than 100

if(testGrades.at(i) > 100){

If yes, the extra digits above 100 is added to the sumExtra

sumExtra = sumExtra + (testGrades.at(i) - 100);

}

The counter is increased, here

i++;

}

The loop is continued while the iterating variable i is less than NUM_VALS which is 4

while(i<NUM_VALS);

You might be interested in
Instant messaging is commonly referred to as
melomori [17]
Chat, IM, in real-time
7 0
4 years ago
The Monte Carlo (MC) Method (Monte Carlo Simulation) was first published in 1949 by Nicholas Metropolis and Stanislaw Ulam in th
Eddi Din [679]

Answer:

can you give more detail

Explanation:

3 0
3 years ago
________ involves the use of the internet to steal important information.
Ivenika [448]
Phishing involves the use of the Internet to steal important information.
Shoulder surfing refers to people spying on other people while they are using an ATM. Skimming a credit card refers to thieves using a device in ATMs to steal information from cards. Dumpster diving refers to picking trash from dumpsters.
5 0
3 years ago
Write an application for Cody’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery
Firdavs [7]

An application for Cody’s Car Care:

#include <iostream>

#include <string>

#include <vector>

using namespace std;

int main()

{

vector<string>stroptions(4);

stroptions[0] = "Oil Change";

stroptions[1] = "Tire Rotation";

stroptions[2] = "Battery Check";

stroptions[3] = "Brake Inspection";

 

vector<int> intprices(4);

intprices[0] = 45;

intprices[1] = 22;

intprices[2] = 15;

intprices[3] = 10;

 

int option;

cout<< "Welcome to Joe's Car Care Shop!" <<endl;

cout<< "Choose a service from our menu:" <<endl;

for(int i = 1; i<= 4; i++)

{

  cout<< "#" <<i<< ": " <<stroptions[i-1] <<endl;

}

cout<< "Choice: ";

bool loop = true;

while(loop)

{

  loop = false;

  cin>> option;

 switch(option)

  {

   case 1:

     cout<< "\nA " <<stroptions[option-1] << " will be: $" <<intprices[option -1] <<endl;

     break;

   case 2:  

     cout<< "\nA " <<stroptions[option -1] << " will be: $" <<intprices[option -1] <<endl;

     break;

   case 3:

     cout<< "\nA " <<stroptions[option -1] << " will be: $" <<intprices[option -1] <<endl;

     break;

   case 4:

     cout<< "\nA " <<stroptions[option -1] <<" will be: $" << intprices[option -1] <<endl;

      break;

    default:

     cout<< "\nYou entered an invalid item! Try again!" <<endl;

     loop = true;

     break;

 }

}

}

3 0
3 years ago
Kali, a Python programmer, is using the turtle module to write the word "hello." Which code should she use to indicate the locat
Sever21 [200]

Answer:

a) penup()

goto(-100, 200)

pendown()

Explanation:

The python program to indicate the location to begin writing the word can be

penup()

goto(-100, 200)

pendown()

# in python is use to add comment so it is incorrect.

all other option does not have correct syntex.

4 0
3 years ago
Read 2 more answers
Other questions:
  • How does the team know what to work upon during the iteration
    6·1 answer
  • Binary is best interpreted by a computer because?
    8·2 answers
  • Stuart wants to delete some text from a slide. What should Stuart do?A. From the Review tab, choose Highlight text and then pres
    7·2 answers
  • Which document would most likely be written in an informal style?
    12·1 answer
  • How do you go about inserting additional worksheets into a workbook?
    15·1 answer
  • The ______ printers are the most popular type of printer in small office/home office and large office environments.
    5·1 answer
  • During the design phase, development teams translate the requirements into?
    11·1 answer
  • What is the most efficient<br> form of transportation we<br> have?
    13·2 answers
  • Problem Statement − Suppose the problem statement at hand is to contain the attrition that happens in companies worldwide. High
    8·1 answer
  • What wireless security technology contains significant flaws and should never be used?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!