-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRef.cpp
More file actions
99 lines (87 loc) · 3.88 KB
/
Ref.cpp
File metadata and controls
99 lines (87 loc) · 3.88 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Ref class function definitions
// Computer Science, MVNU
#include "Ref.h"
#include <iostream>
#include <string>
#include <array>
using namespace std;
// GetNextToken - general routine for getting next token from a string
// Parameters
// str - string to search. search is destructive, i.e., token is removed.
// delimiters - string, a list of characters to use a delimiters between tokens
// Returns: string token (removed from str)
string books[66] = { "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehimiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "Song of Songs", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micha", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", "2 John", "3 John", "Jude", "Revelation" };
string GetNextToken(string& str, const string& delimiters = " ") {
// Skip delimiters at beginning
string::size_type startPos = str.find_first_not_of(delimiters, 0);
// Find position of delimiter at end of token
string::size_type endPos = str.find_first_of(delimiters, startPos);
// Found a token, remove it from string, and return it
string next = str.substr(startPos, endPos - startPos);
string rest = str.substr(endPos - startPos + 1, string::npos);
str = rest;
return(next);
}
// Ref member functions
Ref::Ref() {book = 0; chap = 0; verse = 0;} // Default constructor
Ref::Ref(const string s) { // Parse constructor - receives a line "34:5:7 text"
string rtext = s; // make local copy of string to avoid modifying parameter
// parse the reference - notice, currently there is no error checking!
// Get book number
string strbook = GetNextToken(rtext,":");
book = atoi(strbook.c_str());
// Get the chapter number
string strchap = GetNextToken(rtext,":");
chap = atoi(strchap.c_str());
// Get the verse number
string strverse = GetNextToken(rtext," ");
verse = atoi(strverse.c_str());
}
Ref::Ref(const int b, const int c, const int v) { // Construct Ref from three integers
book = b;
chap = c;
verse = v;
}
// Accessors
int Ref::getBook() {return book;} // Access book number
int Ref::getChap() {return chap;} // Access chapter number
int Ref::getVerse() {return verse;}; // Access verse number
// TO DO: implement comparison functions
// REQUIRED: == comparison
bool Ref::operator==(const Ref r) {
if (verse == r.verse && book == r.book && chap == r.chap) {
return true;
}
return false;
}
// OPTIONAL: define < and > comparisons
bool Ref::operator<(const Ref r) const {
if (book < r.book) {
return true;
}
if (book > r.book) {
return false;
}
if (chap < r.chap) {
return true;
}
if (chap > r.chap) {
return false;
}
if (verse >= r.verse) {
return false;
}
return true;
}
// TO DO: modify display function to show book name instead of book number //Store all lines in list, wait to display until you know what last verse'll be
void Ref::display(const int vNum) { // Display Reference
if (book > 0 && vNum > 1) {
cout << "<p>" << "<b>" << books[book - 1] << " " << chap << ":" << verse << "-" << "..." << "</b>" << "</p>";
}
else if (book > 0) {
cout << "<p>" << "<b>" << books[book - 1] << " " << chap << ":" << verse << "</b>" << "</p>";
}
else {
cout << 0 << ":" << chap << ":" << verse;
}
}