Yurttas/PL/OOL/Cplusplus/F/04/02/03/01/students process.cpp

From ZCubes Wiki
Jump to navigation Jump to search
  1/*
  2   Copyright(C) 2002
  3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4
  5   Permission to use, copy, modify, and distribute this
  6   software and its documentation for EDUCATIONAL purposes
  7   and without fee is hereby granted provided that this
  8   copyright notice appears in all copies.
  9  
 10   date   : June 1, 2002.
 11   author : Salih Yurttas.
 12
 13   students_process.cpp
 14*/
 15
 16
 17#include <iostream>
 18#include <fstream>
 19#include <iomanip>
 20
 21#include <vector>
 22#include <string>
 23
 24using namespace std;
 25
 26#include "Person.h"
 27#include "Courses.h"
 28#include "Student.h"
 29
 30#include "students_process.h"
 31
 32const char GRADE='A';
 33
 34vector<Student>
 35students_process::
 36get_list_students() {
 37  vector<Student> list;
 38  string filename;
 39
 40  cout << endl;
 41  cout << "--> input filename : ";
 42  cin >> filename;
 43
 44  ifstream f_in(filename.c_str());
 45
 46  if(!f_in) {
 47    cerr << "File named as " << filename << " is not opened for input." << endl;
 48    exit(1);
 49  }
 50
 51  else {
 52    string r;
 53
 54    while(getline(f_in,r,'\n')) {
 55      string n = r.substr(0,25);
 56      r.erase(0,24);
 57      Student s(0);
 58
 59      s.Person::set_name(n);
 60      s.Courses::set_course(r);
 61
 62      int k = r.size();
 63      r.erase(k);
 64
 65      list.push_back(s);
 66    }
 67  }
 68
 69  f_in.close();
 70
 71  return list;
 72}
 73
 74vector<Student>
 75students_process::
 76extract_list_students_of_all_a(vector<Student>& g_l) {
 77  vector<Student> e_l;
 78
 79  int n = g_l.size();
 80
 81  for(int i=0; i<n; i++) {
 82    int j;
 83    for(j=0; j<g_l[i].get_number_of_courses(); j++)
 84      if(g_l[i].get_course_grade(j)!=GRADE)
 85        break;
 86
 87   if(j==g_l[i].get_number_of_courses())
 88     e_l.push_back(g_l[i]);
 89  }
 90
 91  return e_l;
 92}
 93
 94void
 95students_process::
 96put_list_students(vector<Student>& list) {
 97  string filename;
 98
 99  cout << endl;
100  cout << "--> output filename : ";
101  cin >> filename;
102
103  ofstream f_out(filename.c_str());
104  
105  extern int course_index;
106
107  int l_s = list.size();
108
109  for(int i=0; i<l_s; i++)
110    f_out << list[i];
111
112  f_out.close();
113}
114
115char
116students_process::
117get_char(string s) {
118  char value;
119
120  cout << endl;
121  cout << "Enter the ";
122  cout << s;
123  cout << " value in char : ";
124  cin >> value;
125
126  return value;
127}