hw3 - / hw3.cpp : Defines the entry point for the console...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// hw3.cpp : Defines the entry point for the console application. // / # include "stdafx.h" # include<iostream> # include<fstream> # include<string> # include<cstring> # include<cctype> # include<vector> # include<algorithm> # using namespace std; u int length(char * t) { int count = -1; do count++; while (t[count] != '\0'); return count; } class StM{ public: StM() {text = ""; pos=-1; patlen = 0; count = 0;} StM(char * t); virtual int init(); virtual int operator ++() = 0; int operator ! () const; int position (); void position (int p); int counter(){return count;}//returns the number of iterations protected: char * text; int pos; int patlen; int count; //stores the number of iterations i }; int StM::init() { pos = -1; return operator ++();} i int StM::operator ! () const {return ((pos >=0) & (pos { int StM::position(){ return pos;} void StM::position(int x) {pos=x;} v class BFM : public StM { public: BFM(){}; BFM(char *pat, char *text); // constructor virtual int operator ++ (); private: string pattern; }; } BFM::BFM(char *p, char *t) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
text = t; pattern = p; patlen = length(p); } int BFM::operator ++ () { int lst = length(text) - patlen; int i; for(pos++; pos <=lst; pos++) { for(i = 0; i < patlen & pattern[i] == text[pos + i]; i++){count++;} // counter increment if(i >= patlen) cout << " " << pos + 1 << "\t"; //prints the position i = 0; count ++; //counter incrementation } cout << "\nNumber of counts: " << count << "\n"; pos = -1; return 0; } class KMP : public StM { public: KMP(); KMP(char *, char *); // ~KMP(); virtual int operator ++(); int counter(){return count + preCounter;} char * pattern;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

hw3 - / hw3.cpp : Defines the entry point for the console...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online