Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read the questions carefully and comments provide with the code solution ColorFunctions.cpp #include ColorFunctions.h #include using namespace std; void WriteHeader ( ) { /

Read the questions carefully and comments provide with the code solution ColorFunctions.cpp #include "ColorFunctions.h
"
#include
using namespace std;
void WriteHeader
(
)
{
/
/
put your name, course and program information
cout
"Brayan Licano, C
+
+
1
1
and this is about swapping colors"
"
on the sentences."
endl;
}
void AskForInputFilenames
(
string& 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
cout
"Enter a file name"
filename
endl;
/
/
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 ReadColors
(
vector& rvColors, string filename
)
{
/
/
open the input stream
int input;
fstream filename;
/
/
open the file
/
/
check if it is ok
.
/
/
return false if not good
/
/
make a for loop or a while or do
-
while loop
/
/
read a temp variable. then add to the vector, only one word
/
/
close the file
return true;
}
bool ReadPhrases
(
vector& rvPhrase, string filename
)
{
/
/
same as read colors, but more than one word, need a getline
return false;
}
bool ReadSentences
(
string 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 WriteOriginals
(
SentenceData& 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 ss
.
str
(
)
;
return false;
}
bool WriteResults
(
SentenceData& data, string filename
)
{
return false;
}
int SwapColors
(
SentenceData& data
)
{
/
/
create a variable for the number of sentences swapped
int totalSentencesSwapped
{
0
}
;
/
/
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
-
1
/
/
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
wstringstream wss;
wss
uppercase
s
[
0
]
nouppercase
s
.
substr
(
1
)
;
wss
>
>
s;
return
0
;
/
/
number of sentences that are modified
}
void SayGoodbye
(
)
{
/
/
cout a nice goodbye
cout
"Goodbye"
endl;
}
Driver.cpp #include "ColorFunctions.h
"
using namespace std;
int main
(
)
{
/
/
create a struct variable
SentenceData data;
/
/
Create any variables you will need for main
/
/
be sure to initialize variable like sentenceFile with the default filename
/
/
call the writerheader
(
)
function
WriteHeader;
/
/
Ask for the output file name and after reading it
,
assign it to its variable
/
/
open the output file and check for validity
/
/
Ask for input filenames
/
/
Read the files. Check if any of the reads do not work, then bail
/
/
if all of the reads returned true. The else says says a message like a data filewas not read
/
/
closes the output stream
/
/
if all files were read, then call WriteOriginals, SwapColors, and WriteResults
/
/
then cout the writeOriginal and write results from the struct
WriteOriginals;
/
/
Call the Goodbye function
SayGoodbyCIS 2275 C++ Programming Part II
Program 1 The Color Swap 100 pts
Review functions, pointers/references, multi-file construction, vectors, arrays, structs and
strings
Turn In Requirements:
5 pts Name your Visual C++2022 project LastnameP1, such as NelsonP1.
5 pts First remove BOTH debug folders and the x64, ipch and the
Browse.VC file from your
project before zipping
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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Did you add the logo at correct size and proportion?

Answered: 1 week ago