| | |
input items to a list
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 0
Hey. I'm trying to simply input items into a list, then be able to sort them and do whatever. I've done this before for my previous classes, but we have we have to use class files out of the book and modify them to make this work and I'm having way too much trouble. If somebody could point me in the right direction, it would be much appreciated.
I created the .cpp file. The unsorted.h is from the book. There are a couple of more files, let me know if they are needed.
I created the .cpp file. The unsorted.h is from the book. There are a couple of more files, let me know if they are needed.
C++ Syntax (Toggle Plain Text)
// This is the .cpp file. #include "unsorted.h" #include <iostream> using namespace std; int main() { UnsortedType list; ItemType item; list.MakeEmpty(); item.Initialize(); cout << "Enter number (-999 to quit): "; cin >> item; list.InsertItem(item); }
C++ Syntax (Toggle Plain Text)
// This is the unsorted.h file. #include "itemtype.h" class UnsortedType { public: UnsortedType(); bool IsFull() const; int LengthIs() const; void RetrieveItem(ItemType& item, bool& found); void InsertItem(ItemType item); void DeleteItem(ItemType item); void ResetList(); void MakeEmpty(); void GetNextItem(ItemType& item); private: int length; ItemType info[MAX_ITEM]; int currentPos; };
Last edited by sfrider0; Feb 12th, 2009 at 1:55 am.
Why are you using 'ItemType' for your lists? Is this some sort of generic container-type object? (Presumably it overloads the '>>' operator, since you were using it in main().) If I were designing the UnsortedType class, I would probably use a template so the object type can be specified when a new instance of the class is defined.
It also seems a bit of a waste the way you store and pass objects, if it's possible, try passing by reference so you don't end up with as much overhead on the stack (since you're going to have to copy the object into the internal array anyway).
It also seems a bit of a waste the way you store and pass objects, if it's possible, try passing by reference so you don't end up with as much overhead on the stack (since you're going to have to copy the object into the internal array anyway).
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 0
That's exactly what I was thinking. The directions specifically said to put the input data into an "item", then put the item in the list. Right now I keep getting errors when I use the "cin >> item" then try to store that into the list. I just get an ItemType error. What exactly do I have to initialize in the "item.Initialize(????)" to get this to work. This whole method of doing this seems messed up.
>Right now I keep getting errors when I use the "cin >> item"
Well, then clearly you haven't overloaded the '>>' operator for ItemType.
>What exactly do I have to initialize in the "item.Initialize(????)"
>to get this to work.
You've never posted how ItemType was defined, so can't help you there. Either make due with the current ItemType structure (perhaps modify it if you're allowed), or you're going to have to use a different structure to hold your list nodes, such as an integer.
Well, then clearly you haven't overloaded the '>>' operator for ItemType.
>What exactly do I have to initialize in the "item.Initialize(????)"
>to get this to work.
You've never posted how ItemType was defined, so can't help you there. Either make due with the current ItemType structure (perhaps modify it if you're allowed), or you're going to have to use a different structure to hold your list nodes, such as an integer.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
![]() |
Similar Threads
- Starting Python (Python)
- help in function to return the number of items greater than certain number (C++)
- Please help with link list reading back the list (C++)
- Removing an item from head of linked list (C)
- Verbal raw input? (Python)
- Sorted linked list help (C++)
- help with adding items to a linked list. (Java)
- find out the error in my code (Java)
- YaBasic: The beginners choice (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: building sphinx4 helloworld in netbeans - errors
- Next Thread: C++ Improving my code - semaphores and mutex
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






