I'm not sure how to get started with this. Here's the assignment and what i've done so far, but I'm not sure if i'm going the right direction with this. The assignment says to have the user enter input one character at a time. That means one letter or space or punctuation mark, then have them hit enter, then another character, they hit enter, and so on.. right?
Programming Assignment Specifications:
You have been sending email to your friends – and you have decided to be clever and insert a second message inside your first (two for the price of one)! However, you are afraid that your friends won’t be able to read the hidden second message, so you have decided to use your new skills at C++ programming to write a program to decode the message that you type in – so that your friends can clearly read it (or so you hope!).
Allow the user to enter in a paragraph – character by character. Write a program to read the paragraph, character by character, and display the second message using the following rules:
- The first letter of each word comprises the hidden message
- However, if the second letter of a word is the SAME as the first letter, then the first letter is NOT used – and the 3rd (if it exists) is used.
- If there are only two letters in the word – and they are the same – then it means that the new message should have a period. If the duplicate characters are actually punctuation (.,;!?), then use that same punctuation for your hidden message.
- If there are two (or more) spaces in a row – between words – then there should be a space between words in the hidden message.
Every word following a period in your new message should be capitalized
Things you should know...as part of your program:
- Experiment with writing your own function. Don’t use global variables.
- Allow the user to enter in another paragraph after decoding the message, or quitting.
- You SHOULD NOT echo the original message. You will not like the results.
- MAKE SURE to read one character at a time. This programming assignment is not designed to be used with strings or arrays (we haven’t learned them yet). Therefore, they MAY NOT be used in this assignment!
Here's what I started doing:
char ch1; //Space entered by user
char ch2; //First letter or space entered by user
char ch3; //Second letter entered by user
char ch4; //Third letter entered by user
char x; //Character used in hidden message
#include <iostream.h>
void decode();
int main()
{
cout <<"Please enter each word of the message, and hit the enter "
<<endl;
cout <<"key after each word entered, Include punctuation "
<<endl;
cout <<"marks and spaces between words. Type in the "
<<endl;
cout <<"spaces at the beginning of the word: ";
cin.get(ch1);
cin.get(ch2);
cin.get(ch3);
cin.get(ch4);
decode ();
return 0;
}
void decode()
{
if (ch1 == '#')
x = '#';
else if (ch2 != ch3)
x = ch2;
else if (ch1 == ' ' && ch2 == ' ')
x = ' ';
else if (ch2 == ch3)
x = ch4;
else
x = '.';
}
Any help is much appreciated, thanks