Facebook
From ja, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 265
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6.         struct student
  7.         {      
  8.                 string imie, nazwisko;
  9.                 double srednia;
  10.                 void odczyt(istream &s_we)
  11.                 {
  12.                         s_we >> imie >> nazwisko;
  13.                         double c =0.0;
  14.                         srednia = 0.0;
  15.                                 while(1)
  16.                                 {
  17.                                         double ocena;
  18.                                         s_we >>ocena;
  19.                                         if(s_we.fail())
  20.                                                 break;
  21.                                          srednia += ocena;
  22.                                          c++;
  23.                                 }
  24.                
  25.                                 srednia = srednia/c;
  26.                                 s_we.clear();
  27.                 }
  28.         };
  29.  
  30.  
  31. int main()
  32. {
  33.         ifstream s_we("lista.txt");
  34.         int linie = 0;
  35.     if(!s_we.good())
  36.     {
  37.         cout << "Nie ma pliku" << endl;
  38.         system("pause");
  39.         return 0;
  40.     }
  41.        
  42.         while(!s_we.eof())
  43.         {
  44.         string temp;
  45.         getline(s_we, temp);
  46.         linie++;
  47.         }
  48.         s_we.clear();
  49.         s_we.seekg(0);
  50.        
  51.         student *studenci=new student[linie];
  52.                 for (int i =0; i<linie; i++)
  53.                 {
  54.                         studenci[i].odczyt(s_we);
  55.                         cout << studenci[i].imie << " " << studenci[i].nazwisko <<"    " << studenci[i].srednia;
  56.                         cout <<endl;
  57.                 }
  58.         cout << endl;
  59.         system("pause");
  60. }
  61.  
  62.