input items to a list

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

input items to a list

 
0
  #1
Feb 12th, 2009
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.

  1. // This is the .cpp file.
  2. #include "unsorted.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. UnsortedType list;
  9. ItemType item;
  10. list.MakeEmpty();
  11. item.Initialize();
  12.  
  13. cout << "Enter number (-999 to quit): ";
  14. cin >> item;
  15. list.InsertItem(item);
  16.  
  17. }
  1. // This is the unsorted.h file.
  2. #include "itemtype.h"
  3.  
  4. class UnsortedType
  5. {
  6. public:
  7. UnsortedType();
  8. bool IsFull() const;
  9. int LengthIs() const;
  10. void RetrieveItem(ItemType& item, bool& found);
  11. void InsertItem(ItemType item);
  12. void DeleteItem(ItemType item);
  13. void ResetList();
  14. void MakeEmpty();
  15. void GetNextItem(ItemType& item);
  16. private:
  17. int length;
  18. ItemType info[MAX_ITEM];
  19. int currentPos;
  20. };
Last edited by sfrider0; Feb 12th, 2009 at 1:55 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: input items to a list

 
1
  #2
Feb 12th, 2009
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).
"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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: input items to a list

 
0
  #3
Feb 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: input items to a list

 
1
  #4
Feb 13th, 2009
>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.
"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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: HAZEM8002 is an unknown quantity at this point 
Solved Threads: 0
HAZEM8002 HAZEM8002 is offline Offline
Newbie Poster
 
0
  #5
25 Days Ago
thanx
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC