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
juin [17]
2 years ago
5

You are training to complete in a local 5K run. You record your time scores in minutes after completing seven practice runs. Wri

te a method to calculate and return the average score based on the data.
Computers and Technology
1 answer:
trapecia [35]2 years ago
3 0

Answer:

Following are the program to this question:

#include <iostream>//defining header file

using namespace std;

float Avg(float sum, int n)//defining method Avg that accepts float parameter

{

float average=sum/n;//defining float variable average that holds average value  

return average;//return average

}

int main()//defining main method

{

float ar[ ] = {24.1,24.5,24.4,23.8,28.2,29.1,27.4};//defining float array

float sum;//defining float variable sum

int n=7,i;//defining integer variable  

for (i = 0; i <n; i++)//defining loop to count total of array

{

sum=sum+ar[i];//add value in sum variable

}

cout<<"The average is: "<<Avg(sum,n);//use print method to call and print method return value

return 0;

}

Output:

The average is: 25.9286

Explanation:

In the above code, the float method "Avg" is declared, that accepts two parameters, that is "sum and n", inside the method, a float variable average is declared that divides and returns its values.

In the main method a float array "ar" is declared that holds values, in the next line, float variable "sum" and integer variable "n, j" is used.

In for loop, the "i" variable is used to add array values in the sum variable and pass into cout to call the "Avg" method and print its return value.

You might be interested in
The following code does not work as intended. It is meant to input two test grades and return the average in decimal format:
vredina [299]

Answer:

Type casting error

Explanation:

Logically, the program is correct and it is expected to return the average value. However, test1 and test2 are int values and when you applies any algebraic expression on Int, it will result into Int.

So, in this part (test1 + test2 )/2, two integers are adding and the final result is still an integer and this part will act as an integer even if you multiple or divide with any external number.

For example,

test1 = 4

test2 = 5

test1 + test2 = 9

Now, if you divide it by 2, it will still react as an integer portion. So, 9/2 would result in 4 instead of 4.5. All the calculation is done on the right side before assigning it to a double variable. Therefore, the double variable is still getting the int value and your program is not working correctly.

The solution is to typecast the "(test1 + test2 )/2" portion to double using Double.valueOf(test1 + test2)/2 ;

I have also attached the working code below.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 System.out.println("Hello World");

 Scanner scan = new Scanner (System.in);

 int test1 = scan.nextInt();

       int test2 = scan.nextInt();

       double average = Double.valueOf(test1 + test2)/2 ;

       System.out.println("Answer: " + average);

}

}

4 0
3 years ago
The it components of an erp system architecture include the hardware, software and the ________
natta225 [31]

The components of an ERP system architecture is made up of the hardware, software and the Data.

<h3>What is an ERP system?</h3>

Enterprise resource planning (ERP) is known to be a kind of  software that firms often use to handle or manage day-to-day business works such as accounting and others.

Note that The components of an ERP system architecture is made up of the hardware, software and the Data.

Learn more about  ERP system from

brainly.com/question/14635097

#SPJ12

6 0
2 years ago
When you enforce restrictions, what must you do immediately?
sweet [91]
The answer is A create a password
4 0
3 years ago
Read 2 more answers
A software team is setting an automation strategy and begins by identifying business processes that could benefit from automatio
mixas84 [53]

B is what I would guess.

5 0
2 years ago
Which sql keyword is used to retrieve a minimum value from an attribute in a table
konstantin123 [22]

The SQL keyword that is often used to retrieve a minimum value from an attribute in a table is the MIN function.

<h3>What is the MIN Function? </h3>

The MIN Function is known to be a group found under Excel Statistical functions.

Note that the MIN often return the minimum value in any list of arguments and as such The SQL keyword that is often used to retrieve a minimum value from an attribute in a table is the MIN function.

Learn more about SQL from

brainly.com/question/25694408

#SPJ11

5 0
2 years ago
Read 2 more answers
Other questions:
  • ________ returns the last character in a StringBuilder variable named strBuf? Select one: A. strBuf.charAt(strBuf.length() - 1)
    15·1 answer
  • Which is the most important reason you should properly cite information that you obtain from an Internet search? Question 2 opti
    8·1 answer
  • A content-managed site can be customized _____.
    12·1 answer
  • MTTF is a file format developed by Microsoft commonly used on Windows systems; it offers file security, large volume size, large
    11·1 answer
  • The default case is required in the switch selection statement.
    12·1 answer
  • Sketch a 2K x 32 memory built from 1K x 8 memory chips. Include control, address, and data line details, as well as any decoding
    5·1 answer
  • When you gather primary or secondary data, what part of the market information management process are you participating in?
    8·1 answer
  • Write any one method to delete a table in writer​
    11·1 answer
  • Please help with question
    14·1 answer
  • A constructor is just a special type of ______________ that instantiates an object from the class.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!