CS1210 – C++ Programming Points: 40 Objective: Develop a C++ program which when
ID: 3632991 • Letter: C
Question
CS1210 – C++ Programming
Points: 40
Objective: Develop a C++ program which when given a Bible reference (i.e., book, chapter, and verse) reads a file of Bible text to find and prints the referenced verse.
Discussion: 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. Examples for using the fstream library appear in display 6.2 (pg 317) and the file I/O summary (pg 318) in your textbook. You can also find another example (file_io_example.cpp) on our class web.
To complete this assignment your program should prompt for a Bible reference: that is a book, chapter and verse. The Bible book name should be given as a full name (if you would like to use abbreviations, please see extra credit below). The program should then search a file of Bible text for the referenced verse. If the verse is found, then the verse should be printed to the screen and appended to an output file. If the verse is not found (e.g., the book was misspelled or the chapter or verse reference was incorrect), then the program should report that the verse was not found. You can find an example of this program and the file of Bible text at /home/vfang/public. The program is called hw8 and the file of Bible text is called KJV_Bible.txt.
Please also take note of some other program details addressed in the section “Additional Details” on the next page.
Style:
a. Please be sure to properly comment you program and use appropriate white space. This include proper indentation.
b. Please provide meaningful, brief comments to give better understanding to the logic of each block of your code.
c. Use meaningful variable names
Additional Details:
Note: Your program must meet the following additional requirements:
• It must append the requested verses, if found, to an output file. The output file can be any name you choose (I used “verses.txt”), but must have a “.txt” extension.
• It must report when a verse cannot be found and why, to let the user know there was a problem. This error message should *not* be appended to the output file.
• Be sure to test you program with different verses to make sure your program is robust. For example, you might try to find the first verse of a book, or the last, or the first verse from a chapter. You should also try various books. I recommend you try to find verses in the Psalms—particularly Psalms 119.
Example: An example run of hw8 is shown below (the user enters the underlined text). It includes an example of retrieving a valid reference and shows the errors the program reports for invalid requests:
john% >hw14
Please enter reference of the verse you would like to retrieve
the book: John
the chapter: 3
the verse: 16
The verse you want is:
John 3:16 For God so loved the world, that he gave his only begotten Son,
that whosoever believeth in him should not perish, but have
everlasting life.
john% >hw14
Please enter reference of the verse you would like to retrieve
the book: Hezekiah
the chapter: 1
the verse: 1
The Bible does not contain the book "Hezekiah"
john% >hw14
Please enter reference of the verse you would like to retrieve
the book: Jude
the chapter: 2
the verse: 1
The book Jude does not have chapter 2
john%temp>hw14
Please enter reference of the verse you would like to retrieve
the book: Philemon
the chapter: 1
the verse: 30
Chapter 1 of book Philemon does not have verse 30
***Note the names of the books are formatted
THE BOOK OF <book name in caps>
the chapters are on a new line formatted
CHAPTER <number>
then the verses are on a new line with one space right after the number then the verse immediatly following.
So far I have this but i don't know how much of it is right
Explanation / Answer
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void main()
{
ifstream bible;
ifstream words;
ofstream concordance;
string word_in;
concordance.open("conc.txt");
bible.open("bible.txt");
words.open("words.txt");
while(!words.eof())
{
getline(words,word_in);
}
}
int messageNumber;
int count;
string message;
ifstream in;
in.open("words.txt");
messageNumber = rand() % someNumber; //maybe someNumber is the #of lines in the text file
for(int i = 0; i < rand()%messageNumber+1; i++)
{
getline(in, message);
}
cout << message; //
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
fstream judeReader;
judeReader.open("Jude.txt");
string searchTerm = "Jesus"; //"God", etc...
string temp;
int counter = 0;
while(!judeReader.eof())
{
judeReader >> temp;
if (temp == searchTerm)
{
counter++;
}
}
cout << searchTerm << " appeared " << counter << " times." << endl;
judeReader.close();
return 0;
}