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
What is the main role of LDAP?
NISA [10]

Answer:

Run directory services

Explanation:

LDAP (Lightweight Directory Access Protocol) is an open protocol used to access some information, information that is stored in a network, the information is organized hierarchical structure, we could find some data like names, directories, and telephone numbers.

With other options, we can find DHCP to assign IP addresses and to resolve IP addresses to host names, we have the DNS.

7 0
3 years ago
Where does the report footer section appear?
natka813 [3]

The report footer section appears at the bottom of the last page. The correct option is b.

<h3>What is a report footer section?</h3>

The report footer is that contain the report items. It is placed in the last page or the bottom of the report border. It is present only one time exactly at the last page.

Thus, the correct option is b, at the bottom of the last page.

Learn more about report footer section

brainly.com/question/13261774

#SPJ1

3 0
2 years ago
How is your day going?Technology affects the learning experience of students by helping them
Alex_Xolod [135]

Answer:

is this technology or

Explanation:

computer

5 0
3 years ago
Read 2 more answers
How can I make room in my schedule for a new activity?
timurjin [86]
Plan out your day and how long it will take you to do everything. then if you still don’t have time, see if there’s anything you can shorten in time
4 0
3 years ago
In a ____, a single communication path connects the network server, departmental servers, workstations, and peripheral devices.
nevsk [136]
In a bus network, a single communication path connects the network server,departamental servers, workstations, and peripheral devices.
c. bus network
4 0
3 years ago
Other questions:
  • Which of the following statements is false? a. Classes (and their objects) encapsulate, i.e., encase, their attributes and metho
    15·1 answer
  • Okay I need help. In the first picture, the black glasses, that was my vision last year 52:17 135 and my vision now is 52:15 135
    5·1 answer
  • In Windows 7/Vista, the information that establishes basic settings such as the location of the operating system and other key s
    7·1 answer
  • A motherboard has four DIMM slots; three slots are gray and the fourth is black. What type of memory is this board designed to u
    6·1 answer
  • In bankruptcy, most of a debtor’s assets will probably be used to repay unsecured debt
    9·1 answer
  • Assume that an array of integers named a that contains exactly five elements has been declared and initialized. Write a single s
    15·1 answer
  • Whixh options are available when a user modifies a recurring appointment. Check all that apply
    12·1 answer
  • Which of the following items can you locate in a document using the navigation pane? Choose the answer.
    10·1 answer
  • What is the meaning of FTTH
    9·2 answers
  • a data analyst is working with a spreadsheet that has very long text strings. rather than counting the characters themselves to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!