Could I get some assistance on this assignment I am a little stuck. I need to cr
ID: 3827897 • Letter: C
Question
Could I get some assistance on this assignment I am a little stuck. I need to create it from scratch using visual studio.
ProgrammingAssignment4.pdf (SECURE -Adobe Acrobat Reader DC D) File Edit View Window Help Home Tools Programmin x gAssig. 37% CS185 Programming Assignment 4 Spring 2017 Due Friday, 28 April 2017 For this programming assignment we are creating a file filter that will read in an input file transforms it in some way and then writes the results to an output file You will need to write an abstract file filter class called FileFilter, (Chapter 15 Section 7 page 945 for abstract classes) that defines a pure virtual function for transforming a character You will create a three derived classes of your file filter class that are explained below Your abstract file filter class will contain the following member functions void doFil ter (ifstream & in, ofstream & out) Type here to search sign In 7:03 PM 4/27/2017Explanation / Answer
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
#include <ctype.h>
#include<stdlib.h>
#include <iomanip>
using namespace std;
class FileFilter
{
public:
virtual string transform(char ch)=0;
void doFilter(ifstream &in,ofstream &out);
};
void FileFilter::doFilter(ifstream &in,ofstream &out)
{
char ch;
string transString,str;
in.get(ch);
while(!in.fail())
{
str.erase(str.begin(),str.end());
str.push_back(ch);
if(str=="\")
transString=transform(' ');
else
transString=transform(ch);
out<<transString;
in.get(ch);
}
}
//replace every tab with three spaces
class TabReplacement:public FileFilter
{
public:
string transform(char ch)
{
string str;
str.push_back(ch);
if(ch==' '){
//str=" "; //three spaces
return str;
}
return str;
}
};
class DoubleSpace:public FileFilter
{
public:
string transform(char ch)
{
string str;
if(ch!=' ' && ch!=' ')
{
str=" ";
str.push_back(ch);
return str;
}
str.push_back(ch);
return str;
}
};
class UpperCase:public FileFilter
{
public:
string transform(char ch)
{
string str;
str.push_back(ch);
if((ch>=65 && ch<=90)||(ch>=97 && ch<=122))
{
str.erase(str.begin(),str.end());
str.push_back(toupper(ch));
return str;
}
str.push_back(ch);
return str;
}
};
void printFile(string file)
{
string line;
ifstream myfile (file);
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << ' ';
}
myfile.close();
}
else cout << "Unable to open file";
}
int main(int argc,char **argv)
{
string infile,outfile;
cout<<"Enter the name of input file: ";
cin>>infile;
cout<<"Enter the name of output file: ";
cin>>outfile;
ifstream in(infile);
ofstream out(outfile);
if (in.is_open())
cout<<"Input file successfully open for reading. ";
else
{
cout << "Unable to open input file";
exit(0);
}
if (out.is_open())
cout<<"Output file successfully open for writing. ";
else
{
cout << "Unable to open output file";
exit(0);
}
//Upper Case
// UpperCase obj1;
//obj.doFilter(in,out);
TabReplacement obj2;
obj2.doFilter(in,out);
out.close();
printFile(outfile);
//creation of objects
}