Answered step by step
Verified Expert Solution
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 filereading 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 numSwappedSIZE; number of colors swapped in a sentence vector vColors;
string sentencesSIZE;
vector vPhrases;
int totalSentences; number of sentences read
int sentencesSwapped; 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 colorFileColorstxt;
string sentenceFileSentencestxt;
string swapPhrasesFileSwapPhrasestxt;
string outputFileOuttxt;
bool bRead;
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 ReadFilesstring 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 WriteFilestring 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 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 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 Goodbye message to the screen.
Functions.h
#ifndef FUNCTIONSH
#define FUNCTIONSH
#include
#include
using namespace std;
string WriteHeader;
void AskForFileNamesstring& colorFile, string& sentenceFile string& phraseFile;
string AskForOutputFile;
void Goodbye;
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started