Question: hi need to complete TextFile.cpp #ifndef SDDS_TEXTFILE_H__ #define SDDS_TEXTFILE_H__ #include namespace sdds { class Text; class Line { char* m_value{ nullptr }; operator const char*

hi need to complete TextFile.cpp

#ifndef SDDS_TEXTFILE_H__ #define SDDS_TEXTFILE_H__ #include namespace sdds { class Text; class Line { char* m_value{ nullptr }; operator const char* ()const; Line() {} Line& operator=(const char*); ~Line(); friend class TextFile; // copy and copy assignment prevention goes here Line& operator=(const Line&) = delete; Line(const Line&) = delete; };

class TextFile { Line* m_textLines; char* m_filename; unsigned m_noOfLines; unsigned m_pageSize; void setFilename(const char* fname, bool isCopy = false); void setNoOfLines(); void saveAs(const char* fileName)const; void setEmpty(); public: TextFile(unsigned pageSize = 15); TextFile(const char* filename, unsigned pageSize = 15); TextFile(const TextFile&); TextFile& operator=(const TextFile&); ~TextFile(); std::ostream& view(std::ostream& ostr)const; std::istream& getFile(std::istream& istr); operator bool()const; unsigned lines()const; const char* name()const; const char* operator[](unsigned index)const; }; std::ostream& operator<<(std::ostream& ostr, const TextFile& text); std::istream& operator>>(std::istream& istr, TextFile& text);

} #endif // !SDDS_TEXTFILE_H__

cstring.h:

#ifndef SDDS_CSTRING_H_ #define SDDS_CSTRING_H_ namespace sdds { void strCpy(char* des, const char* src); int strLen(const char* s); void strCat(char* des, const char* src); } #endif // !SDDS_CSTRING_H_

TextFile.cpp:

#include #include #include #include "TextFile.h" #include "cstring.h" using namespace std; namespace sdds {

Line::operator const char* () const { return (const char*)m_value; } Line& Line::operator=(const char* lineValue) { delete[] m_value; m_value = new char[strLen(lineValue) + 1]; strCpy(m_value, lineValue); return *this; } Line::~Line() { delete[] m_value; }

}

cstring.cpp:

#include "cstring.h" namespace sdds { void strCpy(char* des, const char* src) { int count = 0; for (int i = 0; src[i] != '\0'; i++) { des[i] = src[i]; count++; } des[count] = '\0'; }

// returns the lenght of the C-string in characters int strLen(const char* s) { int len = 0; while (s[len] != '\0') { len++; } return len; }

void strCat(char* des, const char* src) { int desSize = strLen(des); int i = 0; while (src[i] != '\0') { des[desSize + i] = src[i]; i++; } des[desSize + i] = '\0'; return; }

}

w6p1_tester.cpp:

#include #include #include #include "TextFile.h" using namespace sdds; using namespace std;

void FirstTen(TextFile T); void Copy(const string& dest, const string& source); void Dump(const string& filename); int main() { TextFile Empty; TextFile BadFilename("badFilename"); Copy("echoes.txt", "echoesOriginal.txt"); Copy("seamus.txt", "seamusOriginal.txt"); TextFile E; TextFile S("seamus.txt"); cout << "Type echoes.txt and hit " << endl; cout << "Enter the text file name: "; cin >> E; cout << E << endl; cout << S << endl; FirstTen(E); FirstTen(S); E = S; cout << E << endl; cout << "============================================================" << endl; Dump("echoes.txt"); Dump("seamus.txt"); Dump("C_echoes.txt"); Dump("C_seamus.txt"); cout << "*" << Empty << BadFilename << "*" << endl; return 0; } void FirstTen(TextFile T) { if (T) { cout << ">>> First ten lines of : " << T.name() << endl; for (unsigned i = 0; i < 10; i++) { cout << (i + 1) << ": " << T[i] << endl; } } else { cout << "Nothing to print!" << endl; } cout << endl << "-------------------------------------------------------------" << endl; } void Dump(const string& filename) { cout << "DUMP---------------------------------------------------------" << endl; cout << ">>>" << filename << "<<<" << endl; ifstream fin(filename.c_str()); char ch; while (fin.get(ch)) cout << ch; cout << endl << "-------------------------------------------------------------" << endl; } void Copy(const string& dest, const string& source) { ifstream fin(source.c_str()); ofstream fout(dest.c_str()); char ch; while (fin.get(ch)) fout << ch; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!