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
In what way can a costume be deleted ?
alex41 [277]

Answer:

Clicking the "X" button towards the upper-right of each costume's icon in the Costume Pane will delete

Explanation:

5 0
3 years ago
The person or persons requesting the worksheet should supply their requirements in a _____ document
ziro4ka [17]
<span>The person or persons requesting the worksheet should supply their requirements in a requirements document. </span>
3 0
4 years ago
Purple gang or green gang?
zhuklara [117]

Answer:

Purple?

Explanation:

8 0
3 years ago
Read 2 more answers
Orphan record example?
Goryan [66]

Answer:

If we delete record number 15 in a primary table, but there's still a related table with the value of 15, we end up with an orphaned record. Here, the related table contains a foreign key value that doesn't exist in the primary key field of the primary table. This has resulted in an “orphaned record”.

4 0
3 years ago
What does a computer monitor look like when struck really hard?
sveticcg [70]

Answer:

physical damage could include broken glass or ink splotches on the display, distorted images, or discoloration

5 0
2 years ago
Other questions:
  • Assume that ip has been declared to be a pointer to int and that enrollment has been declared to be an array of 20 elements . As
    13·1 answer
  • In a linked chain implementation of a stack ADT the performance of popping am emtry from the stack is
    10·1 answer
  • If I dribbled on my motherboard and I used windex to clean off the spit would it still work ?
    11·2 answers
  • A software development company wants to reorganize its office so that managers and the Computer Programmers they supervise can b
    13·2 answers
  • When a customer makes an online hotel booking the database is updated by using
    9·2 answers
  • Which symbol would be used in a flowchart to represent a connection to another part of the flowchart on the same page
    15·1 answer
  • Add Try/Catch error checking To make sure that the user enters valid values in your program. To catch negative values passed to
    9·1 answer
  • To cope with the uncertainty about how their pages will be viewed, many web page designers opt to use _________ units, which are
    13·1 answer
  • I need a solution for this problem asap.
    7·1 answer
  • Upload your completed project including the following:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!