A function to compare strings in a class

Hi everyone,

I am having an issue doing part of a homework assignment. We have been building a program that makes a small phone directory, and the names of people are stored in strings (called lastName and firstName). Our teacher wants us to create a const bool function that accepts a class parameter that returns true if an object is greater alphabetically than the parameter. After that, we can use a sort of our choice (heap, bubble, etc.) to sort an array of objects (I'm using vectors) and do the comparisons using the function I created above. The instructions say I can put the sort function in my main program file or a separate file

I am having some trouble doing this and understanding it fundamentally. How do I use both the function and the sort together? How can I call the function (do I need a loop when I call it)? And more importantly, how do I go about coding it? Would I use a string comparison here?

Thanks for any help in advance!
How do I use both the function and the sort together? How can I call the function (do I need a loop when I call it)? And more importantly, how do I go about coding it? Would I use a string comparison here?


Remember a function should do one job and do it perfectly
So no you don't combine the bool and sort functions
If s1="crowsfeet" and s2="grouse"
then cout<<(s1>s2?s1:s2);//prints grouse
Iterate through the array or vector and determine if s[0]>parameter,s[1]> etc. and print out s[0] = true else s[0]=false ....and so on.
Topic archived. No new replies allowed.