Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
StudentManagement
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Reinig
StudentManagement
Commits
43e1ce64
Commit
43e1ce64
authored
2 years ago
by
Pelotrio
Browse files
Options
Downloads
Patches
Plain Diff
Final commit
parent
630bd4fd
Branches
master
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Course.cpp
+74
-28
74 additions, 28 deletions
Course.cpp
Course.h
+9
-2
9 additions, 2 deletions
Course.h
Student.cpp
+13
-13
13 additions, 13 deletions
Student.cpp
Student.h
+5
-0
5 additions, 0 deletions
Student.h
main.cpp
+70
-12
70 additions, 12 deletions
main.cpp
with
171 additions
and
55 deletions
Course.cpp
+
74
−
28
View file @
43e1ce64
...
...
@@ -3,46 +3,47 @@
#include
<iostream>
Course
::
Course
(
std
::
string
name
)
:
name
(
std
::
move
(
name
))
{
s
tudent
s
=
nullptr
;
firstS
tudent
=
nullptr
;
}
void
Course
::
addStudent
(
std
::
string
lastName
,
std
::
string
firstName
)
{
auto
*
new
Student
=
n
ew
Student
(
lastName
,
firstName
);
if
(
students
==
nullptr
)
{
s
tudent
s
=
newStudent
;
void
Course
::
addStudent
(
Student
*
newStudent
)
{
if
(
first
Student
=
=
n
ullptr
)
{
firstStudent
=
newStudent
;
lastS
tudent
=
newStudent
;
}
else
{
Student
*
currentStudent
=
students
;
while
(
currentStudent
->
getNextStudent
()
!=
nullptr
)
{
currentStudent
=
currentStudent
->
getNextStudent
();
}
currentStudent
->
setNextStudent
(
newStudent
);
lastStudent
->
setNextStudent
(
newStudent
);
newStudent
->
setPreviousStudent
(
lastStudent
);
lastStudent
=
newStudent
;
}
}
void
Course
::
deleteStudent
(
int
matriculationNumber
)
{
if
(
s
tudent
s
==
nullptr
)
{
if
(
firstS
tudent
==
nullptr
)
{
return
;
}
if
(
students
->
getMatriculationNumber
()
==
matriculationNumber
)
{
auto
*
temp
=
students
;
students
=
students
->
getNextStudent
();
delete
temp
;
}
else
{
Student
*
currentStudent
=
students
;
while
(
currentStudent
->
getNextStudent
()
!=
nullptr
&&
currentStudent
->
getNextStudent
()
->
getMatriculationNumber
()
!=
matriculationNumber
)
{
currentStudent
=
currentStudent
->
getNextStudent
();
Student
*
currentStudent
=
firstStudent
;
while
(
currentStudent
!=
nullptr
&&
currentStudent
->
getMatriculationNumber
()
!=
matriculationNumber
)
{
currentStudent
=
currentStudent
->
getNextStudent
();
}
if
(
currentStudent
!=
nullptr
)
{
if
(
currentStudent
->
getPreviousStudent
()
!=
nullptr
)
{
currentStudent
->
getPreviousStudent
()
->
setNextStudent
(
currentStudent
->
getNextStudent
());
}
if
(
currentStudent
->
getNextStudent
()
!=
nullptr
)
{
auto
*
temp
=
currentStudent
->
getNextStudent
();
currentStudent
->
setNextStudent
(
temp
->
getNextStudent
());
delete
temp
;
currentStudent
->
getNextStudent
()
->
setPreviousStudent
(
currentStudent
->
getPreviousStudent
());
}
if
(
currentStudent
==
firstStudent
)
{
firstStudent
=
currentStudent
->
getNextStudent
();
}
if
(
currentStudent
==
lastStudent
)
{
lastStudent
=
currentStudent
->
getPreviousStudent
();
}
delete
currentStudent
;
}
}
void
Course
::
displayStudent
(
int
matriculationNumber
)
{
Student
*
currentStudent
=
s
tudent
s
;
Student
*
currentStudent
=
firstS
tudent
;
while
(
currentStudent
!=
nullptr
&&
currentStudent
->
getMatriculationNumber
()
!=
matriculationNumber
)
{
currentStudent
=
currentStudent
->
getNextStudent
();
}
...
...
@@ -54,16 +55,61 @@ void Course::displayStudent(int matriculationNumber) {
}
}
Student
*
Course
::
getStudent
(
int
matriculationNumber
)
{
Student
*
currentStudent
=
firstStudent
;
while
(
currentStudent
!=
nullptr
&&
currentStudent
->
getMatriculationNumber
()
!=
matriculationNumber
)
{
currentStudent
=
currentStudent
->
getNextStudent
();
}
if
(
currentStudent
!=
nullptr
)
{
return
currentStudent
;
}
return
nullptr
;
}
void
Course
::
displayStudents
()
{
Student
*
currentStudent
=
students
;
// Display the firstStudent in the course in a table.
std
::
cout
<<
"Name
\t\t
| Vorname
\t\t
| Matrikelnummer"
<<
std
::
endl
;
std
::
cout
<<
"--------------------------------------------"
<<
std
::
endl
;
Student
*
currentStudent
=
firstStudent
;
while
(
currentStudent
!=
nullptr
)
{
std
::
cout
<<
"Student: "
<<
currentStudent
->
getFirstName
()
<<
"
"
<<
currentStudent
->
getLastName
()
<<
std
::
endl
;
std
::
cout
<<
currentStudent
->
getFirstName
()
<<
"
\t\t\t
"
<<
currentStudent
->
getLastName
()
<<
"
\t\t\t
"
<<
currentStudent
->
getMatriculationNumber
()
<<
std
::
endl
;
currentStudent
=
currentStudent
->
getNextStudent
();
}
}
void
Course
::
displayCourse
()
{
std
::
cout
<<
"Course name: "
<<
name
<<
std
::
endl
;
sort
();
displayStudents
();
}
\ No newline at end of file
}
void
Course
::
sort
()
{
if
(
firstStudent
==
nullptr
)
{
return
;
}
Student
*
currentStudent
=
firstStudent
->
getNextStudent
();
while
(
currentStudent
!=
nullptr
)
{
Student
*
tempStudent
=
currentStudent
;
while
(
tempStudent
->
getPreviousStudent
()
!=
nullptr
&&
tempStudent
->
getPreviousStudent
()
->
getLastName
()
>
tempStudent
->
getLastName
())
{
// swap tempStudent and prevStudent
if
(
tempStudent
->
getPreviousStudent
()
==
firstStudent
)
firstStudent
=
tempStudent
;
if
(
tempStudent
==
lastStudent
)
lastStudent
=
tempStudent
->
getPreviousStudent
();
tempStudent
->
getPreviousStudent
()
->
setNextStudent
(
tempStudent
->
getNextStudent
());
if
(
tempStudent
->
getNextStudent
()
!=
nullptr
)
tempStudent
->
getNextStudent
()
->
setPreviousStudent
(
tempStudent
->
getPreviousStudent
());
tempStudent
->
setNextStudent
(
tempStudent
->
getPreviousStudent
());
tempStudent
->
setPreviousStudent
(
tempStudent
->
getPreviousStudent
()
->
getPreviousStudent
());
if
(
tempStudent
->
getPreviousStudent
()
!=
nullptr
)
tempStudent
->
getPreviousStudent
()
->
setNextStudent
(
tempStudent
);
tempStudent
->
getNextStudent
()
->
setPreviousStudent
(
tempStudent
);
}
currentStudent
=
currentStudent
->
getNextStudent
();
}
}
std
::
string
Course
::
getName
()
const
{
return
name
;
}
This diff is collapsed.
Click to expand it.
Course.h
+
9
−
2
View file @
43e1ce64
...
...
@@ -7,12 +7,13 @@
class
Course
{
private:
std
::
string
name
;
Student
*
students
;
Student
*
firstStudent
;
Student
*
lastStudent
;
public:
explicit
Course
(
std
::
string
name
);
void
addStudent
(
std
::
string
lastName
,
std
::
string
firstName
);
void
addStudent
(
Student
*
student
);
void
deleteStudent
(
int
matriculationNumber
);
...
...
@@ -21,6 +22,12 @@ public:
void
displayStudents
();
void
displayCourse
();
std
::
string
getName
()
const
;
void
sort
();
Student
*
getStudent
(
int
matriculationNumber
);
};
#endif
This diff is collapsed.
Click to expand it.
Student.cpp
+
13
−
13
View file @
43e1ce64
#include
"Student.h"
#include
<random>
#include
<set>
Student
::
Student
(
std
::
string
lastName
,
std
::
string
firstName
)
:
lastName
(
lastName
),
firstName
(
firstName
),
matriculationNumber
(
generateMatriculationNumber
())
{
nextStudent
=
nullptr
;
previousStudent
=
nullptr
;
}
std
::
string
Student
::
getLastName
()
const
{
...
...
@@ -27,15 +26,16 @@ void Student::setNextStudent(Student *nextStudent) {
this
->
nextStudent
=
nextStudent
;
}
Student
*
Student
::
getPreviousStudent
()
const
{
return
previousStudent
;
}
void
Student
::
setPreviousStudent
(
Student
*
previousStudent
)
{
this
->
previousStudent
=
previousStudent
;
}
int
Student
::
generateMatriculationNumber
()
{
static
std
::
random_device
rd
;
static
std
::
mt19937
generator
(
rd
());
static
std
::
uniform_int_distribution
<
int
>
distribution
(
100000
,
999999
);
static
std
::
set
<
int
>
usedNumbers
;
int
matriculationNumber
;
do
{
matriculationNumber
=
distribution
(
generator
);
}
while
(
usedNumbers
.
count
(
matriculationNumber
)
>
0
);
usedNumbers
.
insert
(
matriculationNumber
);
return
matriculationNumber
;
}
\ No newline at end of file
// Generate the matriculation number starting from 1000000 and counting up.
static
int
matriculationNumber
=
1000000
;
return
matriculationNumber
++
;
}
This diff is collapsed.
Click to expand it.
Student.h
+
5
−
0
View file @
43e1ce64
...
...
@@ -9,6 +9,7 @@ private:
std
::
string
firstName
;
int
matriculationNumber
;
Student
*
nextStudent
;
Student
*
previousStudent
;
public:
Student
(
std
::
string
lastName
,
std
::
string
firstName
);
...
...
@@ -21,8 +22,12 @@ public:
Student
*
getNextStudent
()
const
;
Student
*
getPreviousStudent
()
const
;
void
setNextStudent
(
Student
*
nextStudent
);
void
setPreviousStudent
(
Student
*
previousStudent
);
static
int
generateMatriculationNumber
();
};
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
70
−
12
View file @
43e1ce64
#include
<iostream>
#include
<set>
#include
<algorithm>
#include
<vector>
#include
"Course.h"
int
main
()
{
Course
*
course
=
nullptr
;
std
::
vector
<
Course
*>
courses
;
bool
quit
=
false
;
while
(
!
quit
)
{
std
::
cout
<<
"1. Create course"
<<
std
::
endl
;
std
::
cout
<<
"2. Add student"
<<
std
::
endl
;
std
::
cout
<<
"3. Display student"
<<
std
::
endl
;
std
::
cout
<<
"4. Delete student"
<<
std
::
endl
;
std
::
cout
<<
"5. Display course"
<<
std
::
endl
;
std
::
cout
<<
"6. Quit"
<<
std
::
endl
;
std
::
cout
<<
"3. Add existing student"
<<
std
::
endl
;
std
::
cout
<<
"4. Display student"
<<
std
::
endl
;
std
::
cout
<<
"5. Remove student"
<<
std
::
endl
;
std
::
cout
<<
"6. Delete student"
<<
std
::
endl
;
std
::
cout
<<
"7. Display course"
<<
std
::
endl
;
std
::
cout
<<
"8. Display all courses"
<<
std
::
endl
;
std
::
cout
<<
"9. Quit"
<<
std
::
endl
;
std
::
cout
<<
"Enter your choice: "
;
int
choice
;
std
::
cin
>>
choice
;
std
::
string
name
,
lastName
,
firstName
;
std
::
string
name
,
lastName
,
firstName
,
courseName
;
int
matriculationNumber
;
switch
(
choice
)
{
case
1
:
std
::
cout
<<
"Enter course name: "
;
std
::
cin
.
ignore
();
std
::
getline
(
std
::
cin
,
name
);
course
=
new
Course
(
name
);
course
s
.
push_back
(
new
Course
(
name
)
)
;
break
;
case
2
:
std
::
cout
<<
"Enter student's first name: "
;
std
::
cin
>>
firstName
;
std
::
cout
<<
"Enter student's last name: "
;
std
::
cin
>>
lastName
;
course
->
addStudent
(
lastName
,
firstName
);
std
::
cout
<<
"Enter course name: "
;
std
::
cin
>>
courseName
;
for
(
auto
*
course
:
courses
)
{
if
(
course
->
getName
()
==
courseName
)
{
course
->
addStudent
(
new
Student
(
lastName
,
firstName
));
}
}
break
;
case
3
:
std
::
cout
<<
"Enter student's matriculation number: "
;
std
::
cin
>>
matriculationNumber
;
course
->
displayStudent
(
matriculationNumber
);
std
::
cout
<<
"Enter course name: "
;
std
::
cin
>>
courseName
;
for
(
auto
*
course
:
courses
)
{
if
(
course
->
getName
()
==
courseName
)
{
Student
*
student
=
course
->
getStudent
(
matriculationNumber
);
if
(
student
!=
nullptr
)
{
course
->
addStudent
(
student
);
}
}
}
break
;
case
4
:
std
::
cout
<<
"Enter student's matriculation number: "
;
std
::
cin
>>
matriculationNumber
;
course
->
deleteStudent
(
matriculationNumber
);
for
(
auto
*
course
:
courses
)
{
course
->
displayStudent
(
matriculationNumber
);
}
break
;
case
5
:
course
->
displayCourse
();
std
::
cout
<<
"Enter student's matriculation number: "
;
std
::
cin
>>
matriculationNumber
;
std
::
cout
<<
"Enter course name: "
;
std
::
cin
>>
courseName
;
for
(
auto
*
course
:
courses
)
{
if
(
course
->
getName
()
==
courseName
)
{
course
->
deleteStudent
(
matriculationNumber
);
}
}
break
;
case
6
:
std
::
cout
<<
"Enter student's matriculation number: "
;
std
::
cin
>>
matriculationNumber
;
// Delete student from all courses
for
(
auto
*
course
:
courses
)
{
course
->
deleteStudent
(
matriculationNumber
);
}
break
;
case
7
:
std
::
cout
<<
"Enter course name: "
;
std
::
cin
>>
courseName
;
for
(
auto
*
course
:
courses
)
{
if
(
course
->
getName
()
==
courseName
)
{
course
->
displayCourse
();
}
}
break
;
case
8
:
std
::
cout
<<
"Courses:"
<<
std
::
endl
;
for
(
auto
*
course
:
courses
)
{
course
->
displayCourse
();
}
break
;
case
9
:
quit
=
true
;
break
;
default
:
...
...
@@ -53,6 +109,8 @@ int main() {
break
;
}
}
delete
course
;
for
(
auto
*
course
:
courses
)
{
delete
course
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment