Advertisement
Guest User

information displayer

a guest
Feb 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7.  
  8. // getting the file name.
  9. string getFileInfo ()
  10. {
  11. string dogo;
  12. string fileName;
  13. ifstream infile;
  14. while (!(dogo == "the price is right"))
  15. {
  16. cout << "Enter a file name: " << endl;
  17. cin >> fileName;
  18. infile.open (fileName);
  19. if ((infile))
  20. {
  21. break;
  22. }
  23. cout <<endl << "tis not possible." << endl;
  24. }
  25. // calculating the mean of all the numbers.
  26. return fileName;
  27. };
  28.  
  29. double calculateMean(string fileName)
  30. {
  31. double mean;
  32. double dog;
  33. double seagull;
  34. mean = 0;
  35. ifstream infile;
  36. infile.open (fileName);
  37. while (infile)
  38. {
  39. infile >> seagull;
  40. dog = seagull + dog;
  41.  
  42. }
  43. dog = dog - 34;
  44. mean = dog / 20;
  45. return mean;
  46. };
  47. // calculatoing the minimum of all the numbers.
  48. int calculateMin(string fileName)
  49. {
  50.  
  51. int min;
  52. int seagull;
  53. int dog;
  54. ifstream infile;
  55. infile.open (fileName);
  56. infile >> seagull;
  57. while (infile)
  58. {
  59. infile >> dog;
  60. if (seagull > dog)
  61. {
  62. seagull = dog;
  63. }
  64. }
  65. min = seagull;
  66. return min;
  67. }
  68. // displaying the infomration gained.
  69. void displayInfo(double mean, int min)
  70. {
  71. cout << "The mean is:\t" << mean << endl;
  72. cout << "the min is:\t"<< min << endl;
  73. };
  74.  
  75.  
  76. int main()
  77. {
  78. // starting functions in main.
  79. string fileName = getFileInfo ();
  80. double mean= calculateMean(fileName);
  81. double min = calculateMin(fileName);
  82. displayInfo(mean, min);
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement