I'm really just looking for some advice on my current code and with moving forward. As you can see, I have a pointer to my student list and data (which just haven't been made yet).
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
class List{ //Building the base of the program, being the nodes, and initializing the functions of the list
private:
typedef struct node {
int student_number;
int class_number;
struct node* classpointer;
struct node* studentpointer;
}* nodePtr; //condensing node structure to simply "nodePtr"
nodePtr head;
nodePtr curr;
nodePtr temp;
//functions that I will be using
public:
List();
void addNode();
void PrintList();
};
//initialize the list pointers
List::List() {
head = NULL;
curr = NULL;
temp = NULL;
}
//function to add a node to the linked list
void List::addNode() {
nodePtr n = new node;
n->classpointer = NULL;
cout << "What value would you like to add?" << endl;
int x;
cin >> x;
n->class_number = x;
if(head != NULL) {
curr = head;
while (curr->classpointer != NULL) {
curr = curr->classpointer;
}
curr->classpointer = n;
}
else {
head = n;
}
}
void List::PrintList() {
curr = head;
while(curr != NULL) {
cout << " " << endl;
cout << curr->class_number << endl;
curr = curr->classpointer;
}
}
int menu() {
int input;
List List;
while (input != 3) {
cout << " " << endl;
cout << "Press '1' to input a node" << endl;
cout << "Press '2' to view the list of nodes" << endl;
cout << "Press '3' to exit" << endl;
cout << " " << endl;
cin >> input;
if (input == 1) {
List.addNode();
}
else if (input == 2) {
List.PrintList();
}
else if (input == 3) {
return 0;
}
else {
cout <<"That is an invalid key" << endl;
}
}
}
int main() {
int i;
for (i=0; i < 500; i++) {
menu();
}
}