Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. /* Author: Alec Yurchenko
  8. * Date: 2/9/16
  9. * Assignment: Chapter 5 #14
  10. * Purpose: This program will read a text file of numbers and analyze the contents (High, low, amount, and average)
  11. */
  12.  
  13. const int AMOUNT = 10;
  14. const double AMOUNTDOUB = 10.0;
  15.  
  16. //Prints the numbers in the txt file
  17. void printNum(string name) {
  18. //Identifiers
  19. double numArray[AMOUNT];
  20. ifstream infile;
  21.  
  22. //Opens txt file
  23. infile.open(name);
  24.  
  25. for (int i = 0; i < AMOUNT; i++) {
  26. cout << numArray[i] << endl;
  27. }
  28.  
  29. //Closes txt file
  30. infile.close();
  31.  
  32. cout << endl;
  33. }
  34.  
  35. int main() {
  36. //Identifiers
  37. string filename;
  38. double numbers[AMOUNT];
  39.  
  40. //Title
  41. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  42. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Number Analyzer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  43. cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  44.  
  45. //Asks user for file name
  46. cout << "What is the name of the file?" << endl;
  47.  
  48. //Filename input
  49. cin >> filename;
  50.  
  51. cout << endl;
  52.  
  53. /*
  54. if (count != 0) {
  55. //Compares and checks for lowest possible alphabetically
  56. if (currentNum < lowNum && currentNum != -9999999999) {
  57. lowNum = currentNum;
  58. cout << count;
  59. }
  60.  
  61. //Compares and checks for highest possible alphabetically
  62. if (currentNum > highNum && currentNum != -9999999999) {
  63. highNum = currentNum;
  64. cout << count;
  65. }
  66.  
  67. avg = avg + currentNum;
  68. }
  69.  
  70. else {
  71. //Reads first line of txt file
  72. infile >> currentNum;
  73.  
  74. //Sets name as first and last name
  75. lowNum = currentNum;
  76. highNum = currentNum;
  77.  
  78. cout << count;
  79. }
  80.  
  81. //Reads out students in txt file
  82. cout << currentNum << endl;
  83. infile >> currentNum;
  84. */
  85.  
  86. /*
  87. //Final statement; Gives first and last students in line
  88. cout << endl;
  89. cout << "Lowest Number: " << lowNum << endl;
  90. cout << "Highest Number: " << highNum << endl;
  91. cout << "Average: " << avg << endl;
  92. */
  93.  
  94. printNum(filename);
  95.  
  96. cout << "Amount of Numbers: " << AMOUNT << endl << endl;
  97.  
  98. return 0;
  99. }
  100.  
  101. /*
  102. 7. Number Analysis Program Write a program that asks the user for a file name.
  103. Assume the file contains a series of numbers, each written on a separate line.
  104. The program should read the contents of the file into an array and then display the following data:
  105. • The lowest number in the array
  106. • The highest number in the array
  107. • The total of the numbers in the array
  108. • The average of the numbers in the array
  109. 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.
  110. You can use the file to test the program. (The companion Web site is at www.pearsonhighered.com/gaddis .)
  111. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement