Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6. int main()
  7. {
  8. ifstream filein;
  9. filein.open("a.txt");
  10. if (!filein)
  11. {
  12. cout << "Nieudana proba otwarcia pliku!" << endl;
  13. system("pause");
  14. return 1;
  15. }
  16. double d,temp[100] = { 0 };
  17. int ilosc = 0;
  18. while (ilosc < 100)
  19. {
  20. filein >> d;
  21. if (filein.eof())break;
  22. temp[ilosc] = d;
  23. cout << d << endl;
  24. ilosc++;
  25. }
  26. filein.close();
  27. ofstream fileout("a.txt");
  28. if (!fileout)
  29. {
  30. cout << "Nieudana proba otwarcia pliku!" << endl;
  31. system("pause");
  32. return 1;
  33. }
  34. for (int i = 0;i < ilosc;i++)
  35. {
  36. fileout << fixed<<setprecision(1)<<temp[i] << endl;
  37. }
  38. fileout.close();
  39. fileout.open("b.txt",ios::app);
  40. double suma = 0;
  41. for (int i = 0;i < ilosc;i++) suma += temp[i];
  42. double srednia = suma / ilosc;
  43. fileout << "srednia: " << fixed << setprecision(3) << srednia << endl;
  44. fileout.close();
  45. system("pause");
  46. return 1;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement