well, this may not be the best forum to put this on, but this community is very helpful and I'm sure some of you fellows have some C++ knowledge
So basically, i have an assignment that is to make a linked list simulating a printer spool. I have to have a class and link the list using structures. Now, I get quite confused when structures are involved because they have more than one item that can be sent to the list.. I don't know why its confusing to me.. but it is![]()
Header file code:
and my cpp file code:Code:#include <cstdlib> #include <iostream> #include <string> using namespace std; struct node { string name; string priority; node* next; }; class MyPrintSpool { private: int sizeoflist; public: node* head; MyPrintSpool(); int countitems(); void send(string b, string a); void sendpri(char arr[],string a); void show(); void remove(); void removefile(string); node *position(int p); void print(); int size(); void printpri(); void priority(); };
So basically, my program crashes once i send the string arguments (file name and a priority) to the class member function send. I just cant seem to figure it out.. i need the class member function to make a new "node"(my structure) and send it a file name, and priority(1-5) For this function im just making the priority a default of five to test things out. But this does not work.Code:#include "Printspool.h" MyPrintSpool::MyPrintSpool() { sizeoflist = 0; head = NULL; } int MyPrintSpool::size() { return sizeoflist; } void MyPrintSpool::send(string pri,string com) { node *newnode; node *currptr = head; node *prevptr = NULL; while(currptr != NULL) { prevptr = currptr;//going through the list until currptr equals currptr = currptr->next;//Null, if it does then ill need to insert } //the file name and priority there. newnode = new node;//Obviously this is wrong, but i just can't newnode->name = com;//think of another way. newnode->priority = pri; if (prevptr == NULL) head=newnode; else prevptr->next = newnode; } void MyPrintSpool::print() { node* currPtr = head; while(currPtr != NULL) { cout << currPtr->name << endl; cout << currPtr->priority << endl; currPtr = currPtr->next; } }
if you need to see my main file just let me know and ill be happy to put this up as well.
com is the file name, and pri is the priority.
Anyone that could help me out please done hesitate too![]()



Reply With Quote




