trying to figure out the reason for memory loss any ideas would be helpful requirements should be done however i need a working file for turn in thanks for help.
leak seems to be around line 59-61 i think in demo.cpp
Demo.cpp
/* File Name: Demo.cpp
Chapter No. 15 - Exercise No. 5
Programmer: Carl Sue
Date Last Modified: Apr 17, 2010
Problem Statement: (what you want the code to do)
A file filter reads an input file, transforms it in some way, and writes
the results to an output file. Write an abstract file filter class that
defines a pure virtual function for transforming a character. Create
one subclass of your file filter class that performs encryption, another
that transforms a file to all uppercase, and another that creates an
unchanged copy of the original file.
The class should have a member function
void doFilter(ifstream &in, ofstream &out)
that is called to perform the actual filtering. The member function for
transforming a single character should have the prototype
char transform(char ch)
The encryption class should have a constructor that takes an integer as
an argument and uses it as the encryption key.
Overall Plan (step-by-step how you want the code to make it happen):
0. create instances of subclasses
1. read data in from a file
2. Preform enctiption
3. set all to uppercase
4. transfer unchanged form input to output
5. output done.
etc.
Classes needed and Purpose (Input, Processing, Output):
*/
#include <iostream>
#include <fstream>
#include "FileFilter.h"
#include "Encripted.h"
#include "ToUpper.h"
#include "Copy.h"
using namespace std;
int main(int argc, char * const argv[]){
ifstream input;
ofstream toUpper, encrypt, copy;
ToUpper up;
Copy cpy;
input.open("original.txt", ios::in);
toUpper.open("ALLUPPER.txt", ios::out | ios::trunc);
encrypt.open("encription.txt", ios::out | ios::trunc);
copy.open("copy.txt", ios::out | ios::trunc);
if (input.fail()) {
cout << "File not found";
return 1;
}
cout << "Enter encription value(int):";
int encryptionValue = 5;
cout << "data loss here i think";
Encripted encrypted(encryptionValue);
up.doFilter(input,toUpper);
cout << "Upper done...";
cpy.doFilter(input,copy);
cout << "copy done...";
encrypted.doFilter(input,encrypt);
cout << "encryption done...";
return 0;
}
FileFilter.cpp
/*
* FileFilter.cpp
*
* Created on: May 16, 2010
* Author: Carl
*/
#include "FileFilter.h"
FileFilter::FileFilter() {
// TODO Auto-generated constructor stub
}
FileFilter::~FileFilter() {
// TODO Auto-generated destructor stub
}
void FileFilter::doFilter(ifstream &in, ofstream &out){
vector<string> page;
while(!in.eof()){
char line[50];
in.getline(line, 49, '\n');
for (int i = 0; i < strlen(line); i++) {
line[i] = transform(line[i]);
}
string strLine = line;
page.push_back(strLine);
}
for (int i = 0; i < page.size(); i++) {
out.write(page[i].c_str(), page[i].length());
}
}
FileFilter.cpp
/*
* FileFilter.h
*
* Created on: May 16, 2010
* Author: Carl
*/
#ifndef FILEFILTER_H_
#define FILEFILTER_H_
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class FileFilter {
public:
FileFilter();
~FileFilter();
virtual char transform(char input) = 0;
void doFilter(ifstream &in, ofstream &out);
};
#endif /* FILEFILTER_H_ */
rest are in zip i can add if needed