Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C + + , any expert that answered my question of ColorFunctions program that's the first program and use it to make a

This is C++, any expert that answered my question of ColorFunctions program that's the first program and use it to make a class with it. Please read the instructions carefully and read the comments carefully. Do NOT change the ColorSwap.h and Functions.h functions because its correct. Provide a code with each comment that looks like this // and the screen shot will be the driver and the other .cpp file Our third program will look the same to the user as the first program. That is, it will write your header information, and then asks the user to enter filename information for the four files. The returns from all of the file-reading and writing are checked and if there are any problems, they are reported to the user. Otherwise, the results are shown to the screen and written to a file. A goodbye message is shown when the program is finished.
This program will be constructed differently than the first. In this program you are going to write a ColorSwap class.
ColorSwap.h
class ColorSwap
{
private:
int numSwapped[SIZE]={}; //number of colors swapped in a sentence vector vColors;
string sentences[SIZE];
vector vPhrases;
int totalSentences{0}; //number of sentences read
int sentencesSwapped{0}; //number of sentences that had their colors swapped
string origResults, finalResults;
//You may use a struct again that contains the variables above. Make the struct in Functions.h and create a SentenceData data; object in the class instead.
//filenames
string colorFile{Colors.txt};
string sentenceFile{Sentences.txt};
string swapPhrasesFile{SwapPhrases.txt};
string outputFile{Out.txt};
bool bRead[3]{0};
//Read the three text files and assign their data to the class variables
void ReadColors();
void ReadSentences();
void ReadPhrases();
//Creates a string with the original information.
void WriteOriginals();
//Creates a string with the final information.
void WriteResults();
//Checks the sentences for the colors, and performs the swaps
void SwapColors();
public:
//Default constructor
ColorSwap()= default;
//Calls the three Read methods, checks that they were successful, assigns the //correct filename into the class variables and if all went well, calls // WriteOriginals(), SwapColors() and WriteResults().
bool ReadFiles(string colorFile, string sentenceFile, string swapPhrasesFile);
//Creates the output filestream, opens the output file, checks that it's ok. If no, returns false. If yes, writes the origResults and finalResults into the file. Closes the file. Returns true.
bool WriteFile(string outputFile);
string GetResults(){ return origResults + finalResults; }
};
There are NO cout or cin statements in the ColorSwap.h or cpp! All data is passed into the class in the ReadFile or WriteFile methods or returned via the Get method.
Since your Program 1 had a Functions.h and .cpp file set that may contain your Ask functions that obtain the filename information, use this code again. Also, your Header function and GoodBye function can be used again. This means you will have 5 files in this program: The Driver, ColorSwap.h and .cpp and Functions.h and .cpp. Do not put interface functions or the Header or Goodbye into your class. They are not the responsibility of the class. Those all go into the Functions.h and .cpp files.
Your main should create one ColorSwap object. After the header is shown, call the functions to get the filenames. Call ReadFiles, passing the input filenames and, assuming that all of the files were successfully read, ask for the output filename. Then call WriteFile. Check the bool return and report back to the user. Display the results using GetResults().
Display a Good-bye message to the screen.
Functions.h
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include
#include
using namespace std;
string WriteHeader();
void AskForFileNames(string& colorFile, string& sentenceFile, string& phraseFile);
string AskForOutputFile();
void Goodbye();
#endif
image text in transcribed

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

Step: 3

blur-text-image

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

Data Science Project Ideas In Health Care Volume 1

Authors: Zemelak Goraga

1st Edition

B0CPX2RWPF, 979-8223791072

More Books

Students also viewed these Databases questions

Question

What advice would you provide to Jennifer?

Answered: 1 week ago

Question

What are the issues of concern for each of the affected parties?

Answered: 1 week ago