Advertisement
patryk178

Untitled

Jan 30th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. Void Wpisz(int ile)
  7. {
  8. ofstream fout("studenci.txt");
  9. string tab[ile][5];
  10. for(int i=0;i<ile;i++)
  11. {
  12. cout<<endl<<"Student nr "<<i+1<<": "<<endl;
  13. cout<<"Nazwisko: ";cin>>tab[i][0];
  14. cout<<"Imie: ";cin>>tab[i][1];
  15. cout<<"Wiek: ";cin>>tab[i][2];
  16. cout<<"Miejsce urodzenia: ";cin>>tab[i][3];
  17. cout<<"Telefon: ";cin>>tab[i][4];
  18. }
  19.  
  20. for(int i=0;i<ile;i++)
  21. {
  22. fout<<tab[i][0]<<" "<<tab[i][1]<<" "<<tab[i][2]<<" "<<tab[i][3]<<" "<<tab[i][4]<<endl;
  23. }
  24. }
  25.  
  26. int main()
  27. {
  28. int ile;
  29. cout<<"Ile studentow: ";cin>>ile;
  30.  
  31. wpisz(ile);
  32.  
  33. ifstream fin("studenci.txt");
  34. while(!fin.eof())
  35. {
  36. string nazwisko,imie,miejsce,telefon;
  37. int wiek;
  38. fin>>nazwisko>>imie>>wiek>>miejsce>>telefon;
  39. cout<<nazwisko<<" "<<imie<<" "<<wiek<<" "<<miejsce<<" "<<telefon<<endl;
  40. }
  41. cout<<endl<<"c)"<<endl;
  42.  
  43. ifstream fin2("studenci.txt");
  44. float srednia = 0;
  45.  
  46. while(!fin2.eof())
  47. {
  48. string nazwisko,imie,miejsce,telefon;
  49. int wiek;
  50. fin2>>nazwisko>>imie>>wiek>>miejsce>>telefon;
  51. cout<<nazwisko<<" "<<telefon<<endl;
  52. srednia+=wiek;
  53.  
  54. }
  55.  
  56. srednia/=ile;
  57. cout<<endl<<"d)"<<srednia;
  58. cout<<endl<<"e)";
  59.  
  60. ifstream fin3("studenci.txt");
  61.  
  62.  
  63. while(!fin3.eof())
  64. {
  65. string nazwisko,imie,miejsce,telefon;
  66. int wiek;
  67. fin3>>nazwisko>>imie>>wiek>>miejsce>>telefon;
  68. if(nazwisko[0]=='A')cout<<imie<<" "<<nazwisko;
  69.  
  70. }
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement