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]
2 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]2 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
Under which reflection(s) is the image of line m also a line?
lubasha [3.4K]

Answer:

c

Explanation:

5 0
3 years ago
Read 2 more answers
Select the correct answer.
Pachacha [2.7K]
B) Spreading the news about the incident response plan is not a good idea. If an incident was intentionally caused by a malicious person or group, knowing your response plan gives them information about how to make things worse.
3 0
3 years ago
Which of these conclusions supports the fact that Eclipse is categorized as an IDE?
Drupady [299]

Answer:

The user must specify the programming language he or she wants to use.

Explanation:

6 0
2 years ago
To prepare his book report on The Adventures of Tom Sawyer, Anand must research life on the Mississippi River in the 1800s. Whic
Viefleur [7K]
He should reread and find arcticles about life on the Mississippi River in the 1800s
3 0
3 years ago
Read 2 more answers
Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Per
SSSSS [86.1K]

Answer:

Person p1, p2, p3;

int m1, m2, m3;

p1 = new Person();

// assignment 1

m1 = p1.getMoney();

p2 = new Student();

// assignment 2

m2 = p2.getMoney();

p3 = new Employee();

// assignment 3

m3 = p3.getMoney();

//////////////////////////////////////////////////////////////////////////////////////////////

The reference to getMoney in assignment 3 is to the <em>Person</em> class.

Explanation:

Since Employee class didn't override Person class's getMoney() method, calling p3 with getMoney() will call Base class's (Person) getMoney() method.

6 0
2 years ago
Other questions:
  • How can users create a shortcut to favorite websites and store them in their browser?
    8·2 answers
  • 1. How does inertia affect a person who is not wearing a seatbelt during a collision? 
    14·2 answers
  • On a wireless router, what gives out IP addresses?<br> DHCP<br> DNS<br> WPA<br> WPS
    7·1 answer
  • Suppose that your application uses a loop that isn't producing the intended results. The best way to analyze what’s going on in
    13·1 answer
  • What does the opacity effect do
    8·2 answers
  • Who is a second-degree contact on a professional networking profile?
    12·1 answer
  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To ac
    14·2 answers
  • How does outlets generate electricity???
    15·1 answer
  • Case Study/Scenario: First, Julio clicks Tools from the Chrome menu on the toolbar. Next, he looks for Manage Add-Ons but can no
    9·1 answer
  • Your organization has an Active Directory domain. One of the users, Bill, should not have read access to a folder named Accounti
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!