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
svet-max [94.6K]
3 years ago
7

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. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8.

Computers and Technology
1 answer:
Anestetic [448]3 years ago
3 0

Answer:

Here is for loop that sets sumExtra to the total extra credit received. I am writing a program in C++

for(i = 0; i <= testGrades.size() - 1; i++){

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

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

Explanation:

The complete program is:

#include <iostream> //to use input output functions

#include <vector> //to use vectors

using namespace std; //to identify objects like cin cout

int main() { //start of main function

const int NUM_VALS = 4; // sets the value of NUM_VALS as a constant to 4

vector<int> testGrades(NUM_VALS); // initialize the vector of int (integer) type

int i = 0; // i is initialzed to 0

int sumExtra = 0; //stores the total extra credit

testGrades.at(0) = 101; //sets 101 at first position in vector

testGrades.at(1) = 83; //sets value 83 at second position

testGrades.at(2) = 107; //sets value 107 at third position

testGrades.at(3) = 90; //sets value 90 at fourth position

for(i = 0; i <= testGrades.size() -1; i++){ //loop iterate through each value of in a vector testGrades

  if(testGrades.at(i) > 100){ // if the value in a vector exceeds 100

      sumExtra = sumExtra + (testGrades.at(i) - 100);   } } //computes total extra credit

cout << "sumExtra: " << sumExtra << endl;} //displays the value of computed total extra credit in output

The loop works as follows:

In the first iteration the value of vector testGrades at(i) is at(0) = 101.

if statement checks if this value/element is greater than 100. This is true as 101 > 100. So sumExtra = sumExtra + (testGrades.at(i) - 100); statement is executed in which 100 is subtracted from that element and the result is added to the sumExtra. sumExtra is initialized to 0 so the value of sumExtra becomes: 0+ 101 - 100= 1 So the value of sumExtra = 1

In the second iteration the value of i = 1 and it is positioned at 2nd value of vector testGrades i.e. 83. Then if statement checks if this value/element is greater than 100. This is false as 83 < 100. So the value of sumExtra = 1

In the third iteration the value of i = 2 and it is positioned at 3rd value of vector testGrades i.e. 107. Then if statement checks if this value/element is greater than 100. This is true as 107 > 100.

sumExtra = sumExtra + (testGrades.at(i) - 100); statement is executed in which 100 is subtracted from that element and the result is added to the sumExtra

sumExtra is 1 so the value of sumExtra becomes: 1+ 107 - 100= 8 So the value of sumExtra = 8

In fourth iteration  the value of i = 3 and it is positioned at 4th value of testGrades vector i.e. 90. Then the if statement checks if this element is greater than 100. This is false as 90 < 100. So the value of sumExtra remains 8.  

Finally the loop breaks as the value of i becomes 4. So the output is 8.

You might be interested in
When troubleshooting firewalls, you should never attempt to repeat the problem because you could do more damage. T/F
Zinaida [17]

Answer:

TRUE

Explanation:

the given statement is correct hence TRUE

troubleshooting is problem solving often applied to repair failed product .

Firewall is used for network security for the computer is monitors and controls the incoming and outgoing network traffic.

Basically what Firewall do is it create barrier between trusted networks and not trusted network.

8 0
3 years ago
You will start by doing a bit of research on viewfinders and LCD displays on digital cameras. After you feel that you have an un
Lemur [1.5K]

Answer:

SOMEBODY ANSWER IT

Explanation:

JESUS C

3 0
3 years ago
Why is the song Twinkle Twinkle Little Star an example of ternary form?
Bogdan [553]

Answer:

p it has a three-part musical form it has a repeating section and a following section this makes and this makes it a ternary form

5 0
3 years ago
What is another word for: a location in memory that contains a value? A. integer B. Boolean C. variable D. float PLEASE HELP URG
german

Answer:

A

Explanation:

Integer because it contains digits that can undergo calculation within the memory

5 0
2 years ago
Choose the answer that best completes the
Fiesta28 [93]

Answer:

the information processing cycle

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Ben is writing web page content on a newly launched gaming gadget. He has to use hyperlinks to help visitors navigate to web pag
    11·1 answer
  • Which of the following is not a network connection LAN WAN SAN MAN
    6·1 answer
  • What is the purpose of a scatter plot introduction to computer applications
    6·2 answers
  • Need this!!
    11·2 answers
  • True or False
    10·2 answers
  • Which of the following combines something you know, such as a password, with something you are (a biometric device such as a fin
    13·1 answer
  • All of the following are organization habits except:
    10·1 answer
  • How to delete Brainly account ?​
    12·1 answer
  • What critical-thinking tool is being used when asking the question, "Is there a large enough scope of
    10·1 answer
  • What java syntax allows me to take user input.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!