SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct Student {
  7.     string name;
  8.     string egn;
  9.     double avgScore;
  10. };
  11.  
  12. Student Input() {
  13.     Student t;
  14.     cout << "Vuvedi ime: ";
  15.     cin >> t.name;
  16.     cout << "Vuvedi egn: ";
  17.     cin >> t.egn;
  18.     cout << "Vuvedi sreden uspeh: ";
  19.     cin >> t.avgScore;
  20.  
  21.     return t;
  22. }
  23.  
  24. void Print(Student s) {
  25.     cout << "Ime: " << s.name << endl;
  26.     cout << "Egn: " << s.egn << endl;
  27.     cout << "Sreden uspeh: " << s.avgScore << endl;
  28.     cout << endl;
  29. }
  30.  
  31. void SaveToFile(vector<Student> arr) {
  32.     fstream file;
  33.     file.open("file_1_o.lubo", ios::app);
  34.  
  35.     for(auto& el : arr) {
  36.         file << el.name << endl;
  37.         file << el.egn << endl;
  38.         file << el.avgScore << endl;
  39.     }
  40.     file.close();
  41. }
  42.  
  43. void InputAll() {
  44.     vector<Student> s;
  45.     int c;
  46.     cout << "Vuvedi broi studenti: ";
  47.     cin >> c;
  48.     for(int i = 0; i < c; i++) {
  49.         s.push_back(Input());
  50.         cout << endl;
  51.     }
  52.     SaveToFile(s);
  53. }
  54.  
  55. void PrintAllWithHighScore(vector<Student> arr) {
  56.     for(auto& el : arr) {
  57.         if(el.avgScore >= 4 && el.avgScore <= 5) {
  58.             Print(el);
  59.         }
  60.     }
  61. }
  62.  
  63. void ReadFile() {
  64.     fstream file;
  65.     file.open("file_1_o.lubo", ios::in);
  66.     vector<Student> arr;
  67.     while(!file.eof()) {
  68.         Student s;
  69.         file >> s.name;
  70.         file >> s.egn;
  71.         file >> s.avgScore;
  72.         arr.push_back(s);
  73.     }
  74.     arr.pop_back();
  75.     PrintAllWithHighScore(arr);
  76.     file.close();
  77. }
  78.  
  79. void Menu() {
  80.     while(true) {
  81.         int i;
  82.         cout << "0: Vuvedi" << endl;
  83.         cout << "1: Izvedi" << endl;
  84.         cin >> i;
  85.         switch(i) {
  86.         case 0:
  87.             InputAll();
  88.             break;
  89.         case 1:
  90.             ReadFile();
  91.             break;
  92.         }
  93.     }
  94. }
  95.  
  96. int main() {
  97.     Menu();
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top