1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help in writing a function to retrieve last item in an unsorted list

Discussion in 'C++' started by elsa87, Nov 17, 2008.

  1. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Relax and destress yourself. This is very simple. You can do it, but not while your head is full of stress and "I can't do this".

    The simple fact is that I can't even give you the answer directly because I also don't have any definitive information on the UnsortedType class. Are you sure you really have absolutely nothing on this? If that's the case then I don't see how your tutor can reasonably expect you to complete the assignment and you should IMMEDIATELY raise this issue with him. This assignment is dependent on knowledge of the UnsortedType class and is impossible if that knowledge is nonexistent.

    What you would be looking for is some code which starts with "class UnsortedType" and that lists the member variables and functions, including info, length, possibly MAX, maybe one or more UnsortedType constructors, a destructor, maybe RetrieveItem() and other functions.

    Earlier you posted some code that started "void UnsortedType::RetrieveItem". Where did you get that from? Did you just make it up; did you hook up /dev/random to a C++ keyword generator, or did you get it from somewhere, e.g. unsortedtype.cpp/unsortedtype.h?

    If the function you have to write has the prototype "ItemType ReturnLastItem();" then the outline of the function must be something like:
    Code:
    ItemType UnsortedType::ReturnLastItem()
    {
      // some processing needed?
      return /* what do we return? */ ;
    }
    
    If any processing is needed it will be to determine which entry is last in the list. At a guess I'd say that was length-1, but nobody it seems knows what length is.
    We return something; what will that be, do you think? You can narrow down the possibilities if you have the class definition, because you'd be looking for something of type ItemType, or maybe an array of them.
     
  2. elsa87

    elsa87 New Member

    Joined:
    Oct 10, 2008
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    mmmmmmmm
    what inforamtion do u need on the UnsortedType class? what difference would it make? can't we just assume we are making a class from scratch?
    last try and im giving up lol
    we have an unsorted list with length that we dont know
    so the last item we are going to retrieve is length-1, right?(by the way..ADT means linked list???)
    and if we are going to just retrive the last item then why do we need processing?
    we will just return(item located in the end of the list)
    bravooooo lol but i have no idea how to implement it loooool
    i was just copying and pasting from my lecture notes to come up with some solution
     
  3. AmNoob

    AmNoob New Member

    Joined:
    Nov 19, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Dont you get it???

    its a MEMBER function which means its in the class Unsorted

    Class UnsortedType{
    .......
    .....
    .......
    ......
    ItemType ReturnLastItem();
    .....
    private:
    .....
    ....
    }

    then you write that function they told you already lol

    ItemType UnsortedType::ReturnItemType()
    {
    return info[length];
    }

    **I just want to know how to write the ReturnItemType the result of that to an OutputFile text, and reading the list from a ready input file text.

    for example:
    input file contains: 10 7 98 54 13 66 4
    how to let the program read the values of the list in the input file which is already there and then let the program create an outputfile txt with the result of ReturnLastItem()... how??????
     

Share This Page