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]
4 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]4 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
If you delete a shortcut from your desktop, have you also deleted the original file?
svet-max [94.6K]

Answer:

no

Explanation:

it just deletes the icon.

4 0
3 years ago
Read 2 more answers
How do access the dictionary and thesaurus in Word?
horrorfan [7]
Click the FILE tab. Click Options in the list on the left side of the screen. On the WordOptions dialog box, click Proofing in the list of options on the left. 
3 0
3 years ago
Read 2 more answers
How do engineers communicate their design ideas?
Nady [450]

Answer:

Explanation:

Mechanical engineers give Presentations when they work on projects and Proposals. Often, professional Presentations require you to verbally and graphically present preliminary designs to colleagues.

Hope this helped!!!

5 0
4 years ago
Which of the following organizes the commands available in tabs and groups?
xxMikexx [17]

Answer: Ribbon

Explanation:

5 0
3 years ago
If we are transferring data from a mobile device to a desktop and receive an error message that the mobile device has stopped co
Alona [7]

Answer should probably be B. I don’t think you’d need an application to transfer data, and the computer wouldn’t even tell you if the data couldn’t transfer if you have the wrong cable head. It wouldn’t even be connected.

6 0
3 years ago
Other questions:
  • Why are computer programs so much longer now than they were in the late 1980?
    8·1 answer
  • What is the difference between 1080p and 2k?
    14·1 answer
  • Operating systems the most common form Microsoft windows in Mac OS discuss the similarities and differences between which two sy
    13·1 answer
  • Which one of the following oscilloscope controls is used to move the trace up and down the screen vertically
    14·1 answer
  • Professional photography is a competitive job field. <br> true <br> false
    12·2 answers
  • Specify either "Write Through" or "Write Back" as the policy which best corresponds to each of the conditions below.
    8·1 answer
  • True false) cad means computer aided manufacturing​
    10·1 answer
  • What is the difference between player-centric game design and designer-centric game design? How does a player-centric game assis
    7·1 answer
  • Why are computer manufacture constantly releases fast computer and do user benefit from ths speed
    9·1 answer
  • What is the dark web and what is the .onion domain
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!