#OT.txt Lookup

49 messages · Page 1 of 1 (latest)

little gust
#

Hi guys, I've been struggling with C++ lately and was wondering if I could get any help with this assignment and a step by step! It would be much appreciated!

"In this assignment you will become familiar with file I/O by reading and writing files using the C++ fstream library. This library allows you to use the familiar >> and << operators for input and output on files.

You can find examples for using the fstream library in Chapter 6 of this Zybook.

To complete this assignment, satisfy the following requirements:

Your program should first prompt for an Old Testament reference: that is, a book, chapter and verse (each part on its own line).
You can expect that the Bible book name will be complete, not an abbreviation.
Two-part books (i.e. First Samuel & Second Samuel) will be input with "First" and "Second" spelled out.
Your program should search the provided file of Old Testament text (OT.txt) for the referenced verse.
If the verse is found, your program should print the verse to the screen and append it to an output file (called verses.txt).
If the verse is not found (e.g., the book name was misspelled or the chapter or verse reference was incorrect), then your program should report that the verse was not found, because the book, chapter or verse (whichever applies) is not in the Old Testament. In order for your assignment to be graded accurately, you will need format your "not found' output as illustrated below in the Examples."

Thanks!

small carbonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

rich juniper
#

Where are you stuck?

little gust
#

So I made the part where I have to open the file. But how do I make it so that when the user inputs for example "Genesis", "3" "23" it will output that verse?

worldly sedge
#

That's what you have to figure out. Do you know how to do that in words? Ie what algorithm, possible structures to use? What to do with the OT text? It's presumably in some sort of format that helps you identify chapter verse etc?

little gust
#

Possibly if/else statements, would that work when searching for a specific line in a file?

rich juniper
#

May we see the file?

little gust
#

I have a screenshot

rich juniper
#

So, if you wanted to find the start of every book, what would you search for?

little gust
#

Well I'd search for the header, but the users input could only be "Jonah" not "THE BOOK OF JONAH", I'm really confused on how I would write that in code

rich juniper
#

Sure, so you add that prefix yourself, eh?

#

I would encourage you to think about what problem you are trying to solve before getting wrapped around the axle in how to implement it.

little gust
#

Of course

rich juniper
#

So, you know you need to get book chapter and verse and that you need to prefix the book name with "THE BOOK OF "

#

So having found the book, how will you find the chapter you are looking for?

little gust
#

I suppose doing the same with "CHAPTER "?

rich juniper
#

but starting from where you found "THE BOOK OF <whatever>"

#

What do you have to look out for while looking for the chapter? What if this book has no chapter n but the next book does?

little gust
#

I apologize, but now I'm really lost 😂

rich juniper
#

Same thing with verse. This chapter may have no verse n but the next chapter does.

little gust
#

Would I have to write an else statement for that?

rich juniper
#

Just think about the problem, not how you would write the code

little gust
#

Right

rich juniper
#

So take your screen shot for example...

#

you are asked for Jonah but in the text of the file that is JONAH

little gust
#

So like if someone is searching for the character Jonah in the book of Jonah?

rich juniper
#

No, as I understand it you will prompt for the book name, the chapter number and the verse number, correct?

little gust
#

Yes

rich juniper
#

So instead of typing JONAH, what if they type Jonah?

little gust
#

Well in the grading of this assignment, the user is required to write Jonah, not JONAH

#

So I would write an error statement for that

#

Or just exit the program

rich juniper
#

you know users, eh? give them a prompt for data and they can type anything. Why not just uppercase whatever they type and search for that?

little gust
#

How would I do that?

#

I really apologize for my ignorance, and if you need to leave please do. I'm very behind on this class and CS is just not my major

rich juniper
#

for now is it not sufficient to make a list of the things you need to do?
prompt for book name.
whatever they enter convert it to uppercase.
prefix the book name with THE BOOK OF
prompt for chapter
whatever they enter, make sure its a number
prompt for verse
whatever they enter, make sure its a number

Make sense?

little gust
#

Yes that makes sense

rich juniper
#

My point is to think through how you will solve the problem before writing any code.

little gust
#

I see what you mean, way more easier to figure out now

rich juniper
#

cool, progress... 🙂 Ok, so what's next?
open the file
find the book in the file
handle any failures
find the chapter without going beyond the end of the book
handle any failures
find the verse without going beyond the chapter
handle any failures
print out whatever is required for the assignment
clean up, close files, free memory, whatever.

#

Good enough for an outline or have I missed anything?

little gust
#

No I actually think you nailed that perfectly

#

That was actually really helpful too, in terms of changing the way I think and look at code

rich juniper
#

Excellent. Give it a go and ask questions when you get stuck.

little gust
#

Of course, thank you

small carbonBOT
#

@little gust Has your question been resolved? If so, type !solved :)

little gust
#

So question while writing the code, so if I'm looking for a certain book, should I use a while loop that'll go until it finds it?

rich juniper
#

Sure, you could read the file a line at a time and check if it starts with THE BOOK OF<whatever>

little gust
#

!solved