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
Spam and i report
defon

Answer:

option d is the correct answer

8 0
3 years ago
Read 2 more answers
What is the function of a slide transition in a presentation program? A. It enables you to change the presentation layouts. B. I
Allushta [10]

I believe you answer is going to be A.

5 0
3 years ago
Which of the following is not a function of an operating system?
Semmy [17]

Answer:

C:carries out a specific task for the user

Explanation:

4 0
2 years ago
David bought 5.2 pounds of oranges for $1.20 per pound . how much did david spend ..............................................
Tcecarenko [31]

Answer:

David spent $6.24.

Explanation:

5.2 times 1.2

3 0
3 years ago
Which of the following statements about ip addresses is true?
Greeley [361]

This question is incomplete because it is lacking the necessary answer options, which I have provided below:

A. When data is sent between devices on the Internet, they identify each other with an IP address.

B. When a user signs up for an email address they must also sign up for an IP address.

C. IP addresses are assigned at the factory.

D. The IPV4 IP scheme allows for an unlimited number of devices to connect to the Internet.

So, given your question, the answer option which is true about IP addresses is: A. When data is sent between devices on the Internet, they identify each other with an IP address.

An IP address is an abbreviation for Internet protocol address and it can be defined as a unique number assigned to a computing device or other network devices, in order to differentiate each computing device from one another in an active network system.

Hence, an IP address is typically designed and developed to uniquely identify each computing device or network devices connected to the Internet or an active network system.

Basically, IP addresses are used anytime two or more computing devices send and receive data from one another over the Internet.

In conclusion, interconnected computing devices identify each other with an IP address when sending and receiving data over the Internet.

Read more: brainly.com/question/20629962

5 0
3 years ago
Other questions:
  • How do I turn of the noise canceling feature on my beats studio wireless?
    13·1 answer
  • [15 points] 3.2 Lesson Practice (holy marry mother of joseph)
    7·1 answer
  • Question 3.3. Which of the following is NOT a computer protocol? FTP SMTP ISP TCP
    11·1 answer
  • Why information technology is important in healthcare?
    13·1 answer
  • Intellectual property piracy has gotten a small boost from the increasing availability of counterfeit goods through Internet cha
    14·1 answer
  • What shoul i get, Airpods or a ps4 cooling fan ???
    7·2 answers
  • Sarah has entered data about football players from team A and team B in a worksheet. She enters names of players from team A wit
    9·2 answers
  • In python:
    8·1 answer
  • Service and software companies typically have a high return-on-assets ratio because they require lower blank as compared to manu
    11·2 answers
  • What kind of personal information are you comfortable sharing with others online? Why? What steps do you take to control how tha
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!