Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is C + + , read the instructions carefully don't rush it each comment has / / answer all of them with code and
This is C read the instructions carefully don't rush it each comment has answer all of them with code and what the comments said ColorFunctions.h #ifndef COLORFUNCTIONSH
#define COLORFUNCTIONSH
#include
#include
#include
using namespace std;
const int SIZE;
struct SentenceData
int numSwappedSIZE;
string sentenceSIZE;
int total;
vector rvColors;
vector rvPhrases;
ofstream output;
string resultsOriginal;
string resultSwapped;
string colorFile "Colors.txt;
string sentenceFile "Sentences.txt;
string swapPhrasesFile "SwapPhrases.txt;
string outputFile "Out.txt;
;
void WriteHeader;
void AskForInputFilenamesstring& colorFile, string& sentenceFile string& phraseFile;
string AskForOutputFilename;
bool ReadColorsvector& rvColors, string filename;
bool ReadPhrasesvector& rvPhrase, string filename;
bool ReadSentencesstring sentences string filename, SentenceData& data;
bool WriteOriginalsSentenceData& data, int totalSentencesModified, string filename;
bool WriteResultsSentenceData& data, string filename;
int SwapColorsSentenceData& data;
void SayGoodbye;
#endif ColorFunctions.cpp #include "ColorFunctions.h
#include
void WriteHeader
put your name, course and program information
void AskForInputFilenamesstring& colorFile, string& sentenceFile string& phraseFile
There will be deafult filenames, the ones in your project.
Ask the user for the color filename, and give them the choice of the default.
Then do the same for reading sentences and phrases.
string AskForOutputFilename
Ask the user to enter a filename for the output file. There can be a default
Be sure to tell the user the form, at of the filename or give the, an example
read the filename entered, if any
return filename;
bool ReadColorsvector& rvColors, string filename
open the input stream
open the file
check if it is ok
return false if not good
make a for loop or a while or dowhile loop
read a temp variable. then add to the vector, only one word
close the file
return true;
bool ReadPhrasesvector& rvPhrase, string filename
same as read colors, but more than one word, need a getline
return false;
bool ReadSentencesstring sentences string filename, SentenceData pData
This time we were reading into any array use getline again
assign to the array at the index corresponding to the loop
use a while loop and read to eof && SIZE
keep track of the number of sentence read and assign to total
return false;
bool WriteOriginalsSentenceData& data, int totalSentencesModified, string filename
This is just a stringstream to write the sentences, the color and the phrases
If you do this, you can also cout the ssstr;
return false;
bool WriteResultsSentenceData& data, string filename
return false;
int SwapColorsSentenceData& data
create a variable for the number of sentences swapped
int totalSentencesSwapped;
search each sentence for all of the colors
use a for loop going to data.total
have to handle that first word is capitalized
make your sentence all lower case and then after the swapping,
replace the capital letter at the beginning
look for functions that look like to lower or something like that or use ascii table
then we need an inner loop for the colors
search for each color using the string function find
the find function returns an int, which is the position of thr first
letter of the string. If the string is not found, it returns
so you need to check the return from the function
if it is a positive number, then you have to exchaange the color or a phrase
But the phrase will be longer than the color.
You can get the length of the color name and look for string functions like replace
them keep track of the number of colors swapped
make the first letter a capital. then return the swapped sentence
return ; number of sentences that are modified
SayGoodbye
cout a nice goodbye
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