|
Please help with programming project i have due for tomorrow! Here are the instructions and what I have so far!
Filename: cs201pj2.cpp
(use all lowercase letters in your filename, and make sure it is located in your cs201 directory, also all lowercase)
Write a program that will use a array to store a linked list. Your linked list should contain an Student number and an the student's last name. You linked list should use the student number as the key field to order the list and contain a maximum of 8 students. Each line will start with a number that will indicate the operation. The data necessary to perform the operation will follow. Each operation shoud print out a message indicating that it was performed correctly. Your program should process the following operations:
Initialize an empty list
This operation should initialize the list to an empty list
0
Add an student to the list:
This operation should add this student to the linked list
1 4521 Smith
Delete an student from the list:
Delete this student from the linked list. If the student is not in the list, print a message.
2 1000
Print the list in Logical Order
3
Find an student in the list:
Find this student from the linked list. If the student is not in the list, print a message.
4 1000
Print the list in Physical Order
This operation should print the physical contents of the list along with all of the links, list and free.
5
Your program should read the input from a data file by redirecting the input to the program ($ a.out < datafile).
Example data file:
0 1 3000 Hill 1 1000 Smith 1 2000 Green 3 5
For this data file, the first operation should initialize the list, the next 3 operations should add the 3 students to the list, the 4th operation (3) should print the list logical order:
1000 Smith 2000 Green 3000 Hill
The last operation (5) should print the physical contents of the list.
list=1 avail= 3
0 3000 Hill -1 1 1000 Smith 2 2 2000 Green 0 3 4 4 5 5 6 6 7 7 -1
This is the code i have.
#include <iostream> #include <string>
struct studenttype{ int stnum; string lname; int link; } studenttype stud[8]; int list; int avail; int prev;
void initialize (int&, int&, int&); void addstud (int&, studenttype[], int&, int&); void delstud (int&, studenttype[], int&, int&); void printlo (int, studenttype[]); void findstud (int, studenttype[]); void printfo (int, studenttype[], int);
main(); { int operation; while (cin>>operation) { switch (operation) { case 0 : initialize (list, avail, prev); break; case 1 : addstud (list, stud, avail, prev); break; case 2 : delstud (list, stud, avail, prev); break; case 3 : printlo (list, stud); break; case 4 : findstud (list, stud) break; case 5 : printfo (list, stud, avail); break; default : cout<<”Entered wrong operation code”<<endl; break; } } } void initialize (int& begin, int& open, int& before) { begin = -1; open = 0; before = -1 cout<<”The list is now empty”<<endl; } void addstud (int& begin, studenttype s[], int& open, int& before) { cin>>s[open].idnum>>s[open].lname; if (before = -1) { s[open].link = before; before = before + 1; begin = open; open = open + 1; cout<<”The next available position is “<<open<<endl; } else { s[before].link = open; before = before + 1; s[open].link = -1; open = open + 1; cout<<”The next available position is “<<open<<endl; } }
void delstud (int& begin, studenttype s[], int& open, int& before) { int ditem; while (s[
|