Class assignment is so frustrating. Cannot figure out

Overview

For this assignment, write a program to decode an encoded text message and count the different types of characters.
Processing

The encoded text message will be processed one character at a time. Each character will be decoded by calling an appropriate function and then displayed. Counters for specific types of characters will also be maintained.

The basic layout for your program is as follows:

ifstream inFile;

inFile.open( "encoded_beer.txt" )
if( inFile.fail() )
{
cout << "Input file failed to open";
exit(-1);
}

inFile >> ch;

while ( inFile )
{
//Process the 1 character by decoding it. A cascading if statement should
//be used to test the "type" of character (alphabetic, digit, punctuation,
//etc...) and call the appropriate decoding function and increment the
//appropriate counter

//Display the decoded character

inFile >> ch;
}

inFile.close();

This code will open an input file called "encoded_beer.txt" and then read it one character at a time. It has already been placed in a CPP file that you can download and use to start your program:

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/assign6.cpp

As mentioned earlier, besides the encoding, the program will also count specific types of characters AFTER they have been encoded. Keep track of:

* the total number of characters in the file
* the number of alphabetic characters
* the number of uppercase alphabetic characters
* the number of lowercase alphabetic characters
* the number of digits
* the number of punctuation marks
* the number of "special characters" (ie. those that aren't alphabetic, a digit, or punctuation)
* the number of newline characters
* the number of spaces

These values should be displayed after the encoded text.
Input

For this assignment, the encoded text message is contained in a file that can be downloaded and saved on your computer. It is called encoded_beer.txt and can be found here:

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/encoded_beer.txt

It should be saved in the same location as your CPP file.
The Encoding Process

The program that encoded the original text message used the following rules. Your program will simply undo what it did. The original message that was encoded that will be referred to as "msg" below:

1.

Any character in msg that was an uppercase character was converted to lowercase and then had 1 subtracted from it. So 'B' became 'a', 'C' became 'b', ... The first uppercase letter 'A' was wrapped around to the end of the alphabet so that it became 'z'.
2.

Any character in msg that was a lowercase character was converted to uppercase and then had 1 added to it. So 'a' became 'B', 'b' became 'C', ... The last lowercase letter 'z' was wrapped around to the beginning of the alphabet so that it became 'A'.
3.

Any character in msg that was a digit ('0' ... '9') was converted as follows:

0 --> #
1 --> /
2 --> +
3 --> *
4 --> -
5 --> ;
6 --> ^
7 --> @
8 --> $
9 --> !

4.

Certain punctuation was encoded as shown below. Any punctuation that is not shown here was not altered at all.

, --> 9
" --> 8
$ --> 7
: --> 6
? --> 5
' (single quote) --> 4
( --> 3
) --> 2
. --> 1
- --> 0

5.

Two white space characters were encoded as non-standard characters:

a blank/space was encoded as an ASCII 22
a newline character was encoded as an ASCII 20

Note again: any character that does not fit the criteria listed above in 1 - 5 was not altered in the encoding.
The Functions

The decoding will be done by calling the appropriate function. The following set of functions are standard library functions that you can simply call in your program (ie. you do no have to write the code them): isalpha, isupper(), islower(), ispunct(), isdigit().

Each of the functions listed above take a character as an argument and returns a true or false value:

*

isalpha() will return true if the passed in character is an alphabetic character; and false if the passed in character is not an alphabetic character
*

isupper() will return true if the passed in character is an uppercase character; and false if the passed in character is not an uppercase character
*

islower() will return true if the passed in character is a lowercase character; and false if the passed in character is not a lowercase character
*

ispunct() will return true if the passed in character is a punctuation character; and false if the passed in character is not a punctuation character
*

isdigit() will return true if the passed in character is a digit; and false if the passed in character is not a digit

The return value allows for the functions to be called as the condition in an if statement:

if( isdigit(ch) )
{
call appropriate decoding function
}

The functions listed below will be used to decode a character (these are the functions you will have to write and call in your program).


char convUpper( char ch )

This function will be called for any character that is an uppercase character. It takes a single character as its argument: the character to be decoded. It returns the decoded character. The function should reverse the process that was detailed in #2 of the Encoding Process above by converting the passed in character to lowercase and subtracting 1, so that, for example, 'C' becomes 'b'. However, there is a special case: 'A' should become 'z'.


char convLower( char ch )

This function will be called for any character that is a lowercase character. It takes a single character as its argument: the character to be decoded. It returns the decoded character. The function should reverse the process that was detailed in #1 of the Encoding Process above by converting the passed in character to uppercase and adding 1, so that, for example, 'd' becomes 'E'. However, there is a special case: 'z' should become 'A'.
char convPunct( char ch )

This function will be called for any character that is a punctuation symbol (in C++, that is all type-able characters that are not letters, digits, or whitespace). It takes a single character as its argument: the character to possibly be decoded. It returns the decoded character. The function should use a switch statement to check for each of the punctuation symbols that were listed under #3 of the Encoding Process above and convert the passed in character to its decoded version, so that, for example, ';' becomes '5'. Don't forget that if the punctuation symbol is not listed above, it should be returned unchanged.


char convDigit( char ch )

This function will be called for any character that is a digit. It takes a single character as its argument: the character to be decoded. It returns the decoded character. The function should use a switch statement to check for each of the digits that were listed under #4 of the Encoding Process above and convert the passed in character to its decoded version, so that, for example, '6' becomes '&'. Since all of the digits were encoded, there will be no case of an argument value not being altered.


char convSpecial( char ch )

This function will be called for any character that is not an uppercase, lowercase, punctuation, or digit character. It takes a single character as its argument: the character to possibly be decoded. It returns the decoded character. The function will only change the passed in character if it has ASCII value 20 or 22. If the passed in character has ASCII value 20, then it will return a newline character. If the passed in character has an ASCII value of 22, then it will return a space. Anything else will be returned unchanged.
Requirements


If someone can help me with this it would be greatly appreciate. I would keep reading and reading but I cannot find out how to write this program out. If someone could help me step by step that would help me learn greatly what to do
Last edited on
What's up buddy.

Assignment is due in 2 hours ;]

I'll help you out with the while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
while( inFile )
{
total_count++;
if (isalpha(ch))
{
alpha_count++;
if (isupper(ch))
{
convUpper( ch );
lower_count++;
}
else if (islower(ch))
{
convLower( ch );
upper_count++;
}
}	   	   
else if (ispunct(ch))
{
convPunct( ch );
digit_count++;
}
else if (isdigit(ch))
{
convDigit( ch );
punct_count++;
}
else if (ch == 20 || ch == 22)
{
convSpecial( ch );
special_count++;
if (ch == 20)
newline_count++;
else if (ch == 22)
space_count++;
}
	
inFile >> ch;
  
   
   
  
  }


The functions are the whole assignment so I can't give that to you. So this should hopefully give you a start...


Good luck!
and you dont have private messaging set up... or else i would email you.

send me a pm [private message] if you have questions.
damn thanks man... See I had something like that but I didn't know how to implement it right. Thanks man and yea if I have question I'll send you a pm. Thanks
it really helped me to use a test.txt and try certain letters and numbers and what not. like she said ABC -> zab

and just incase it messes you up... I might have flipped digit count and punct count. the wording of the conversion on blackboard confused the shit out of me.


so yeah... if your count is wrong at the end try switching those ;]
Alright I will try that out and see what happens... I sent you a pm about the first function
Topic archived. No new replies allowed.