I'm trying to develop a program that stores a list of hw assignments in the form of "Date,Assignment name,grade". I have functions that add,remove, and delete from a list, but I would also like to search and delete a particular date found in the list. From here, split - Splitting a string in C++ - Stack Overflow I've tested Evan Teran's method to split a string, but I'm unsure of how to implement it in my code.
List.h
List.cppCode:#ifndef LIST_H #define LIST_H #include <string> using namespace std; class List{ private: typedef struct node{ string hw; string grade; string date; node* next; }* Node; Node head; Node current; Node temp; public: List(); void AddAssign(string addData); void DeleteAssign(string delData); void PrintList(); }; #endif /* LIST_H */
Code:#include <cstdlib> #include <iostream> #include <string> #include "List.h" using namespace std; List::List(){ head = NULL; current = NULL; temp = NULL; } /* @function - addAssign * @pre - * @post * @return - adds a list of elements to * assignment list. */ void List::AddAssign(string addData){ Node n = new node; n->next = NULL; n->hw = addData;//initializes hw if(head != NULL){ current = head; while(current->next != NULL){//next node is not at end of list current = current->next;//go to next node } current->next = n;//next node is new } else{ head = n;//newest node is head of list } } void List::DeleteAssign(string delData){ Node delPtr = NULL; temp = head; current = head; while(current != NULL && current->hw != delData){ temp = current; current = current->next; } if(current == NULL){ cout << delData << " was not in the list\n"; delete delPtr; }else{ delPtr = current; current = current->next; temp->next = current; if(delPtr == head){ head = head->next; temp = NULL; } delete delPtr; cout << "The Value " << delData << " was deleted\n"; } } void List::PrintList(){ current = head; while(current!= NULL){//is not last node cout << current->hw << endl; current = current->next; } }
listmain.cpp
Code:#include <cstdlib> #include "List.h" #include <string> #include <iostream> #include <list> using namespace std; int main(int argc, char** argv) { List assign; string date = "3/9/13"; assign.AddAssign("3/4/13,Calculus,77"); assign.AddAssign("3/7/13,Programming,88"); assign.AddAssign("3/15/13,English,89"); assign.AddAssign("3/23/13,Physics,78"); cout<<"Starting list..." << endl; assign.PrintList(); return 0; }



LinkBack URL
About LinkBacks



