QuestionQuestion

You are to implement two containers:
1. A Codeword container for storing ordered lists of symbols making up a codeword.
2. A Code container containing a collection of codewords.

The symbols are themselves allowed to be of any type that supports certain functionality. We shall consider the containers after considering the two symbol classes you need to implement.

The symbol classes
1. The first symbol class Mint allows us to store a single integer value in the range 0 to p   1, where    p is a positive integer. In this class you should overload the addition and subtraction operators overloaded to produce the typical integer result modulo p.
2. The second symbol class Melt allows us to store a single lowercase letter from the English alphabet, with the subtraction operator overloaded to give 1 if the symbols are different and 0 if they are the same. There are p = 26 distinct possible symbols.

Both should have the insertion and extraction operators overloaded. See later for a description of the main() function. Both should also have a special ”zero” symbol, for Mint this will be the integer 0, while for Melt it will be a letter ’a’.

The codeword container
This container should be used to store m elements of the same type. It should be a templated container class. This container should have the extraction operator overloaded. The following methods should also be provided.

1. The method Weight() should determine the number of elements in the code that are not–equal to    the ”zero” symbol. For example, 0 2 0 3 3 3 0 has a weight of 4.
2. The method Distance() should take another codeword and determine the sum of the element by element difference according to the overloaded subtraction operation for the contained symbol class. For example, the distance between 0 0 2 0 0 2 and 0 1 2 3 0 1 would be determined as 0 + 1 + 0 + 3 + 0 + 1 = 5.
3. The method Display() should output the elements in the codeword, each separated by a space, with a final gap and the weight of the codeword displayed. For example,

4 6 9 11 3 Weight: 5

This container should contain a zero codeword, with the m elements being all ”zero”, in accordance with the zero element for the contained symbol class.

The code container
This container should be used to store collections of n codewords. It should be a templated container class. This container should have the extraction operator overloaded. The following methods should also be provided.
1. The method minimumWeight() should determine the minimum Weight() value across all non–zero codewords.
2. The method calcDistance() should determine the distances between every pair of codewords in the code, and store these values.
3. The method minimumDistance() should determine the minimum Distance() between two code- words in the code, as determined across all distinct pairs of codewords.
4. The method Display() should display all the codewords contained in the container, using the Display() method for the codewords themselves, and display the minimum weight and minimum distance for this code. The table of distances between codewords should be displayed also.

The Main() function
You should request from the user the class type (0 for Mint, 1 for Melt), the number of distinct symbols in the class (p), the number of symbols in each codeword (m) and the number of codewords in the code (n). The codewords should then be read one by one.
After being read the minimum weights and distances should be calculated for the code. The code should be displayed using the code method Display().
You need to specify the compilation instruction for your program to compile on Banshee to a program with the name Code. Your program will only be tested on Banshee.
Assuming your code is compiled to the executable Code , it should be able to run as follows:
Code < Code.txt > Output.txt
where Code.txt contains information in accordance with the instructions provided above. Two examples of code files, Code1.txt and Code2.txt, one of each type, have been provided along with corresponding output Code1-Out.txt and Code2-Out.txt. The output files contain some notes as well and don’t have the input request information included.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#ifndef CODEWORD_H
#define CODEWORD_H

#include <iostream>
using namespace std;

template <class T>
class Codeword {
public:

    /**
    * constructor
    */
    Codeword() {
       arr = 0;
       m = 0;
    };

    /**
    * copy constructor
    * @param o
    */
    Codeword(const Codeword& o) {
       m = o.m;
       arr = new T[m];
       for (int i = 0; i < m; i++) {
            arr[i] = o.arr[i];
       }
    };

    /**
    * destructor
    */
    virtual ~Codeword() {
       if (arr != 0) {
            delete [] arr;
       }
    };

    /**
    * set up array of word
    * @param m size of the array
    */
    void setCodeword(int m) {
       arr = new T[m];
       this->m = m;
    }

    /**
    * extractor
    * @return
    */
    friend istream& operator>>(istream& is, Codeword& c) {
       for (int i = 0; i < c.m; i++) {
            is >> c.arr[i];
       }
       return is;
    };

    /**
    *
    * @return weight of the code word
    */
    int Weight() {
       T zero;
       int counter = 0;
       for (int i = 0; i < m; i++) {
            if (zero != arr[i]) {
                counter++;
            }
       }
       return counter;
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$63.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats