| | |
Class Troubles...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 9
Reputation:
Solved Threads: 0
Okay so the deal is, our instructor wrote what the class is supposed to look like (will be included with the code) and also gave us the Input, Preconditions, Process, Output, and Postcondtions of each function that is supposed to be used. I'm having trouble with an insert, delete, and clear functions dealing with the array. There is no USER input, we're just supposed to test the functions within the main function. Here's the code I've written thus far. Any help would be much appreciated!! Thanks for your time.
Code:
Each time I try to write the delete function, I get a runtime error. Stack around A is corrupt. Not sure what to do.
iTsweetie
Code:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; #define DataType int #define Boolean bool #define ARRAYSIZE 0 class SeqList { private: int size; int listitem[ARRAYSIZE]; public: SeqList(void); int ListSize(void)const; Boolean ListEmpty(void) const; Boolean Find(DataType& item) const; DataType GetData(int pos) const; void Insert(const DataType& item); void Delete(const DataType& item); DataType DeleteFront(void); void ClearList(void); }; SeqList::SeqList() { size = 0; } int SeqList::ListSize() const { return size; } Boolean SeqList::ListEmpty() const { if(size == 0) return true; else return false; } Boolean SeqList::Find(DataType& item) const { if(item == listitem[size]) { return true; } else return false; } void SeqList::Insert(const int& item)//Input: Item to insert in the list, no preconditions, Process: //Add the item at the rear of the list., No output, Postconditions: The list has a new item; its size //is increased by one { size++; listitem[size] = item; } DataType SeqList::GetData(int pos) const { if(pos >= size) abort(); else return pos; } void SeqList::Delete(const int& item)//Input: Value to delete from the list, No preconditions, //Process: Scan the list and remove the first occurrence of the item in the list. Take no action if //the item is not in the list, no output, Post conditions: If a match occurs, the list has one fewer //items { if(item != listitem[size]) { abort(); } else for(int i = 0; i < size; i++) { listitem[size]=listitem[size-1]; } } //DataType DeleteFront(void)//No input, Preconditions: List must not be empty, Process: //Remove the first item from the list, output: Return the value of the item that is removed //Post conditions: The list has one fewer items //{ //**Code for delete only with the index listitem[0] //} void ClearList(void)//No input, no preconditions, process: Remove all elements from the list and //set the list size to 0 { } int main() { SeqList A; A.Insert(12); cout << A.ListSize()<<endl; if(A.ListEmpty()) cout<< "The List Is Empty" << endl; else cout<< "The List Is Not Empty" << endl; return 0; }
Each time I try to write the delete function, I get a runtime error. Stack around A is corrupt. Not sure what to do.
iTsweetie
![]() |
Similar Threads
- Spyware troubles (Viruses, Spyware and other Nasties)
- About:Blank troubles and ad/spyware questions (don't worry, it isn't a Hijack log :)) (Viruses, Spyware and other Nasties)
- Please Help : Log File Troubles (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Windows Programming, how to implement such a scroll bar?
- Next Thread: still stuck by the map and veotor
Views: 218 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





