Question
Simple Decoder In c++, this assignment you are to write a function called decode that will decode a nine character string into three separate int
Simple Decoder
In c++, this assignment you are to write a function called decode that will decode a nine character string into three separate int value codes.
The input to your function should be a string that contains nine characters. You are to break the nine characters into three separate codes by summing each set of three characters. For example, given the following string:
"ABCDEFGHI"
You are to sum:
"ABC"
"DEF"
"GHI"
The first set of characters will yield a sum of 198 This is because on the ASCII chart
'A' = 65
'B' = 66
'C' = 67
for a total of 198
Your function should return back to main the decoded values through the use of reference parameters. This function should also check to make sure the code is valid. This means that the function must make sure the length of the string is exactly nine characters long. If not the function should simply return false and report from main that the sequence was invalid. Otherwise the function should compute the codes, store them each of the reference parameters and return true. Each individual code should be printed from main.
Some things to consider for your grade:
Your function should have four total parameters. A string, and three int variables by reference
Your functions should return a bool (true or false) 0 and 1 are not bool values
Use the at function that is part of a string to get each individual character.
Use the length function that is part of the string when referring to the length of the input string.
You need to cast the character to an int to get its value
You need to print out the three codes in main.
The decode function must return true or false to indicate the success of the function.
You are only allowed to use one for loop to sum the characters
What not to do
Using any of the following will drop your grade for this assignment by 70%
global variables
cin in the decode function
cout in the decode function
goto statements
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started