Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this program w6p1_tester.cpp #include #include #include #include TextFile.h using namespace sdds ; using namespace std ; void FirstTen ( TextFile T

I need help with this program

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; } 

TextFile.h

#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 }; 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 loadText(); 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__ 

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; } } 

echoesOriginal.txt

Overhead the albatross hangs motionless upon the air And deep beneath the rolling waves In labyrinths of coral caves The echo of a distant time Comes willowing across the sand And everything is green and submarine And no one showed us to the land And no one knows the wheres or whys But something stirs and something tries And starts to climb towards the light Strangers passing in the street By chance two separate glances meet And I am you and what I see is me And do I take you by the hand? And lead you through the land? And help me understand the best I can? And no one calls us to move on And no one forces down our eyes And no one speaks and no one tries And no one flies around the sun Cloudless everyday you fall upon my waking eyes Inviting and inciting me to rise And through the window in the wall Come streaming in on sunlight wings A million bright ambassadors of morning And no one sings me lullabies And no one makes me close my eyes And so I throw the windows wide And call to you across the sky 

seamusOriginal.txt

I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried 

ExecutionOutputSample

Enter the text file name: echoes.txt echoes.txt ========== Overhead the albatross hangs motionless upon the air And deep beneath the rolling waves In labyrinths of coral caves The echo of a distant time Comes willowing across the sand And everything is green and submarine And no one showed us to the land And no one knows the wheres or whys But something stirs and something tries And starts to climb towards the light Strangers passing in the street By chance two separate glances meet And I am you and what I see is me Hit ENTER to continue... And do I take you by the hand? And lead you through the land? And help me understand the best I can? And no one calls us to move on And no one forces down our eyes And no one speaks and no one tries And no one flies around the sun Cloudless everyday you fall upon my waking eyes Inviting and inciting me to rise And through the window in the wall Come streaming in on sunlight wings A million bright ambassadors of morning Hit ENTER to continue... And no one sings me lullabies And no one makes me close my eyes And so I throw the windows wide And call to you across the sky seamus.txt ========== I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried >>> First ten lines of : C_echoes.txt 1: Overhead the albatross hangs motionless upon the air 2: And deep beneath the rolling waves 3: In labyrinths of coral caves 4: The echo of a distant time 5: Comes willowing across the sand 6: And everything is green and submarine 7: 8: And no one showed us to the land 9: And no one knows the wheres or whys 10: But something stirs and something tries ------------------------------------------------------------- >>> First ten lines of : C_seamus.txt 1: I was in the kitchen 2: Seamus, that's the dog, was outside 3: Well, I was in the kitchen 4: Seamus, my old hound, was outside 5: Well, the sun sinks slowly 6: But my old hound just sat right down and cried 7: I was in the kitchen 8: Seamus, that's the dog, was outside 9: Well, I was in the kitchen 10: Seamus, my old hound, was outside ------------------------------------------------------------- echoes.txt ========== I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried ============================================================ DUMP--------------------------------------------------------- >>>echoes.txt<<< I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried ------------------------------------------------------------- DUMP--------------------------------------------------------- >>>seamus.txt<<< I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried ------------------------------------------------------------- DUMP--------------------------------------------------------- >>>C_echoes.txt<<< Overhead the albatross hangs motionless upon the air And deep beneath the rolling waves In labyrinths of coral caves The echo of a distant time Comes willowing across the sand And everything is green and submarine And no one showed us to the land And no one knows the wheres or whys But something stirs and something tries And starts to climb towards the light Strangers passing in the street By chance two separate glances meet And I am you and what I see is me And do I take you by the hand? And lead you through the land? And help me understand the best I can? And no one calls us to move on And no one forces down our eyes And no one speaks and no one tries And no one flies around the sun Cloudless everyday you fall upon my waking eyes Inviting and inciting me to rise And through the window in the wall Come streaming in on sunlight wings A million bright ambassadors of morning And no one sings me lullabies And no one makes me close my eyes And so I throw the windows wide And call to you across the sky ------------------------------------------------------------- DUMP--------------------------------------------------------- >>>C_seamus.txt<<< I was in the kitchen Seamus, that's the dog, was outside Well, I was in the kitchen Seamus, my old hound, was outside Well, the sun sinks slowly But my old hound just sat right down and cried ------------------------------------------------------------- ** 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions