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
kolbaska11 [484]
3 years ago
11

Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full cre

dit 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:
Tresset [83]3 years ago
5 0

Answer: The program in c++ language for the given scenario is given below.

#include <iostream>

using namespace std;

int main() {    

int sumExtra = 0, len;

int testGrades[len];

// this input determines the length of the array

cout<<"Enter the number of grades to be entered : ";

cin>>len;

 

for(int j=0; j<len; j++)

{

    cout<<endl<<"Enter grade "<<j+1;

    cin >> testGrades[j];

}

 

for(int i=0; i<len; i++)

{

    if(testGrades[i] > 100)

        sumExtra =  sumExtra + ( testGrades[i] - 100 );

    else

        continue;

}

cout<<endl<<"Sum of extra credit = " << sumExtra;

return 0;

}

Explanation:

Header files are imported for input/ output alongwith the namespace.

#include <iostream>

using namespace std;

All variables and array is declared of type integer.

int sumExtra = 0, len;

int testGrades[len];

User is prompted for the number of grades to be entered. This number is stored in variable len, which determines the length of the array, testGrades.

testGrades[len];

Using for loop, grades are entered for each index.

for(int j=0; j<len; j++)

{

     cout<<endl<<"Enter grade "<<j+1;

     cin >> testGrades[j];

}

Using another for loop and if-else statement, if the grade > 100, extra credit is added and sum is stored in the variable, sumExtra.

for(int i=0; i<len; i++)

{

     if(testGrades[i] > 100)

          sumExtra =  sumExtra + ( testGrades[i] - 100 );

     else

          continue;

}

This is followed by displaying the message with sum of the extra credit.

The main() function has the return type int. Hence, integer 0 is returned at the end of the program.

In the above, endl keyword is used to insert break line. The following message will be displayed on the new line. This is another alternative for the newline character, \n.

The given program does not implements a class since the logic is simple. Also, the question does not specify that the class and object should be used.

You might be interested in
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
Xelga [282]

Answer:

import java.util.Scanner;

public class ListOfIntegers {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user input

 Scanner input = new Scanner(System.in);

 // Prompt the user for the number of integers they want to enter

 System.out.print("Enter the number of integers : ");

 // Get and store the number of integers entered by user

 int n = input.nextInt();

 System.out.println();

 // Create an array to hold the integers

 // The array has the same length as the number of integers

 int[] numbers = new int[n];

 // Create a loop that asks the user to enter all integers

 // At each cycle of the loop, save the entered integer into the array

 for (int i = 0; i < n; i++) {

  System.out.print("Enter number " + (i + 1) + " : ");

  numbers[i] = input.nextInt();

  System.out.println();

 }

 // Prompt the user for the lower bound

 System.out.print("Enter the lower bound : ");

 // Get and store the lower bound in a variable

 int lowerbound = input.nextInt();

 System.out.println();

 // Prompt the user for the upper bound

 System.out.print("Enter the upper bound : ");

 // Get and store the upper bound in a variable

 int upperbound = input.nextInt();

 System.out.println();

 System.out.println("OUTPUT :: ");

 // Create a loop to cycle through the array of numbers.

 // At each cycle, check if the array element is within range.

 // If it is within range, print it to the console

 for (int j = 0; j < numbers.length; j++) {

  if (numbers[j] >= lowerbound && numbers[j] <= upperbound) {

   System.out.print(numbers[j] + " ");

  }

 }

}

}

Explanation:

Please go through the comments in the code for more readability and understanding. The source code file has been attached to this response. Kindly download the file to get a better formatting of the code.

Hope this helps!

Download java
7 0
4 years ago
Read 2 more answers
The base fine is $35.0 and the hourly rate is $10.0 per hour. The parking meter is in minutes and it is rounded up to hours for
mr_godi [17]

Answer:$45

Explanation:I am assuming it has been an hour? $35 base fine and $10 for hourly rate.

5 0
4 years ago
Understanding the intended audience of a media piece will help the reader :
Sati [7]

Answer:

It depends

Explanation:

..

6 0
3 years ago
Suppose that actions can have arbitrarily large negative costs; explain why this possibility would force any optimal algorithm t
yuradex [85]

The reason why this cost is going to force the optimal algorithm to explore the entire state space is the fact that large negative costs can cause concurrent automatically for optimal solutions.

<h3>The step to take with a negative cost</h3>

Now if there is the existence of a large negative cost for each of these actions, the optimal algorithm is going to try an exploration of the whole space state.

The reason for this would be the fact that the route that has the least consequences would be better of.

Read more on negative cost here: brainly.com/question/7143854

3 0
3 years ago
PLEASE HELP 100!!!!!!!!!!!!!!!!!!
Shalnov [3]

I think it is very accurate. Because how it talks about what happened and why. Yes historical accuracy is important in films and in theatre productions because they need the right information. How it looked like. They react weirdly. The influence is that people are glad to see it and could help them get over some of there fears.Theatre actors influence people to try newer things. They actor uses prop to make them look better.The result is people laugh.Nnbecause the props were horrible.

8 0
4 years ago
Read 2 more answers
Other questions:
  • Who invented google​
    14·1 answer
  • Can someone help me
    8·1 answer
  • A customer asks you over the phone how much it will cost to upgrade memory on her desktop system to 16 GB. She is a capable Wind
    8·1 answer
  • How can I do a project with a model on the steam machine?
    14·1 answer
  • A) Suppose a computer has an instruction pipeline with 4 phases. How many cycles (if there are no delays) would it take to compl
    13·1 answer
  • Which of the following factors will have the greatest impact on your credit score? I. Length of Credit History II. Payment Histo
    6·2 answers
  • What font family is Times New Roman an what font family is Arial?
    9·2 answers
  • What is considered an important ethical consideration when working with families
    13·1 answer
  • Please tell fast plzzzzzz. ​
    10·2 answers
  • Code used when creating a hyperlink to a specific part of the same page.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!