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
Explain the effects of disposing electronic equipments to the environment ​
Rina8888 [55]

Answer:

When electronics are improperly disposed and end up in landfills, toxic chemicals are released, impacting the earth's air, soil, water and ultimately, human health.

5 0
3 years ago
Your client expresses that they want their new website to have a responsivedesign with consistent coding. They are concerned wit
tresset_1 [31]

D

Explanation:

Because that's the one that works good together

5 0
3 years ago
There are spoilers that doctor brenner is back in stranger things four and eleven is going back. Do you believe it or no? Make s
Svetlanka [38]
Wait Doctor Brenner is coming back?!?! Wait omg when??
5 0
3 years ago
Indicate whether the following actions are the actions of a person who will be a victim, or will not be a victim, of phishing at
Zepler [3.9K]

Answer:

Phishing Victim

Explanation:

Replying to this email could make you a victim of a phishing scam. Phishing attacks are common challenges on security that internet users are faced with. It could lead to others getting hold of sensitive information like your password or bank details. email is one way the hackers used to get this information. replying to such an email could lead one to an unsecure website where information could be extracted

4 0
3 years ago
What project started the development of inter-network connections using tcp/ip that has evolved in to the internet today
Vinvika [58]
The <span>ARPANET </span><span>project started the development of inter-network connections using TCP/IP that has evolved in to the internet today</span>
4 0
3 years ago
Other questions:
  • Which best describes a VPN?
    14·2 answers
  • Google's stated mission is to: establish itself as the most valuable media company in the world. organize the world's informatio
    11·1 answer
  • Which of the following statements about certificates is true?
    14·2 answers
  • A Network Systems employee set up a network-wide password system in which other employees log in to access their work. Which tas
    6·2 answers
  • Select the correct answer. Which of these statements is an explorer most likely to make?​
    6·1 answer
  • Variable-length entities. fixed-length entities. data structures that contain up to 10 related data items. used to draw a sequen
    14·1 answer
  • Hey guys i need help again on coding
    7·1 answer
  • State three reasons why users attach speakers to their computer​
    8·1 answer
  • Provide examples of how information technology has created an ethical dilemma that would not have existed before the advent of I
    7·1 answer
  • What is the best response to cyberbullying?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!