Program Purpose Using Visual Studio 2017 create a console application. Create a
ID: 3901023 • Letter: P
Question
Program Purpose
Using Visual Studio 2017 create a console application. Create a program plan and then convert it into C++ statements. Practice debugging, declaring variables, type casting, formatting output, if statements and input /output to / from the console window and files, input validation, and loops.
Mandatory Instructions
Write a program that will check if a word or a sentence is a palindrome. A palindrome is a word (or sentence) that is the same when read front to back and back to front. For example: race car, mom, poop, etc. Sentences can also be palindromes, for example “Ten animals I slam in a net” is a palindrome.
In order to verify that a word is a palindrome it needs to be reversed and then compared to the original. If both are the same, then we can conclude it is a palindrome. Sentences need a bit more processing. All spaces, punctuation marks have to be first removed from the sentence. Then in (both word and sentence case) we need to upper case all letters. Then sentence needs to be reversed and compared to the compressed and upper cased sentence.
Example:
Initial input: Ten Animals I slam in a net.
Compressed: TenAnimalsIslaminanet
Lower cased: TENANIMALSISLAMINANET
Reversed: TENANIMALSISLAMINANET
The last two are the same --> so this sentence is a palindrome.
You will need to set up the main processing of your program as a DO WHILE loop. After one word or sentence is entered and processed you will ask the user if he/she wants to enter another. If they answer “Yes” or “yes” then the loop should continue and capture more input from the console window. If the user answers anything else then program should end. Keepgoing should be declared as a bool variable.
do
{
// Processing for a word/sentence
} while (keepgoing != false)
Inside this main loop you should do the following:
1. Get user input from the console window
2. Compress the input, i.e., remove all punctuation characters and blanks and upper case each letter (this MUST be a separate loop inside of the main processing loop)
3. Reverse compressed string (this MUST be another separate loop inside the main processing loop)
4. Compare compressed string to reversed string… show appropriate message to the user
5. Ask if the user wants to provide another input word/sentence
* * * NOTES * * *
1. The step 2 and 3 above MUST be implemented as while loops (no built in functions to do your work are allowed here!!! --- for example to reverse a string)
2. When capturing word, sentence, choice of whether to continue or not, use getline(cin, yourinputvar);
3. The input sentences can have the following punctuation characters: ! , . ‘ ? ; “ ( ) - and space
BONUS Instructions
When the user decides not to keepgoing process the input file “prog4_input.txt” and translate all sentences found in the file producing an output file “prog4_report.txt”. There should be one message shown on screen “File processing done” when file is closed. Here are some sample palindromes that you will find in the file:
Milestones? Oh, 'twas I saw those, not Selim.
No, it's a bar of gold, a bad log for a bastion.
"Naomi, sex at noon taxes", I moan.
Snug & raw was I ere I saw war & guns.
Doc, note, I dissent. A fast never prevents a fatness. I diet on cod.
Live was I ere I saw evil.
Program Documentation & Style:
1. Declare all variables and constants that your program uses at the beginning of your program.
2. Your program should include two types of comments:
a. Header Comments at the top including lines with:
- Your name, course name, and class time
- Program assignment number, program file name and due date
- A sentence or two explaining the purpose of the program
- A description of the input data needed by the program when you run it
- A description of the processing (calculations) done by the program
- A description of the results (output) produced by the program
b. In-line comments: There should be an in-line comment for each main step in your program. In general, this means a comment with each group of C++ statements that handle the declarations, input, processing, and the output steps of your program
3. Use meaningful identifier names
4. Include clear prompts for the user about entering the data
5. Include clear descriptions of the results when you display them
DATA FILE CONTENTS: palindromes.txt
Jack and "Jill"
A man, a plan, a canal -- Panama
Never a foot too far, even.
Euston saw I was not Sue.
Live on evasions? No, I save no evil.
Red Roses run no risk, sir, on nurses order.
Salisbury moor, sir, is roomy. Rub Silas.
Marge, let's "went." I await news telegram.
A new order began, a more Roman age bred Rowena.
I, man, am regal; a German am I.
Tracy, no panic in a pony-cart.
Egad! Loretta has Adams as mad as a hatter. Old age!
Eve, mad Adam, Eve!
Resume so pacific a pose, muser.
Marge let a moody baby doom a telegram.
Tenet C is a basis, a basic tenet.
Nella's simple hymn: "I attain my help, Miss Allen."
Straw? No, too stupid a fad. I put soot on warts.
Sir, I demand, I am a maid named Iris.
Lay a wallaby baby ball away, Al.
Tessa's in Italy, Latin is asset.
Noel sees Leon.
No, it can assess an action.
Bob: "Did Anna peep?" Anna: "Did Bob?"
Sex at noon taxes.
Egad, a base life defiles a bad age.
"Stop!" nine myriad murmur. "Put up rum, rum, dairymen, in pots."
Delia, here we nine were hailed.
Not I, no hotel, cycle to Honiton.
Anne, I vote more cars race Rome-to-Vienna.
Mother Eve's noose we soon sever, eh, Tom?
"Sue," Tom smiles, "Selim smote us."
Telegram, Margelet!
Too hot to hoot.
Unglad, I tar a tidal gnu.
Eve damed Ede, mad Eve.
Snug Satraps eye Sparta's guns.
Nurse, save rare vases, run!
Draw, O Caesar, erase a coward.
No mists or frost, Simon.
Sail on, game vassal! Lacy callas save magnolias!
Trap a rat! Stare, piper, at Star apart.
Sue, dice, do, to decide us.
La, Mr. O'Neill, lie normal.
Top step -- Sara's pet spot.
Eel-fodder, stack-cats red do flee.
Reg, no lone car won, now race no longer.
Zeus was deified, saw Suez.
Evil is a name of a foeman, as I live.
No waste, grab a bar, get saw on.
"Degenerate Moslem, a cad!" Eva saved a camel so Meta reneged.
Was it felt? I had a hit left, I saw.
Won't I repaper? Repaper it now.
Too far, Edna, wander afoot.
Stella won no wallets.
"Do nine men interpret?" "Nine men," I nod.
Nurse, I spy gypsies, run!
Draw pupil's pup's lip upward.
Lewd did I live, and, Edna, evil I did dwel.
"Sirrah! Deliver deified desserts detartrated!" stressed deified, reviled Harris.
All erotic, I lose my lyme solicitor, Ella.
No, is Ivy's order a red rosy vision?
No word, no bond, row on.
On tub, Edward imitated a cadet; a timid raw debut, no?
Tense, I snap Sharon roses, or Norah's pansies net.
"Deliver desserts," demanded Nemesis, "emended, named, stressed, reviled."
No, it is opposed; Art sees Trade's opposition.
"Knight, I ask nary rank," saith gink.
Moors dine, nip -- in Enid's room.
"Ma," Jerome raps pot top, "spare more jam!"
Live not on evil deed, live not on evil.
Sir, I'm Iris!
Now do I repay a period won.
A rod, not a bar, a baton, Dora.
Now saw ye no mosses or foam, or aroma of roses. So money was won.
Amiced was I ere I saw Decima.
"Pooh," smiles Eva, "have Selim's hoop."
No, set a maple here, help a mate, son.
A war at Tarawa!
Some men interpret nine memos.
Delia sailed as sad Elias ailed.
Ned, I am a maiden.
Dennis sinned.
Remit Rome cargo to go to Grace Mortimer.
Did Dean aid Diana? Ed did.
I told Edna how to get a mate: "Go two-handed." Loti.
Sire, was I ere I saw Eris?
Now Eve, we're here, we've won.
"Suit no regrets." A motto, Master Gerontius.
Eve, man, am Eve!
Slap-dab set-up, Mistress Ann asserts, imputes bad pals.
Tuna nut.
Saladin enrobes a baroness, Senora, base-born Enid, alas.
Deny me not; atone, my Ned.
Roy Ames, I was a wise mayor.
Wonders in Italy, Latin is "Red" now.
'Tis Ivan on a visit.
Did Ione take Kate? No, I did.
Solo gigolos.
No, it is open on one position.
He Goddam Mad Dog, Eh?
Ned, go gag Ogden.
Draw no dray a yard onward.
"Revolt, love!" raved Eva. "Revolt, lover!"
Enid and Edna dine.
Anne, I stay a day at Sienna.
Senile felines.
Max, I stay away at six A.M.
Ere hypocrisies or poses are in, my hymn I erase. So prose I, sir, copy here.
St. Simon sees no mists.
Draw, O coward!
Top step's pup's pet spot.
Noel, did I not rub Burton? I did, Leon.
Puss, a legacy! Rat in a snug, unsanitary cage, lass, up!
Rise to vote, Sir.
Noel saw I was Leon.
Now, sir, a war is won!
Ha! Robed Selim smiles, Deborah!
Degas, are we not drawn onward, we freer few, drawn onward to new eras aged?
Now ere we nine were held idle here, we nine were won.
Yo! Bottoms up, U.S. Motto, boy!
Nor I nor Emma had level'd a hammer on iron.
Al lets Della call Ed, Stella.
No Dot nor Ottawa, "legal age" law at Toronto, Don.
Yes, Mark, cable to hotel, "Back Ramsey."
Was it a bar or a bat I saw?
Marge lets Norah see Sharon's telegram.
Analytic Paget saw an inn in a waste-gap city, Lana.
Was raw tap ale not a reviver at one lap at Warsaw?
Live on, Time; emit no evil.
"Not for Cecil?" asks Alice Crofton.
Ban campus motto, "Bottoms up, MacNab."
So may Apollo pay Amos.
Norma is as selfless as I am, Ron.
Arden saw I was Nedra.
Won't lovers revolt now?
Do not start at rats to nod.
Ha! On, on, o Noah!
Norah's foes order red rose of Sharon.
I made border bard's drowsy swords; drab, red-robed am I.
Emil, asleep, Hannah peels a lime.
Set a broom on no moor, Bates.
Ten dip a rapid net.
O render gnostic illicit song, red Nero.
Are we not drawn onwards, we Jews, drawn onward to new era?
Mother at song no star, eh Tom?
I maim nine men in Saginaw; wan, I gas nine men in Miami.
So may get Arts award. Draw a strategy, Amos.
Nella, demand a lad named Allen.
Yes, Syd, Owen saved Eva's new Odyssey.
"Now dine," said I as Enid won.
Lepers repel.
May a moody baby doom a yam?
Draw -- aye, no melody -- dole-money award.
Mirth, sir, a gayy asset? No, don't essayy a garish trim.
See few owe fees.
Stressed was I ere I saw desserts.
Name I -- Major-General Clare -- negro Jamie Man.
Tennis set won now Tess in net.
Ewer of miry rim for ewe.
Sh! Tom sees moths.
No misses ordered roses, Simon.
"Stop, Syrian, I start at rats in airy spots"
I, Marian, I too fall; a foot-in-air am I.
Evade me, Dave.
Delia's debonair dahlias, poor, drop, or droop. Sail, Hadrian; Obed sailed.
No ham came, sir, now siege is won. Rise, MacMahon.
Now Ned, I am a maiden nun; Ned, I am a maiden won.
Ten animals I slam in a net.
Did I draw Della too tall, Edward? I did?
Go hang a salami in a ladagna hog.
Di, did I as I said I did?
Milestones? Oh, 'twas I saw those, not Selim.
No, it's a bar of gold, a bad log for a bastion.
"Naomi, sex at noon taxes", I moan.
Snug & raw was I ere I saw war & guns.
Doc, note, I dissent. A fast never prevents a fatness. I diet on cod.
Live was I ere I saw evil.
Red now on level -- no wonder.
Stop! Murder us not tonsured rumpots!
Step on hose-pipes? Oh no, pets.
Stiff, o dairyman, in a myriad of fits.
To nets, ah, no, son, haste not.
Dennis, no misfit can act if Simon sinned.
Revered now I live on. O did I do no evil, I wonder ever?
Sore was I ere I saw Eros.
Noel, lets egg Estelle on.
In a regal age ran I.
"Novrad," sides reversed, is "Darvon."
Name now one man.
Dennis and Edna sinned.
Nora, alert, saws goldenrod-adorned logs, wastrel Aaron!
Sums are not set as a test on Erasmus.
Deliver, Eva, him I have reviled.
Damosel, a poem? A carol? Or a cameo pale? (So mad!)
Doom an evil deed, liven a mood.
God, a red nugget! A fat egg under a dog!
Nurse's onset abates, noses run.
Roy, am I mayor?
Ron, Eton mistress asserts I'm no tenor.
I tip away a wapiti.
Adelberta was I ere I saw a trebled "A".
Sit on a potato pan, Otis.
Moorgate got nine men in to get a groom.
Repel evil as a live leper.
Eva, can I stab bats in a cave?
Did Hannah say as Hannah did?
Goddesses so pay a possessed dog.
Eva, Lave!
Ah, Satan sees Natasha.
Do Good's deeds live on? No, Evil's deeds do, O God.
Madame, not one man is selfless; I name not one Madam.
Dora tended net, a rod.
Golf, No, sir, prefer prison flog.
Nella risks all: "I will ask Sir Allen."
Now do I report "Sea Moth" to Maestro, period? Won.
Selim's tired, no wonder, it's miles.
"So I darn on," a Canon radios.
War-distended nets I draw.
Stephen, my hat! Ah, what a hymn, eh, pets?
Mad Zeus, no live devil, lived evil on Suez dam.
Bog dirt up a sidetrack carted is a putrid gob.
Mad? Am I, madam?
Madam, in Eden I'm Adam!
Ward nurses run "draw."
Live dirt up a sidetrack carted is a putrid evil.
Oh who was it I saw, oh who?
"Reviled did I live," said I, "as evil I did deliver."
Live was I ere I saw Evil.
Pull up, Eva, we're here, wave, pull up.
Revolt on Yale, Democrats edit "Noon-Tide Star." Come, delay not lover.
Won race, so loth to lose car now.
No, it never propagates if I set a "gap" or prevention.
Delia sailed, Eva waved, Elias ailed.
I maim nine more hero-men in Miami.
Rise, morning is red, no wonder-sign in Rome, Sir.
Emil asleep, Allen yodelled "Oy." Nella peels a lime.
No. I save on final perusal, a sure plan if no evasion.
Yreka Bakery.
He lived as a devil, eh?
I saw thee, madame, eh? 'Twas I.
Dior Droid.
Regard a mere mad rager.
I saw desserts; I'd no lemons, alas no melon. Distressed was I.
A dog! A panic in a pagoda!
Yawn a more Roman way.
Semite, be sure! Dam a ma-made ruse betimes.
Pull up if I pull up.
Able was I ere I saw Elba.
Eve saw diamond, erred, no maid was Eve.
"Slang is not suet, is it?" Euston signals.
I roamed under it as a tired, nude Maori.
Pa's a sap.
No, miss, it is Simon.
Step on no pets!
Niagara, O roar again!
Lewd did I live; evil I did dwel.
Too bad, I hid a boot.
"Rats gnash teeth," sang Star.
Lapp, Mac? No, sir, prison-camp pal.
Tide-net safe, soon, Allin. A manilla noose fastened it.
I moan, Naomi.
Too far away, no mere clay or royal ceremony, a war afoot.
Rats live on no evil star.
Deer frisk, sir, freed.
I did roar again, Niagara! ... or did I?
No evil Shahs live on.
O gnats, tango!
Stop, Syrian, I start at rats in airy spots.
"Not New York," Roy went on.
"Norah's moods," Naomi moans, "doom Sharon."
Eva, can I pose as Aesop in a cave?
Trade ye no mere moneyed art.
Was it a rat I saw?
Help Max, Enid -- in example, "H."
So may Obadiah, even in Nineveh, aid a boy, Amos.
See, slave, I demonstrate yet arts no medieval sees.
Egad, a base tone denotes a bad age.
Lew, Otto has a hot towel.
"Warden in a Cap," Mac's pup scamp, a canine draw.
Paget saw an inn in a waste gap.
A slu nixes sex in Ulsa.
Must sell at tallest sum.
Naomi, did I moan?
Drab Red, no londer bard.
Revenge my baby, meg? Never!
Stop, Syrian, I see bees in airy spots.
Did I do, O God, did I as I said I'd do? Good, I did!
Pusillanimity obsesses Boy Tim in "All Is Up."
Refasten Gipsy's pig-net safer.
Pat and Edna tap.
Adam, I'm Ada!
Ma is as selfless as I am.
Poor Dan is in a droop.
Leon sees Noel.
So may Obadiah aid a boy, Amos.
Sis, Sargasso moss a grass is.
Now, Ned, I am a maiden won.
I moan, "Live on, O evil Naomi!"
Delia and Edna ailed.
So remain a mere man. I am Eros.
No lemons, no melon.
Never odd or even.
Rise, sir lapdog! Revolt, lover! God, pal, rise, sir!
Ah, Aristides opposed it, sir, aha!
Ma is a nun, as I am.
Madam, I'm Adam.
Star? Come, Donna Melba, I'm an amiable man -- no Democrats!
We'll let Dad tell Lew.
No, it is opposition.
No benison, no sin, Ebon.
Ladle histolytic city lots I held, Al.
Harass selfless Sarah!
Ten? No bass orchestra tarts, eh? Cross a bonnet!
Si, we'll let Dad tell Lewis.
In airy Sahara's level, Sarah, a Syrian, I.
Nor I, fool, ah no? We won halo -- of iron.
We seven, Eve, sew.
Peel's lager on red rum did murder no regal sleep.
"Go, droop aloof," sides reversed, is "fool a poor dog."
Sir, I soon saw Bob was no Osiris.
St. Eloi, venin saved a mad Eva's nine violets.
Here so long? No loser, eh?
Flee to me, remote elf.
Six at party, no pony-trap, taxis.
Drab as a fool, as aloof as a bard.
Red? Rum, eh? 'Twas I saw the murder.
Pull a bat! I held a ladle, hit a ball up.
No, Hal, I led Delilah on.
Nomists reign at Tangier, St. Simon.
Nemo, we revere women.
Harass sensuousness, Sarah.
Are we not, Rae, near to new era?
Red root put up to order.
"Sal is not in?" Ruth asks. "Ah, turn it on, Silas."
Retracting, I sign it, Carter.
A Toyota.
Gate-man sees name, garage-man sees name-tag.
Live not on evil.
Nella won't set a test now, Allen.
Ha! I rush to my lion oily moths, Uriah!
Live dirt, up a side-track carted, is a putrid evil.
Dog, as a devil deified, lived as a god.
Explanation / Answer
Screenshot
--------------------------------------------------------------------
Program
/*This program take sentence by sentence
display the entered sentence
compress the sentence and uppercased
display compressed and uppercase
Reverse the sentence and uppercased
display reversed uppercased
*/
//Header files for i/o , string handling and file handler
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
//Main method
int main()
{
/*File processing part*/
//Variables for file read , write and line by line
ifstream in;
ofstream out;
string line;
//Open files for read or write
in.open("C:/Users/deept/Desktop/palindromes.txt");
out.open("C:/Users/deept/Desktop/palindrome_report.txt");
//Check file can open for writing
if (!out) {
cout << "File not found" << endl;
exit(0);
}//If open then
else {
//Check input file can open or not
if (!in) {
cout << "File not found" << endl;
exit(0);
}
//If open
else {
//Read line by line and process
while (!in.eof()) {
string newtext = "";
string revtext = "";
getline(in, line);
//write read data
out << "InitialInput:" << line << endl;
//loop for avoiding all characters other than alphabet
for (int i = 0; i < line.length(); i++) {
if (isalpha(line[i])) {
string str(1, line[i]);
newtext.append(str);
}
}
//write compressed data
out << "Compressed:" << newtext << endl;
//Loop for uppercasing
for (int i = 0; i<newtext.length(); i++)
{
if (newtext[i] >= 97 && newtext[i] <= 122)
{
newtext[i] = newtext[i] - 32;
}
}
//write uppercased
out << "UpperCased:" << newtext << endl;
//Loop for reversing
for (int i = newtext.length() - 1; i >= 0; i--) {
string str(1, newtext[i]);
revtext.append(str);
}
//Loop for upper casing
for (int i = 0; i<revtext.length(); i++)
{
if (revtext[i] >= 97 && revtext[i] <= 122)
{
revtext[i] = revtext[i] - 32;
}
}
//write uppercase reverse sentence
out << "Reversed:" << revtext << endl;
//check the sentence is palindrome or not
if (newtext == revtext) {
out << "palindrome" << endl;
}
else {
out << "Not palindrome" << endl;
}
}
}
//End of processing display cfile processing completed
cout << "File processing is completed" << endl;
//close files
in.close();
out.close();
}
/*User entering part*/
//Loop checking string for user prompt repeatation
string keepgoing = "yes";
//loop until user enter 'no'
do
{
//variables for string read , compressed string and reverse string
string text;
string newtext = "";
string revtext = "";
cin.ignore();
//user prompt for palindrome check sentence
cout << "Enter text:";
getline(cin, text);
//Display enterd data
cout << "InitialInput:" << text << endl;
//loop for avoiding all characters other than alphabet
for (int i = 0; i < text.length(); i++) {
if (isalpha(text[i])) {
string str(1, text[i]);
newtext.append(str);
}
}
//Display compressed data
cout << "Compressed:" << newtext << endl;
//Loop for uppercasing
for (int i = 0; i<newtext.length(); i++)
{
if (newtext[i] >= 97 && newtext[i] <= 122)
{
newtext[i] = newtext[i] - 32;
}
}
//Display uppercased
cout << "UpperCased:" << newtext << endl;
//Loop for reversing
for (int i = newtext.length() - 1; i >= 0; i--) {
string str(1, newtext[i]);
revtext.append(str);
}
//Loop for upper casing
for (int i = 0; i<revtext.length(); i++)
{
if (revtext[i] >= 97 && revtext[i] <= 122)
{
revtext[i] = revtext[i] - 32;
}
}
//Displayuppercase reverse sentence
cout << "Reversed:"<<revtext << endl;
//check the sentence is palindrome or not
if (newtext == revtext) {
cout << "palindrome" << endl;
}
else {
cout << "not palindrome" << endl;
}
//Prompt user choice to continue or not
cout << "Do you want to continue/not(yes/no):";
cin >> keepgoing;
} while (keepgoing != "no");
return 0;
}
---------------------------------
Output
File processing is completed
Enter text:Ten Animals I slam in a net.
InitialInput:Ten Animals I slam in a net.
Compressed:TenAnimalsIslaminanet
UpperCased:TENANIMALSISLAMINANET
Reversed:TENANIMALSISLAMINANET
palindrome
Do you want to continue/not(yes/no):yes
Enter text:hello world
InitialInput:hello world
Compressed:helloworld
UpperCased:HELLOWORLD
Reversed:DLROWOLLEH
not palindrome
Do you want to continue/not(yes/no):no
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.