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
Anon25 [30]
2 years ago
14

Number Analysis Program: Write a program that reads data from the text file numbers.txt. Assume the file contains a series of nu

mbers, each written on a separate line. The program should read the numbers from the file and store them into the array numbers. Then program should display the lowest value, the highest value in the array. Also calculate and display the average of these values.
Computers and Technology
1 answer:
diamong [38]2 years ago
8 0

Answer:

See Explaination

Explanation:

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

// namespace std

using namespace std;

// start of the main function

int main() {

// setting precision to 2 decimal point

cout << fixed << setprecision(2) << endl;

// variable declration

int i, count = 0;

int min, max, value, arr[100];

double sum = 0;

double Avg;

// file object creation

ifstream infile;

string file;

// input the file name to read

cout << "Please enter the name of the file to read numbers for Number "

"Analysis program "

<< endl;

getline(cin, file);

infile.open(file.c_str());

// check if file exist or not

// and loop untill you get correct file name

// if you do not want to loop again and again then

// simply return 0; from code

if (infile.fail()) {

cout << "Error opening the file." << endl;

return 0;

// cout << "Please enter the name of the file to read numbers for Number "

// "Analysis program "

// << endl;

// getline(cin, file);

// infile.open(file.c_str());

}

// start reading the data from the file

while (infile >> value) {

arr[count] = value;

count++;

}

// initialize min max to arr[0]

min = max = arr[0];

// find the lowest element

for (i = 0; i < count; i++) {

if (arr[i] < min) {

min = arr[i];

}

}

for (i = 0; i < count; i++) {

// find the highest element

if (arr[i] > max) {

max = arr[i];

}

}

for (i = 0; i < count; i++) {

// calculate sum

sum = sum + arr[i];

}

Avg = sum / count;

// display output

cout << "The highest value is " << max << endl;

cout << "The lowest value is " << min << endl;

cout << "The sum of the numbers is " << sum << endl;

cout << endl;

cout << "The average of the numbers is " << Avg << endl;

return 0;

} // end of the main program

You might be interested in
What are two examples of ways an electronic record may be distributed to others?
Karolina [17]

Answer:

Way 1. Email, Way 2. Publish on Internet

Explanation:

8 0
3 years ago
ASAP BRAINLIEST!!!
Hoochie [10]

Answer:

none

Explanation:

6 0
3 years ago
In python please:
Vikki [24]

Answer:

"

if 'marsupial' in dictionary:

   del dictionary['marsupial']

else:

   print("The key marsupial is not in the dictionary")

"

Explanation:

So you can use the keyword "in" to check if a certain key exists.

So the following code:

"

if key in object:

   # some code

"

will only run if the value of "key" is a key in the object dictionary.

So using this, we can check if the string "marsupial' exists in the dictionary.

"

if 'marsupial' in dictionary:

   # code

"

Since you never gave the variable name for the variable that references a dictionary, I'm just going to use the variable name "dictionary"

Anyways, to delete a key, there are two methods.

"

del dictionary[key]

dictionary.pop(key)

"

Both will raise the error "KeyError" if the key doesn't exist in the dictionary, although there is method with pop that causes an error to not be raised, but that isn[t necessary in this case, since you're using the if statement to check if it's in the dictionary first.

So I'll just use del dictionary[key] method here

"

if 'marsupial' in dictionary:

   del dictionary['marsupial']

else:

   print("The key marsupial is not in the dictionary")

"

The last part which I just added in the code is just an else statement which will only run if the key 'marsupial' is not in the dictionary.

3 0
2 years ago
In which situations would it be most helpful to filter a form? Check all that apply.
Paladinen [302]

Answer: hey did you find the answer? Do you mind telling me it?

Explanation:

8 0
3 years ago
If you know the unit prices of two different brands of an item you are better able to
vitfil [10]

Answer:

TO UNDERSTAND TO ITS VALUES AND ITS  FEATURES

Explanation:

4 0
3 years ago
Other questions:
  • What is the differnces between dark and middle ages of computer?​
    9·1 answer
  • This activity will help you meet these educational goals:
    7·2 answers
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • You asked your colleague to provide feedback on a blog post you recently wrote. When they sent you their feedback, they made edi
    10·1 answer
  • A palindrome is a string that reads the same both forward and backward. For example, the string madam is a palindrome. Write a p
    13·1 answer
  • <br> Help me please I need the correct answe
    10·1 answer
  • A10:A20 Refer to values in
    8·1 answer
  • Did it surprise you to discover that the Sun is actually a star in the middle of its life cycle? Why or why not?
    8·1 answer
  • 3.5 code practice question 1
    5·2 answers
  • Which of the following tiny computer apps is designed to be useful but could cause more harm than good?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!