-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNKJV Bible C++ Program.cpp
79 lines (68 loc) · 1.99 KB
/
NKJV Bible C++ Program.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
using namespace std;
map<string, int> books = {
{"Genesis", 1},
{"Exodus", 2},
{"Leviticus", 3},
{"Numbers", 4},
{"Deuteronomy", 5},
// Add additional book names and their corresponding book number
};
int main()
{
string bookName;
int chapter, startVerse, endVerse;
cout << "Enter the name of the book: ";
cin >> bookName;
if (books.count(bookName) == 0)
{
cout << "Error: invalid book name" << endl;
return 1;
}
cout << "Enter the chapter number (0 for full book, -1 for full chapter): ";
cin >> chapter;
if (chapter >= 0)
{
cout << "Enter the starting verse number: ";
cin >> startVerse;
cout << "Enter the ending verse number (0 for full chapter): ";
cin >> endVerse;
}
// Open the file for reading
string filename = bookName + ".txt";
ifstream file(filename);
if (!file.is_open())
{
cout << "Error: unable to open file" << endl;
return 1;
}
// Read the file line by line
string line;
while (getline(file, line))
{
// Check if the line starts with the desired book, chapter, and verse
stringstream ss(line);
int currBook, currChapter, currVerse;
ss >> currBook >> currChapter >> currVerse;
if (currBook == books[bookName] && (chapter == -1 || currChapter == chapter))
{
if (chapter == 0 || (startVerse == 0 && endVerse == 0) || (currVerse >= startVerse && currVerse <= endVerse))
{
// Print the line if the book, chapter, and verse match the criteria
cout << line << endl;
if (endVerse > 0 && currVerse == endVerse)
{
// Stop reading if the end verse has been reached
break;
}
}
}
}
// Close the file
file.close();
return 0;
}