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
Can someone help me with python
pishuonlain [190]

Answer:

here

Explanation:

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation.

7 0
2 years ago
Use ________ resolution when recording human speech in an audio file.
Reil [10]
<span>Use 8-bit resolution when recording human speech in an audio file.
</span><span>The </span>resolution<span> of </span>8 bits<span> can encode an analog input to one in 256 different levels. The reason why 256 levels is because 2^8</span><span> = 256.
</span>The analog to digital converter (ADC) <span> represents the analog input as a digital word.</span>
6 0
3 years ago
What would be a good hash code for a vehicle identification that is a string of numbers and letters of the form “9x9xx99x9xx9999
Hunter-Best [27]
I also want to ask a question recently i used a software named [url=http://www.videoconverterfactory.com/tips/youtube-to-flac.html]youtube to flac[/url] while after the conversion the size is to big. Why did this happen and how to solve without lose quality?
4 0
3 years ago
Drag each statement to the correct location.
VMariaS [17]

Answer:

(a)\ 222_{10} = DE_{16} --- True

(b)\ D7_{16} = 11010011_2 --- False

(c)\ 13_{16} = 19_{10} --- True

Explanation:

Required

Determine if the statements are true or not.

(a)\ 222_{10} = DE_{16}

To do this, we convert DE from base 16 to base 10 using product rule.

So, we have:

DE_{16} = D * 16^1 + E * 16^0

In hexadecimal.

D =13 \\E = 14

So, we have:

DE_{16} = 13 * 16^1 + 14 * 16^0

DE_{16} = 222_{10}

Hence:

(a) is true

(b)\ D7_{16} = 11010011_2

First, convert D7 to base 10 using product rule

D7_{16} = D * 16^1 + 7 * 16^0

D = 13

So, we have:

D7_{16} = 13 * 16^1 + 7 * 16^0

D7_{16} = 215_{10}

Next convert 215 to base 2, using division rule

215 / 2 = 107 R 1

107/2 =53 R 1

53/2 =26 R1

26/2 = 13 R 0

13/2 = 6 R 1

6/2 = 3 R 0

3/2 = 1 R 1

1/2 = 0 R1

Write the remainders from bottom to top.

D7_{16} = 11010111_2

<em>Hence (b) is false</em>

(c)\ 13_{16} = 19_{10}

Convert 13 to base 10 using product rule

13_{16} = 1 * 16^1 + 3 * 16^0

13_{16} = 19

Hence; (c) is true

7 0
2 years ago
How do online note-taking tools support students’ academic goals? Check all that apply.
MakcuM [25]

Answer:

all but 3

Explanation:

3 is strange and I need points sorry

5 0
3 years ago
Read 2 more answers
Other questions:
  • How can you recognize an unsecured wireless network?
    9·1 answer
  • To select all the text in a document, press ____.
    12·2 answers
  • Using the media as equipment for living. Explain how you would use some form of media to serve a purpose in your life—and what t
    6·2 answers
  • Which of these sites would need additional investigation to check for reliability?
    8·2 answers
  • 1. What type of malware is triggered by a specific condition, such as a specific date or a particular user account being disable
    6·1 answer
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • What is MVC architecture in relation to developing in web applications? How
    6·1 answer
  • imagine that you wanted to write a program that asks the user to enter in 5 grade values. the user may or may not enter valid gr
    12·1 answer
  • Terence creates software requirements specification (SRS) documents for various software development projects. In which phase of
    6·1 answer
  • 1. If an android phone is out of date or outdated and it requires an update. Explain the steps how I can update this phone.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!