Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. `#include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include<stdlib.h>
  5. #include<vector>
  6. using namespace std;
  7. int main(){
  8. string line;
  9. int line2;
  10. vector<int> score;
  11. int i=0;
  12. int temp;
  13. string x;
  14. cin>>x;
  15. ifstream feederfile(x.c_str());
  16. if(feederfile.is_open()){
  17. while(feederfile.good()){
  18. score.push_back(line2);
  19. i++;
  20. }
  21. feederfile.close();
  22. }
  23. else cout<<"Unable to open Source file";
  24.  
  25. for(int i=0;i<score.size()-1;i++){
  26. for(int k=i;k<score.size();k++){
  27. if(score[i]<score[k]){
  28. temp=score[i];
  29. score[i]=score[k];
  30. score[k]=temp;
  31. }
  32. }
  33. }
  34. int a=score[score.size()-1];
  35. int b=score[0];
  36. double abh=2/(1/double (a)+1/double (b));
  37. ofstream myfile ("F:MyFile.txt");
  38. if(myfile.is_open()){
  39. myfile<<"The Harmonic Mean is: "<<abh<<endl;
  40. myfile<<"Sorted Numbers: ";
  41. for(int i=0;i<score.size();i++){
  42. if(i<score.size()-1){
  43. myfile<<score[i]<<", ";
  44. }
  45. else{myfile<<score[i];}
  46. }
  47. myfile.close();
  48. }
  49. else cout<<"Unable to open Export file";
  50. return 0;
  51. }
  52. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement