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
Why should we learn Ethereum? Explain.
Licemer1 [7]

Answer:

<h3><em>Ethereum Benefits</em></h3><h3><em>It has a large and committed global community and the largest ecosystem in blockchain and cryptocurrency. Wide range of functions. Besides being used as a digital currency, Ethereum can also process other financial transactions, execute smart contracts and store data for third-party applications.</em></h3>

Explanation:

<h3><em>Hope this helps and mark as a brianliest</em></h3>
7 0
2 years ago
A CPU has just been powered on and it immediately executes a machine code instruction. What is the most likely type of instructi
adell [148]

The most likely type of instruction that was executed by the CPU is: a jump instruction.

<h3>What is a CPU?</h3>

A central processing unit (CPU) can be defined as the main components of a computer because it acts as the brain of a computer and does all the processing and logical control.

This ultimately implies that, a central processing unit (CPU) is typically used by a computer to execute an instruction or set of instructions when powered on.

<h3>What is a jump instruction?</h3>

In Computer technology, a jump instruction specifies an offset to a new place in the program sequence when processing an instruction or set of instructions in a computer.

Read more on CPU here: brainly.com/question/5430107

3 0
2 years ago
When doing a Risk assessment, what is one of the most important things to do?
GaryK [48]

Answer:

Determine who might be harmed and how.

8 0
2 years ago
Read 2 more answers
What is the name of the variable in this code?
nata0808 [166]

Answer:

fav_color

Explanation:

4 0
2 years ago
Read 2 more answers
Cuales son los multiplos de un byte
GalinKa [24]

Answer:

I hope this works for u

Explanation:

1 GIGABYTE = 1Gb = 1024 Mb = 1.000.000.000 bytes. 1 TERABYTE = 1Tb = 1024 Gb = 1 billon de bytes. 1 PETABYTE = 1Pb = 1024 Tb = Mill billones de bytes. 1 EXABYTE = 1 Eb = 1024 Pb = 1 trillon de bytes.

Can I have a brainliest..

Puedo tener un brainliest

Plz :3

8 0
3 years ago
Other questions:
  • Which css property configures the capitalization of text?
    12·1 answer
  • You maintain an RODC running Windows Server 2012 R2 at a branch office, and you want Juanita, who has solid computer knowledge,
    13·1 answer
  • andy accidentally saved a file in the wrong folder. what is the quickest way to move the file? create a new file and save it in
    8·2 answers
  • A router is a device that addresses a packet on a network to the next router along the line. Under which layer of the OSI model
    5·1 answer
  • PLEASE HELP ME ASP<br> An ISDN carries a signal in digital form.<br><br> True<br><br> False
    12·2 answers
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • Diane is receiving a lot of unwanted e-mail. What steps can she take to reduce the amount of e-mail she receives?
    12·1 answer
  • Write a program that receives an character and displays its Unicode. Here is a sample run: Enter an character: E The Unicode for
    8·1 answer
  • _____ describes the layout of the screen. Block-based, Interface, Editor, Player
    11·2 answers
  • Estoy empezando a usar una pagina llamada source filmmaker, no se que apreté y quiero el menú de nuevo (en donde se ponen los mo
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!