Yurttas/PL/OOL/Cplusplus/F/04/02/03/01/Courses.cpp
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 Courses.cpp
14*/
15
16#include "Courses.h"
17
18Courses::
19Courses(const int a) {
20 number_of_courses = a;
21}
22
23Courses::
24Courses(const Courses& a) {
25 number_of_courses = a.number_of_courses;
26
27 for(int i=0; i<number_of_courses; i++) {
28 course_name.push_back(a.course_name[i]);
29
30 grade.push_back(a.grade[i]);
31 }
32}
33
34string
35Courses::
36get_course_name(const int a) const {
37 return course_name[a];
38}
39
40char
41Courses::
42get_course_grade(const int a) const {
43 return grade[a];
44}
45
46int
47Courses::
48get_number_of_courses() const {
49 return number_of_courses;
50}
51
52void
53Courses::
54set_course(const string& a) {
55 string t = a;
56 int length = t.length();
57
58 while(length>1) {
59 course_name.push_back(t.substr(1,7));
60 grade.push_back(t.substr(9,1)[0]);
61 number_of_courses++;
62 t.erase(0,10);
63 length = t.length();
64 }
65}
66
67void
68Courses::
69set_course_name(const int a,
70 const string& b) {
71 course_name[a] = b;
72}
73
74void
75Courses::
76set_course_grade(const int a,
77 const char b) {
78 grade[a] = b;
79}
80
81ostream&
82operator<<(ostream& os,
83 const Courses& a) {
84 int n = a.number_of_courses;
85
86 for(int i=0; i<n; i++) {
87 os << ' ' << a.course_name[i];
88 os << ' ' << a.grade[i];
89 }
90 os << endl;
91
92 return os;
93}