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
Travka [436]
3 years ago
14

Write a program to read 10 integers from an input file and output the average, minimum, and maximum of those numbers to an outpu

t file. Take the name of the input file and output file from the user. Make sure to test for the conditions 1. if the count of numbers is less than 10 in the input file, then your average should reflect only for that many numbers 2. if the count of numbers is more than 10 in the input file, then your average should reflect only for ten numbers only.
Computers and Technology
1 answer:
umka21 [38]3 years ago
3 0

Answer:

#include <iostream>

#include <climits>

#include<fstream>

using namespace std;

int main ()

{

fstream filein;

ofstream fileout;

string inputfilename, outputfilename;

// ASk user to enter filenames of input and output file

cout<<"Enter file input name: ";

cin>>inputfilename;

cout<<"Enter file output name: ";

cin>>outputfilename;

// Open both file

filein.open(inputfilename);

fileout.open(outputfilename);

// Check if file exists [Output file will automatically be created if not exists]

if(!filein)

{

cout<<"File cannot be opened"<<endl;

return 0;

}

int min = INT_MAX;

int max = INT_MIN; //(Can't use 0 or any other value in case input file has negative numbers)

int count = 0; // To keep track of number of integers read from file

double average = 0;

int number;

// Read number from file

while(filein>>number)

{

// If min > number, set min = number

if (min>number)

{

min = number;

}

// If max < number. set max = number

if(max<number)

{

max = number;

}

// add number to average

average = average+number;

// add 1 to count

count+=1;

// If count reaches 10, break the loop

if(count==10)

{

break;

}

}

// Calculate average

average = average/count;

// Write result in output file

fileout<<"Max: "<<max<<"\nMin: "<<min<<"\nAverage: "<<average;

// Close both files

filein.close();

fileout.close();

return 0;

}

You might be interested in
The order in which statements are executed during a program run. Answer 1 The first part of a compound statement begins with a k
Elodia [21]

This is an incomplete question. The question I was able to find as the complete one is as follows:

Match the following terms and definitions

  • stack diagram
  • flow of execution
  • local variable
  • function call
  • header

-The order in which statements are executed during a program run. Answer 1

-The first part of a compound statement, begins with a keyword and ends with a colon ( : ) Answer 2

-A statement that executes a function. It consists of the name of the function followed by a list of arguments enclosed in parentheses. Answer 3

-A variable defined inside a function that can only be used inside its function. Answer 4

-A graphical representation of functions, their variables, and the values to which they refer. Answer 5

<h2>Answer with Explanation:</h2>
  1. Flow of Execution: The order in which statements are executed during a program run. This is done from top to bottom which means the statement written first is executed first.
  2. Header: The first part of a compound statement, begins with a keyword and ends with a colon ( : ). A header is given usually at the top. It can contain libraries being used in the program body.
  3. Function Call:  A statement that executes a function. It consists of the name of the function followed by a list of arguments enclosed in parentheses.  It is used to perform specific functions that are defined before calling a function. A program can be called as many times as needed.
  4. Local Variable: A variable defined inside a function that can only be used inside its function. A local variable with same name can be used inside two different functions but they are needed to be defined first.
  5. Stack Diagram: A graphical representation of functions, their variables, and the values to which they refer. It is the tool for knowing the state of program at the time given.

i hope it will help you!

                   

8 0
3 years ago
When creating envelopes, how will you adjust the layout?
Burka [1]
It D because I hade this too so it is D
4 0
3 years ago
Read 2 more answers
The New option is found in the ...............tab.​
morpeh [17]

in your notes books and in your vopy

3 0
3 years ago
Read 2 more answers
WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST
Alchen [17]

The simple interset program is a sequential program, and does not require loops and conditions

The simple interset program in Python, where comments are used to explain each line is as follows:

#This gets input for the principal amount

P = int(input("P = "))

#This gets input for the rate

R = int(input("R = "))

#This gets input for the number of years

N = int(input("N = "))

#This calculates the simple interest

I = P * R * T * 0.01

#This prints the simple interest

print("Simple Interest =",I)

Read more about simple interest at:

brainly.com/question/2294792

7 0
2 years ago
I Previous
Tcecarenko [31]

Answer:

D. Change the def to def area (width, height = 12)

Explanation:

Required

Update the function to set height to 12 when height is not passed

To do this, we simply update the def function to:

def area (width, height = 12)

So:

In boxlarea = area (5,2), the area will be calculated as:

area = 5 * 2 = 10

In box2area = area (6), where height is not passed, the area will be calculated as:

area = 6 * 12 = 72

5 0
2 years ago
Other questions:
  • To keep from overwriting existing fields with your Lookup you can use the ____________ clause.
    14·2 answers
  • Which of these forms of multimedia would most likely contain both music and text:
    14·1 answer
  • What best describes "broadband access"? a. broadband access is a specific term used to describe the delivery of one-way televisi
    5·1 answer
  • Which type of microphone uses two metal plates?
    7·1 answer
  • Your it department enforces the use of 128-bit encryption on all company transmissions. your department also protects the compan
    13·1 answer
  • Hi, I just have a few questions from my digital tech assignment.
    14·2 answers
  • From Blown to Bits why is it important to know what children are doing on the Web Tonight?
    7·1 answer
  • Wearables, video playback and tracking devices can help athletes because
    15·1 answer
  • How do you describe Microsoft excel?
    13·1 answer
  • True or False? The background color block should be inserted after all the images are added.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!