Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ help programming assignment The goal is a program that can decode a sentence that has been encoded using a rectangle of unknown width. using

C++ help programming assignment

The goal is a program that can decode a sentence that has been encoded using a rectangle of unknown width.

using two classes described

the .cpp file reads in from a large text file to count the number of digraphs and then arranges the messed up entered sentence based on the data count of digraphs to form a logical sentence.

image text in transcribed

image text in transcribed

image text in transcribed

WAYNE'S ANNOYING RECTANGULAR TRANSPOSITION. Wayne likes to send messages by first writing them in a rectangle row-wise, and then reading them off column-wise. Example: When Orange rules" is encoded in a rectangle of width 4, oran ger ules one gets "Ogurela enrs". The goal is a program that can decode a sentence that has been encoded using a rectangle of unknown width. 1) Initial version of class Wart You should start with a Wart class (stored in .cpp and .h of the same name). The class stores a phrase in a string member variable. It should initially have at least the following: a constructor that takes a string a void encode (int) function that takes the width and changes the stored string. Note that if the length of the string is not a multiple of width, then the string should be padded with periods so that the length becomes a multiple of width. For example, when "Orange rules is encoded in a rectangle of width 5, the result is "Oeer sar.nu.gl.. an overloaded stream insertion operator for output a destructor if needed 2) Class Digraph The decoding will choose the version that is "closest" to English. In order to do the decoding, we need the relative proportions of digraphs in English. A digraph is an ordered pair of consecutive letters within the same word. Create a class Digraph (stored in files of the same name) that stores these proportions. The class should be case-insensitive, and should scale the proportions so that they sum to 1. The Digraph class should have at least the following: a no-argument constructor that sets the proportions to 0.1 for each of th he in eran rend at on nt and 0.0 for every other digraph. a constructor that takes the name of a text file, and uses that file to determine the proportions. The constructor should print out the digraph with highest proportion. a function double getScore(char, char) that takes two chars and returns the proportion associated with that digraph. (Case-insensitive) a function double getScorel & string ) that takes a string and returns the sum of the proportions associated with each consecutive pair of characters. (If either character is not a letter then its score is zero.) a destructor if needed 3) Doing the decoding Implement a primitive decoding method. For this, you need to add one public function to your Wart class (but you might choose to also add a private function or two). A void function decode(&Digraph): Say the current string has length m. Then try all possible widths from 1 up to m inclusive, but only those that are divisors of m. For each possible width, determine the score the Digraph gives. After considering all possibilities, change the stored string to the decoding that gives the highest score. (Ties can be broken arbitrarily.) 4) Driver file Create a driver file Runner.cpp that: reads a file name from user and creates a Digraph using that file; reads the encoded sentence from the user (not the command line) and creates a Wart; . then invokes the decode function and prints out the resultant Wart. Here is a sample run: Make sure that your output is similar. Enter file name for digraph: kafka.txt Most common was: he with a proportion of 3591/83508 = 0.0430019 Enter sentence terminated by Ogurela enrs This gets a score of: 0.0508215 The decoded sentence is: Orange rules #include using namespace std; #include "Wart.h" int main() Wart w("Cogito ergo sum"); w.encode( 3 ); cout Ogurela enrs This gets a score of: 0.0508215 The decoded sentence is: Orange rules #include using namespace std; #include "Wart.h" int main() Wart w("Cogito ergo sum"); w.encode( 3 ); cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Did you check photos for quality and rights clearance?

Answered: 1 week ago

Question

Did you check the facts, their accuracy, and sources?

Answered: 1 week ago