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
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
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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
