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
Given the following data definition
Mashcka [7]

Answer:

Array + 36.

Explanation:

The array contains the address of the first element or the starting address.So to find the address of an element we to add the size*position to the starting address of the array.Which is stored in the variable or word in this case.

There are 9 elements in the array and the size of integer is 4 bytes.So to access the last element we have to write

array + 4*9

array+36

4 0
3 years ago
Which word is most appropriate to describe a laptop?
Thepotemich [5.8K]
The best word to describe a laptop would be Portable
8 0
3 years ago
A desktop computer (named workstation22) can’t connect to the network. A network card was purchased without documentation or dri
Lelechka [254]

Answer:

<em>The first step is to download the driver file from the Internet using  another Computer system, Copy the driver to a flash or CD then run the installation file on the Desktop Computer.</em>

Explanation:

<em>Driver files can be easily gotten from software sites online or from other secure websites, most times you have to pay for these driver files in some sites for secure and authentic download.</em>

<em>it is very necessary  that the user takes note of the exact system name, model and system architecture with respect to when downloading the driver file.</em>

4 0
4 years ago
What data type of data type would you use to represent the registration letter of a car​
miss Akunina [59]

Answer:

If it is just one letter, use a character, but if it is more than one letter, use a string (string of characters)

6 0
3 years ago
Read 2 more answers
Which of the following is a responsibility of CTSO membership?
Leni [432]

Answer:conducting yourself appropriately and professionally

Explanation:

2021 edg

7 0
2 years ago
Other questions:
  • Write a sentinel-controlled while loop that accumulates a set of integer test scores input by the user until negative 99 is ente
    8·1 answer
  • When the wires are connected to the terminals of the battery, what causes electric current in the circuit?
    15·1 answer
  • What is a DreamScape?<br> Explain <br> and give example (if you want)
    10·1 answer
  • 2. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The object
    14·1 answer
  • Let X and Y be two decision problems. Suppose we know that X reduces to Yin polynomial time. Which of the following statements a
    14·1 answer
  • What is the home page on a website?
    7·1 answer
  • Websites not only give us information, but they also inspire designers in their layouts, illustrations, images, typefaces, and c
    6·1 answer
  • How many questions do you have to answer before you can use direct messages on Brainly?
    13·2 answers
  • Can someone help plz, I’d really appreciate it
    7·1 answer
  • HELP PLSS!?? I’ve been stuck on this one for a while because I mess up too many time ! If you can solve this than I’ll give you
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!