Project #41690 - C++

Q1)

 

Time to practice with functions and STL!

Write a program that asks the user for string and display an all-uppercase version of that same string to the screen. The function should take a string parameter with the users input and return the same string in all-uppercase. You must write a function to do this!

The main function should get the user's input, call the function and display the resulting stirng to the screen.

Hint: There is an STL library function that can uppercase a string in one line!


Example output:

Please enter a string to shout:

i really love programming!

I REALLY LOVE PROGRAMMING!

 

-------------------------------------------------------------------------------------

Q2)

 

More functions and STL....


Write a program that asks the user for a string and display that same string in reverse order on the screen. The function should take a string parameter with the users input and return the same string, except each character is in reverse order. You must write a function to do this!


The main function should get the user's input, call the function and display the resulting stirng to the screen.


Hint: There is an STL library function that can reverse a string in one line!


Example output:


Please enter a string to reverse:


backwards sentence


ecnetnes sdrawkcab

 

---------------------------------------------------------------------------------

Q3)

 

 

Description

 

Cylon says what?!?!?! Part 1

Admiral Adama needs to decrypt a series of messages from his various lookout pilots. He’s hoping that one of them will let him know the position of the Cylon fleet. Because of his standing order, computers cannot be networked together, so to decrypt the message it will have to be run through 3 separate programs run on 3 different computers. 

Adama feeds the encrypted file into the first computer, and it immediately spits out a new file.  Looking at it he can see that it’s starting to decrypt the file.

He then feeds this new file into the second computer, and it immediately spits out a second new file. Looking at this file he can see that the file is almost readable, but still needs to go through the next stage.

Finally, Adama  feeds the file to the last computer.  It immediately spits out the final decrypted file and sees that one of his pilots has indeed found the Cylon fleet. 

Decryption

For this project you will be writing 3 programs. Each program will contain a main and 1 function that will do the decrypting. 

Decryption stage 1:

Attached to this project is the initial file to decrypt. It is named one_message.txt. You will read the sentence into a string.

You will send the string to a function you write named “reverse_sentence”:

string reverse_sentence(string s);

This function will reverse the string, and then return the reversed string. Do not make a new string, save it back into the original string.

You must use one of the STL algorithms to reverse the string.

Write the string to a new file called “stage2.txt”.

Decryption stage 2:

The structure of this program is similar to stage 1; you will open the file “stage2.txt” and read the sentence into a string.

You will send the string to a function you write named “normalize_sentence”:

string normalize_sentence(string s);

This function will down case all letters of the string (that is, make all letters lower-case), and then up case only the first character of the string.  It will then return the modified string.

You must use one of the STL algorithms.

Write out the normalized string to a new file called “stage3.txt”. 

Decryption stage 3:

The structure of this program is similar to stage 2; you will open the file “stage3.txt” and read the sentence into a string.

You will send the string to a function called “replace_sentence”:

string replace_sentence(string s);

This function will replace certain words in the string with other words.  You will then return the modified string.

You must use string functions.

USE IF-STATEMENTS TO DO THE SUBSTITUTIONS. DO NOT USE A SWITCH-STATEMENT IN THIS FUNCTION!!!

Here are the words that need to be replaced. Both words may appear once in the string.

  1. Replace “barn” with “Galactica
  2. Replace “toaster” with “Cylon

You must replace the entire string if you find these phrases

After you finish write out the string to a new file named “decrypted.txt”. 


Additional Things!!

  • You must close the files you are reading from and writing to before the end of each program.
  • You can use cin/cout for testing, but remove or comment out the lines before turning in the program.

IMPORTANT HINTS!!!!

For stages 1 and 2, the functions required can be found in the algorithms section of the standard template library. You can see the library on http://www.cplusplus.com under the reference section. 

Experiment. Write small test programs to test out functions before you build the full programs.

Note again that one_message.txt is attached.


Objectives:

  • practice declaring C++ variables with appropriate names and data types
  • practice console I/O
  • practice using boolean expressions in flow-of-control statements
  • learn and practice the strategy of incremental development

Requirements:

  • your program source code must include your name and the project name in comments [5 points]
  • your programs must compile and run without errors [15 points]
  • your programs must successfully read from and write to text files [5]
  •     reverse_sentence function implemented correctly [25] 
  •      normalize_sentence function implemented correctly [25] 
  •       replace_sentence function implemented correctly [25] 

Subject Computer
Due By (Pacific Time) 10/01/2014 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy