I need to use a class for a program that reads an input file, prints the file, sorts the list then prints the sorted list. This is for a Programming II class. I can see how to print and sort. My issue is the input file and the array. I am trying to make the array a part of the class. What I am trying to do is dynamically allocate the array as a part of the class. I am imagining a member function List.read where the input file will be processed into the array. Is this too complicated for this level? Should I just make the array part of the int main() and pass the array to the member function? Do you actually "pass" the ifstream object to the member function or just have the member function contain the code to access the input file? If the array is a part of the class, then a destructor needs to delete the dynamic memory object, right? If you need code I will post it but I have not really reached a "finish point" yet. I am trying to determine if it is a waste of my time to try it this way.
Jump to Post
My thought is that you're overworking this.
Unless you're committed to linked lists, use a vector. It's comfortable and easy to wear.
The operator overloads required to implement a vector provide a convenient 'on read' sorting system. If possible, before you add to the vector, use the overloaded operators …
Jump to Post
No offense taken. I'm finally out of college, and I've been taken to task a few times at work for doing things in a needlessly complex way.
I'd think reading the file twice is not efficient, but I've been primarily working with C, so I can't say if that's …
All 7 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.