-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.cpp
More file actions
106 lines (100 loc) · 1.64 KB
/
Student.cpp
File metadata and controls
106 lines (100 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
using namespace std;
#include <string>
#include <cstddef>
#include "Student.h"
/*
Saitcan Baskol
21803589
SEC02
*/
Student::Student()
{
stuhead = NULL;
studentBooks = 0;
studentId = 0;
studentName = "DEFAULT";
}
Student::Student(int id,string name)
{
stuhead = NULL;
studentBooks = 0;
setId(id);
setName(name);
}
Student::~Student()
{
while(!isEmpty())
{
removeNode(1);
}
}
int Student::getId()
{
return studentId;
}
void Student::setId(int id)
{
studentId = id;
}
string Student::getName()
{
return studentName;
}
void Student::setName(string nameP)
{
studentName = nameP;
}
bool Student::isEmpty() const
{
return studentBooks == 0;
}
int Student::getLength() const
{
return studentBooks;
}
int Student::findIndex(int bookId)
{
studentBookNode* cur = stuhead;
for(int i = 1; i <= getLength();i++)
{
if(cur->item.getBookId() == bookId)
{
return i;
}
cur = cur->next;
}
}
Student::studentBookNode* Student::findPointer(int index)
{
studentBookNode* cur = stuhead;
for(int i = 1; i < index; i++)
{
cur = cur->next;
}
return cur;
}
bool Student::removeNode(int index)
{
studentBookNode* cur;
if ((index < 1) || (index > getLength()))
{
return false;
}
studentBooks--;
if(index == 1)
{
cur = stuhead;
stuhead = stuhead->next;
}
else
{
studentBookNode* prev = findPointer(index - 1);
cur = prev->next;
prev->next = cur->next;
}
cur->next = NULL;
delete cur;
cur = NULL;
return true;
}