Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- /* Author: Alec Yurchenko
- * Date: 2/9/16
- * Assignment: Chapter 5 #14
- * Purpose: This program will read a text file of numbers and analyze the contents (High, low, amount, and average)
- */
- const int AMOUNT = 10;
- const double AMOUNTDOUB = 10.0;
- //Prints the numbers in the txt file
- void printNum(string name) {
- //Identifiers
- double numArray[AMOUNT];
- ifstream infile;
- //Opens txt file
- infile.open(name);
- for (int i = 0; i < AMOUNT; i++) {
- cout << numArray[i] << endl;
- }
- //Closes txt file
- infile.close();
- cout << endl;
- }
- int main() {
- //Identifiers
- string filename;
- double numbers[AMOUNT];
- //Title
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Number Analyzer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- //Asks user for file name
- cout << "What is the name of the file?" << endl;
- //Filename input
- cin >> filename;
- cout << endl;
- /*
- if (count != 0) {
- //Compares and checks for lowest possible alphabetically
- if (currentNum < lowNum && currentNum != -9999999999) {
- lowNum = currentNum;
- cout << count;
- }
- //Compares and checks for highest possible alphabetically
- if (currentNum > highNum && currentNum != -9999999999) {
- highNum = currentNum;
- cout << count;
- }
- avg = avg + currentNum;
- }
- else {
- //Reads first line of txt file
- infile >> currentNum;
- //Sets name as first and last name
- lowNum = currentNum;
- highNum = currentNum;
- cout << count;
- }
- //Reads out students in txt file
- cout << currentNum << endl;
- infile >> currentNum;
- */
- /*
- //Final statement; Gives first and last students in line
- cout << endl;
- cout << "Lowest Number: " << lowNum << endl;
- cout << "Highest Number: " << highNum << endl;
- cout << "Average: " << avg << endl;
- */
- printNum(filename);
- cout << "Amount of Numbers: " << AMOUNT << endl << endl;
- return 0;
- }
- /*
- 7. Number Analysis Program Write a program that asks the user for a file name.
- Assume the file contains a series of numbers, each written on a separate line.
- The program should read the contents of the file into an array and then display the following data:
- • The lowest number in the array
- • The highest number in the array
- • The total of the numbers in the array
- • The average of the numbers in the array
- If you have downloaded this book’s source code from the companion Web site, you will find a file named numbers.txt in the Chapter 07 folder.
- You can use the file to test the program. (The companion Web site is at www.pearsonhighered.com/gaddis .)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement