Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
cptr142_group_project
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jared Sexton
cptr142_group_project
Commits
b0e3c113
Commit
b0e3c113
authored
Mar 07, 2018
by
Andrew Binder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating checkRoster()
parent
06b24473
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
35 deletions
+12
-35
Teacher.cpp
Teacher.cpp
+10
-30
Teacher.h
Teacher.h
+2
-5
No files found.
Teacher.cpp
View file @
b0e3c113
...
...
@@ -57,8 +57,7 @@ void Teacher::displayMenu() {
{
cout
<<
"Please enter a username (no spaces): "
;
cin
>>
stringIn
;
Student
studentIn
(
stringIn
);
enrollStudent
(
studentIn
);
enrollStudent
(
stringIn
);
break
;
}
case
4
:
// Adjust Student Progress
...
...
@@ -175,19 +174,11 @@ void Teacher::importProgress() {
// Enroll a new student
// Input: student username
// Output: success or not
void
Teacher
::
enrollStudent
(
Student
studentIn
)
{
bool
validName
=
1
;
//Assume name is valid
// Determine if the username already exists in the vector
// If it does, set validName to false
for
(
int
i
=
0
;
i
<
roster
.
size
();
i
++
)
{
if
(
roster
.
at
(
i
).
getUserName
()
==
studentIn
.
getUserName
())
{
validName
=
0
;
}
}
void
Teacher
::
enrollStudent
(
string
studentIn
)
{
int
validName
=
checkRoster
(
studentIn
);
// Check if username exists in roster
// If the name is valid, enroll the student, otherwise output an error
if
(
validName
)
{
if
(
validName
==
-
1
)
{
roster
.
push_back
(
studentIn
);
cout
<<
"Student succesfully enrolled."
<<
endl
;
}
else
{
...
...
@@ -199,23 +190,12 @@ void Teacher::enrollStudent(Student studentIn) {
// Input: Student's username and new level
// Output: Changed student within the roster vector and success or not
void
Teacher
::
adjustProgress
(
string
studentUserNameIn
,
int
level
)
{
int
lastLevel
=
-
1
,
studentNumber
=
-
1
;
bool
validName
=
0
;
// Find if username exists, save student position
for
(
int
i
=
0
;
i
<
roster
.
size
();
i
++
)
{
if
(
roster
.
at
(
i
).
getUserName
()
==
studentUserNameIn
)
{
validName
=
1
;
studentNumber
=
i
;
}
}
int
studentNumber
=
checkRoster
(
studentUserNameIn
);
// Check if student exists/Get student position in vector
// If the username exists, change the level and output success to console
// Otherwise, output an error
if
(
validName
)
{
lastLevel
=
roster
.
at
(
studentNumber
).
getLevel
();
if
(
studentNumber
>=
0
)
{
int
lastLevel
=
roster
.
at
(
studentNumber
).
getLevel
();
roster
.
at
(
studentNumber
).
setLevel
(
level
);
cout
<<
roster
.
at
(
studentNumber
).
getUserName
()
<<
"'s level was changed from level "
<<
lastLevel
<<
" to "
<<
roster
.
at
(
studentNumber
).
getLevel
()
<<
"."
<<
endl
;
}
else
{
...
...
@@ -231,13 +211,13 @@ void Teacher::endProgram() {
}
// Checks the roster for a given student, and returns true if found.
bool
Teacher
::
checkRoster
(
string
student
)
{
int
Teacher
::
checkRoster
(
string
student
)
{
for
(
int
i
=
0
;
i
<
roster
.
size
();
i
++
)
{
if
(
roster
.
at
(
i
).
getUserName
()
==
student
)
{
return
true
;
return
i
;
}
}
return
false
;
return
-
1
;
}
// Accessors
...
...
Teacher.h
View file @
b0e3c113
...
...
@@ -24,13 +24,10 @@ class Teacher {
void
exportProgress
();
// outputProgress() in UML
void
saveProgress
();
// Exports roster/progress to a file; this is run whenever log out is selected from menu
void
importProgress
();
// Imports roster/progress from a file
void
enrollStudent
(
Student
studentIn
);
// Enrolls a new student; includes error checking
void
enrollStudent
(
string
studentIn
);
// Enrolls a new student; includes error checking
void
adjustProgress
(
string
studentUserNameIn
,
int
level
);
// Changes a students level; includes error checking for student username
int
checkRoster
(
string
student
);
// Checks to see if a student exists with input string
void
endProgram
();
// saves and ends program gracefully
/* Andrew - I added this function to search for a given student in the roster (for use in login stage) */
bool
checkRoster
(
string
student
);
// Accessors
const
string
getUserName
();
const
string
getExitCode
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment