• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading file Input and Output

 
Mel Ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys have been great at helping figure things out so I'm appreciating your responses!!

My next problem is this, I am suppose to have a program that opens a file and read it as and prints it out. I've done that and that is great. But I then need to open a new file and have that print out as well. I've been going in circles with that. I've already created the new file. here's the code that I have now.



Here's what I thought I could do:



So what the second part of the program is suppose to do is read another file that contains the same names that were in the first file, but in alphabetical order. I'm suppose to show both. I already created that file, like I said, in alpha order, so it's all ready to go. sigh. Any takers?
 
Andrew Tangen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?
 
Mel Ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Tangen wrote:I can't help you without knowing what the problem is. Your second grouping of code will work fine to read the first/last names after only looking at it for 5 seconds, because its no different from your first batch there. You didn't even need that second class as you said you already had the second file in alpha order.

What was the expected behavior opposed to what actually happened?


Ok.. here's what the problem states. FYI, this problem is not taken from any textbook. This is a problem from the teacher himself.

Write a program that reads a file of names where each name is a string consisting of a person’s first name, followed by a blank, then followed by the person’s last name. (Assume that the file contains at most twenty names.) Create a new file with the same names, but where each name is in the form: last name, followed by a comma, followed by a space, then followed by the person’s first name. Assume that the original file is in no particular order, and write the new file in alphabetical order based on last name.


 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a case for some slightly more old-fashioned technology. Write a file of names, on paper, like this
Mel Ram
Andrew Tangen
Campbell Ritchie
Write down some way of putting them into some sort of collection. Write down a way of sorting them, then write how you think you can put them into a new file. And remember you want this in Object-Oriented format. So you need a class to record the names in.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic