Question

Write a program( using only and ) that reads in a datafile of an unknown quantity...

Write a program( using only and ) that reads in a datafile of an unknown quantity of integers, and prints out the following information: The number of values in the dataset The maximum value The minimum value The average of the values

Note: Please only answer this if your using ONLY #include and #include . DO NOT USE ANY OTHERS! only using c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <fstream>

using namespace std;

int main() {
    char fileName[100];
    cout << "Enter file name: ";
    cin >> fileName;
    ifstream in(fileName);
    if (in.is_open()) {
        int min = 0, max = 0, avg = 0, count = 0, num;
        while (in >> num) {
            if (count == 0) {
                min = num;
                max = num;
            }
            ++count;
            if (num > max) max = num;
            if (num < min) min = num;
            avg += num;
        }
        cout << "Minimum number is " << min << endl;
        cout << "Maximum number is " << max << endl;
        cout << "Count is " << count << endl;
        cout << "Average is " << avg/(double)count << endl;
        in.close();
    } else {
        cout << fileName << " does not exists!" << endl;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a program( using only and ) that reads in a datafile of an unknown quantity...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT