-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (70 loc) · 2.29 KB
/
main.cpp
File metadata and controls
96 lines (70 loc) · 2.29 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
#include <iostream>
#include <cstring>
#include "Node.h"
#include "student.h"
using namespace std;
Node* head = NULL;
void add(char* first, char* last, int id, float gpa) {
Student* newStudent = new Student(first, last, id, gpa);
Node* current = head;
if(current == NULL) {
head = new Node(newStudent);
head->setStudent(newStudent);
} else {
while(current->getNext() != NULL) {
current = current->getNext();
}
current->setNext(new Node(newStudent));
current->getNext()->setStudent(newStudent);
}
}
void print(Node* next) {
if(next == head) {
cout << "list: ";
}
if(next != NULL) {
cout << next->getStudent()->getFirst() << " " << next->getStudent()->getLast() << "\t"<< next ->getStudent()->getId() << "\t" <<
next ->getStudent()-> getGpa() << endl;
print(next->getNext());
}
}
int main() {
bool running = true;
char inp[20];
char first[20];
char last[20];
int id;
float gpa;
while(running) {
cout << "Enter what you would like to do" << endl;
cin.get(inp,20);
cin.clear();
cin.ignore();
if(strcmp(inp, "add") == 0) {
cout << "Enter a first name: " << endl;
cin.get(first, 20);
cin.clear();
cin.ignore();
cout << "Enther their last name: " << endl;
cin.get(last,20);
cin.clear();
cin.ignore();
cout << "Enter their id: " << endl;
cin >> id;
cin.clear();
cin.ignore();
cout << "Enter their gpa: " << endl;
cin >> gpa;
cin.clear();
cin.ignore();
add(first,last,id,gpa);
} else if(strcmp(inp,"print") == 0) {
print(head);
}else if(strcmp(inp, "quit") == 0) {
running = false;
} else {
cout << "Enter a valid option" << endl;
}
}
return 0;
}