Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

calyne Group Title

PLEASE HELP [C++] alphabetical sort ?!?!? http://www.daniweb.com/software-development/cpp/threads/421354/alphabetical-sort-class-object-vector-array- details in there

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    In both your friends instructions and the advice given in the forum you have the answer you need. The user on the forum even wrote the function for you, leaving you to fill in the condition. You simply need to decide how you will evaluate one object over another and place that as the conditional in the if statement. Perhaps this will clear it up a little more for you: http://www.cplusplus.com/reference/algorithm/sort/

    • 2 years ago
  2. iHelp Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Y not just use the ASCII values?

    • 2 years ago
  3. calyne Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    espex - i still don't ge tit, and i did check that page already.

    • 2 years ago
  4. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    There are many different sorting algorithms. Which one to use depends on how many items need sorting and how random their order is before sorting. Choosing which algorithm is up to you. All sort algorithms require two helper functions. One to compare the two items in question, and another to swap them if needed. Swapping is simple enough. Comparison functions are needed for different data types. Usually, they return an int. Usually they return -1 for a<b, 0 for a==b and +1 for a>b. The calling code handles what to do depending on the int returned. string has a comparison member function that follows the norm, and it's not too bad to learn. Write a separate test program to get used to it. Mine was 10 lines of code.

    • 2 years ago
  5. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    The sort() function takes three arguments, a starting point, an ending point, and a means to compare the two. Your friend gave you these instructions: "Just create a new function that takes two employee objects by reference and returns a Bool. The whole function is one if else statement where you check whether the first parameter name is less than the second parameter name and return true or false accordingly. Then simply pass the name of the function to the sort function as if it was a variable" So if the method you create is called mySort(), you would call sort(start, end, mySort), your task is to create that comparison method. One such way to compare would be to take in a record, pull the last name and compare the first letters. If you had Smith and Jones and compared S to J, then J has a value less than that of S so you decide how to handle that, ascending or descending sort.

    • 2 years ago
  6. calyne Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    that's roughly what i've been working with, except i can't get it working, so i don't need "roughly", i need like exactly, in context, because i don't know this t all and i'm not figuring it out

    • 2 years ago
  7. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    As I did not see anywhere that you could not use string compare then you could easily adapt the example given here: http://www.cplusplus.com/reference/string/string/compare/ to return which string is greater. Likewise you could compare the first character of each string and let that be your test for equality as is done in this example: http://www.cplusplus.com/reference/clibrary/cstring/strncmp/ OR you could even say if(record::name1[0] > record::name2[0]) return record::name1; Hope that helps.

    • 2 years ago
  8. calyne Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    how do i go through and sort all of them that way... i'm sorry hah what can i say i don't GET IT but ok i'll work with it just answer me that and let's see

    • 2 years ago
  9. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ultimately, strings are arrays of characters. You can iterate through them one character at a time.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.