Hello! I am currently writing a program that takes last name, first name , pay rate, hours worked and calculates the tax and net pay. I have figured everything out except how to sort it.
I have not been taught vectors in my class yet. I'm assuming I need to take the last name string and put it into an array and sort it, but i haven't been able to do it.
here is my input data
Marion Louise 13.00 40.00
Davidson Carl 8.75 38.00
Whittle Ed 11.50 25.50
John Doe 17.00 46.50
Prentiss Paula 15.75 50.50
You need to know how big to make the array before you can put things in it. That means you need to go through the file twice - once to figure out how much space you need, and again to actually fill the space once you've gotten it.
I would be willing to learn std:string. I will look up what i can on that.
No i do not want to file juggle. I am just getting back into programming after a long break so I am refreshing and trying to remember if there is another way to do it.
I am trying to sort by last name alphabetically so i was wondering if i was able to just sort by the information being held in the variable lastN. and have the rest of the variables follow along. (again just trying to refresh my possibilities)
I would be willing to learn std:string. I will look up what i can on that.
What? You use it on lines 5, 22, and 23 already...
gogobumrush wrote:
No i do not want to file juggle. I am just getting back into programming after a long break so I am refreshing and trying to remember if there is another way to do it.
Aside from std::vector, not really.
gogobumrush wrote:
I am trying to sort by last name alphabetically so i was wondering if i was able to just sort by the information being held in the variable lastN. and have the rest of the variables follow along. (again just trying to refresh my possibilities)
Yes, you can do that with a custom compare function passed to the sorting algorithm you use.
Is it out of the question for you to use vectors? In my classes, if you ask, the professor usually does not mind if you use your own way of completing an assignment, especially if you are doing it using real-world solutions, IE utilizing the work of those before you and not reinventing the wheel.