-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_students.cpp
110 lines (91 loc) · 3.88 KB
/
table_students.cpp
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
105
106
107
108
109
110
//Tim Garvin
#include "table_students.h"
//Constructor implementation (Initialization of variables)
Table_Students::Table_Students()
{
table_data = new Row_Students(); //Initializes the class object for rows in the Students table
}
//Inserts a new row into the Students table
void Table_Students::insert(string studentID, string firstName, string lastName)
{
//Checks if table is empty
if(table_data->get_ID() == "-1")
{
table_data->set_currentRow(studentID, firstName, lastName); //Populates the first row in the Students table
}
else
{
Row_Students *current_row = new Row_Students(); //Creates a temporary new class object for rows in the Students table
current_row = table_data; //Populates the temporary class object for rows in the Students table
//Loops through the Students table
while(current_row->get_ID() != "-1")
{
current_row = current_row->get_nextRow(); //Moves the row pointer to the next row in the Students table
//Checks if the current row is empty
if(current_row->get_ID() == "-1")
{
current_row->set_currentRow(studentID, firstName, lastName); //Populates the next empty row in the Students table
break;
}
}
}
}
//Prints the Students table
void Table_Students::print()
{
Row_Students *current_row = new Row_Students(); //Creates a temporary new class object for rows in the Students table
current_row = table_data; //Populates the temporary class object for rows in the Students table
//Loops through the Students table
while(current_row->get_ID() != "-1")
{
cout<<"("<<current_row->get_ID()<<","<<current_row->get_firstName()<<","<<current_row->get_lastName()<<")"; //Displays the current row
current_row = current_row->get_nextRow(); //Moves the row pointer to the next row in the Students table
}
cout<<endl;
}
//Selects rows from the Students table
void Table_Students::select(string attribute, string value)
{
Row_Students *current_row = new Row_Students(); //Creates a temporary new class object for rows in the Students table
current_row = table_data; //Populates the temporary class object for rows in the Students table
//Loops through the Students table
while(current_row->get_ID() != "-1")
{
if(attribute == "id") //Checks if the attribute selected is for Student ID
{
//Checks if the user entered value matches the one in the current row
if(value == current_row->get_ID())
{
cout<<"("<<current_row->get_ID()<<","<<current_row->get_firstName()<<","<<current_row->get_lastName()<<")"; //Displays the matching row
}
}
else if(attribute == "firstname") //Checks if the attribute selected is for First Name
{
//Checks if the user entered value matches the one in the current row
if(value == current_row->get_firstName())
{
cout<<"("<<current_row->get_ID()<<","<<current_row->get_firstName()<<","<<current_row->get_lastName()<<")"; //Displays the matching row
}
}
else if(attribute == "lastname") //Checks if the attribute selected is for Last Name
{
//Checks if the user entered value matches the one in the current row
if(value == current_row->get_lastName())
{
cout<<"("<<current_row->get_ID()<<","<<current_row->get_firstName()<<","<<current_row->get_lastName()<<")"; //Displays the matching row
}
}
current_row = current_row->get_nextRow(); //Moves the row pointer to the next row in the Students table
}
cout<<endl;
}
//Returns the whole Students table
Row_Students* Table_Students::get_tableData()
{
return table_data;
}
//Destructor
Table_Students::~Table_Students()
{
delete table_data;
}