biblereader.cpp - Main Line - simple code to test classes

#include "biblereader.h"
#include "Ref.h"
#include "Verse.h"
#include "Bible.h"
#include <iostream>
#include <fstream>
#include <string> 
#include <stdio.h>
#include <stdlib.h>

using namespace std;


int main (int argc, char ** argv) {
        Bible kjv("/home/class/csc3004/Bibles/kjv-complete");
 
 Verse verse;
 int b,c,v;
 LookupResult result;
 cout << "Using Bible from:";
 kjv.display();
 // Get the verse to lookup
 cout <<"What book, chapter and verse?";
 cin >>b>>c>>v;	

 //Create a reference from the numbers
 Ref ref(b,c,v);

 // Look it up in the bible
 cout << "Looking up reference: ";
 ref.display();
 cout << endl;

 verse = kjv.lookup(ref,result);
 cout << "Result: " << endl;
 verse.display();
 cout << endl;
}

Ref.h Reference Class Header - Parse and Retrieve Reference Information

//
// Class Ref
// 
// Mount Vernon Nazarene University
//
// Ref is a class for representing Bible References consisting of
//    * short book   - The book from 1 (Genesis) to 66 (Revalation)
//    * short chap   - The chapter number >1
//    * short verse  - The verse numner >1
//

#include <string> 
#include <stdlib.h>
#ifndef Ref_H
#define Ref_H
using namespace std;

string GetNextToken(string&, const string&);

class Ref {
private:
   short    book, chap, verse;	// Reference information
public:
   Ref();  	// Default constructor
   Ref(string s); 	// Parse constructor - pass "3:5:7"
   Ref(const int,const int,const int); 	// Construct from three integers;
   // Accessors
   int getBook();	// Access book number
   int getChap();	// Access chapter number
   int getVerse();	// Access verse number
   bool operator==(const Ref );	// Compare if two references equal
   void display(); 	// Display Reference
 // Your version must show actual book name
};

#endif//Ref_H

Verse.h - Verse Class Header - Parse and Retrieve Verse content

//
// Class Verse
// 
// Mount Vernon Nazarene University
//
// Verse is a class representing complete Bible Verses, including references
//    * Ref ref          - the reference (1:1:1)
//    * string verseText - the actual verse text
//

#include <string> 
#include <stdlib.h>
#include "Ref.h"
#ifndef Verse_H
#define Verse_H
using namespace std;
class Verse {
 private:
   Ref verseRef;      	// The reference for this verse.
   string verseText;  	// Actual verse text 

 public:
 // (You are free to use a String class)
   Verse();   	// Default constructor
   Verse(const string s);   	// Parse constructor - pass verse string

   // Accessors
   string getVerse();
   Ref getRef();

   //Display Verse on cout
   void display();  	// Display ref & verse with line breaks.
 // This will call verseref.print().
};

#endif //Verse_H

Bible.h - Bible Header - Parse and Retrieve Bible content

//
// Class Bible
// 
// Mount Vernon Nazarene University
//
// Bible is a class for representing a particular version of the Bible
// The bible is created byu giving it a file reference containing the entire
// entire text of the version
//

#include "Ref.h"
#include "Verse.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#ifndef Bible_H
#define Bible_H
using namespace std;
   enum LookupResult { success, no_book, no_chapter, no_verse, other};
class Bible {	// A class for a version of the bible

 private:
   string infile;

 public: 

   Bible();	// Default constructor
   Bible(const string s);	// Constructor  pass a line from bible file
   const Verse lookup( Ref , LookupResult);	// Find a given verse in this Bible
                	// return the status
   const Ref  next(const Ref,	
              LookupResult );	// Return the reference after this ref
   const Ref  prev(const Ref,	
              LookupResult );	// Return the reference before this ref
   const string error(LookupResult);	// Return a String lookup error message
   void display();
};
#endif //Bible_H

ref.cpp - Parse and Retrieve Bible content - Partial code

#include <iostream>
#include <string>
using namespace std;

// GetNextToken - general routine for getting next Token
// Parameters
//    str - string to search.  search is destructive, e.g. tken is removed.
//    delimiters - string list of characters to use a delimiters for tokens
//    returns - string token (removed from str)
//
string GetNextToken(string& str,
     const string& delimiters = " ")
{
  // Skip delimiters at beginning.                                             
  string::size_type lastPos = str.find_first_not_of(delimiters, 0);
  // Find first "non-delimiter".                                               
  string::size_type pos     = str.find_first_of(delimiters, lastPos);

  // Found a token, remove it from string, and return it                       
  string next = str.substr(lastPos, pos - lastPos);
  string rest = str.substr(pos - lastPos + 1,string::npos);
  str = rest;
  return(next);
}


#include "Ref.h"

Ref::Ref() {book = 0; chap = 0; verse = 0;}  	// Default constructor

Ref::Ref(const string s){ 			// Parse constructor - pass "34:5:7 Stuff"
  string rtext = s;
  // parse the reference - notice, currently no error checking!
  if (rtext.length() > 6) {
    // 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 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

   bool Ref::operator==(const Ref::Ref a) {	// Compare if two references equal
      bool result;			// < and > compares might also be useful
      result = (a.book == book) &&
         (a.chap == chap) &&
         (a.verse == verse);
      return result;
   }
   void Ref::display(){ 	// Display Reference
     cout << book << ":" << chap << ":" << verse;
   }
 // Your version must show actual book name


Verse.cpp - Partial code

#include <iostream>

#include "Verse.h"
using namespace std;
   Ref verseRef;      	// The reference for this verse.
   string verseText;  	// Actual verse text 
 // (You are free to use a String class)
   Verse::Verse()  {  	// Default constructor
     verseText = "Uninitialized Verse!";
     verseRef = Ref();
   } 
   Verse::Verse(const string s){ // Parse constructor - pass verse string

}  	

   // Accessors
   string getVerse(){
   
   }

   Ref getRef(){
   
   }

 // Parse reference and verse
   void Verse::display(){  	// Display ref & verse
     verseRef.display();
     cout << " " << verseText;
 }

Bible.cpp - Partial code

#include "Ref.h"
#include "Verse.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#include "Bible.h" 

using namespace std;

Bible::Bible(){infile ="/home/class/csc3004/Bibles/kjv-complete";}	// Default constructor

Bible::Bible(const string s){ infile = s;}	// Constructor  pass a line from bible file

const Verse Bible::lookup( Ref , LookupResult )	// Find a given verse in this Bible
{ 
  Verse aVerse;
  // Get the verse .....
  // return the status
  return(aVerse);
}
const Ref  Bible::next(const Ref ref,	
       LookupResult result){};	// Return the reference after this ref

const Ref  Bible::prev(const Ref ref,	
       LookupResult result){};	// Return the reference before this ref

const string Bible::error(LookupResult result){};	// Return a String lookup error message

void Bible::display() {cout << "Bible: " << Bible::infile << endl;}
Topic revision: r1 - 2016-02-09 - BenjaminKindle
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback