Question

MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...

MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:

MUST WRITE IN C++

Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms.

Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A private member variable of the string type to hold the encrypted message. A constructor that receives the file name as a parameter and reads the text into the object. A pure virtual function decode that will be implemented in the derived classes. A function that prints the message on the screen.

Define two derived classes: CypherA and CypherB. Each one should implement its own version of decode according to the following algorithms:

CypherA should use the following key to decode the message: input character: abcdefghijklmnopqrstuvwxyz decoded character: iztohndbeqrkglmacsvwfuypjx Each 'a' in the input text should be replaced with an 'i', each 'b' with a 'z' and so forth.

CypherB should implement the "rotational cypher" algorithm. In this encryption method, a key is added to each letter of the original text. In order to decode you need to subtract 4. For example:

Cleartext: A P P L E Key: 4 4 4 4 4 Ciphertext: E T T P I

Main Program here
#include
#include
#include

#include "CypherA.h"
#include "CypherB.h"

using namespace std;

int main(int argc, const char * argv[]) {

string filename;

cout << "Enter file name to be decoded with algorithm A: ";
cin >> filename;

class CypherA messageA (filename);

messageA.decode();
cout << "Decoded message: \n";
messageA.print();
cout << endl << endl;

cout << "Enter file name to be decoded with algorithm B: ";
cin >> filename;

class CypherB messageB (filename);
messageB.decode();
cout << "Decoded message: \n";
messageB.print();
cout << endl;

return 0;
}

Homework Answers

Answer #1

// PLEASE LIKE THE SOLUTION

// FEEL FREE TO DISCUSS IN COMMENT SECTION

#include "bits/stdc++.h"
using namespace std;

class BaseClass{
   string cipher;
   public:
   // constructor
   BaseClass(string filename){
       // open file
       ifstream f(filename);

       // now read and store in cipher
       f>>cipher;
       f.close();
   }

   string getCipher(){
       return cipher;
   }

   // virtual function
   virtual void decode() = 0;
};

// CypherA
class CypherA: public BaseClass{
   public:
   string message;
   // constructor
   CypherA(string filename):BaseClass(filename){
       message ="";
   }

   void decode(){
       string key = "iztohndbeqrkglmacsvwfuypjx";

       // now decode by substracting 4
       message ="";
       string c = getCipher();
       for(int i=0;i<c.length();i++){
           message += key[(c[i]-'a')];
       }
   }

   void print(){
       cout<<message;
   }
};

// CypherB
class CypherB: public BaseClass{
   public:
   string message;
   // constructor
   CypherB(string filename):BaseClass(filename){
       message = "";
   }

   void decode(){
       // now decode by substracting 4
       message ="";
       string c = getCipher();
       for(int i=0;i<c.length();i++){
           message += (c[i]-4);
       }
   }

   void print(){
       cout<<message;
   }
};


int main(int argc, const char * argv[]){
   string filename;
   cout << "Enter file name to be decoded with algorithm A: ";
   cin >> filename;

   CypherA messageA (filename);

   messageA.decode();
   cout << "Decoded message: \n";
   messageA.print();
   cout << endl << endl;

   cout << "Enter file name to be decoded with algorithm B: ";
   cin >> filename;

   CypherB messageB (filename);
   messageB.decode();
   cout << "Decoded message: \n";
   messageB.print();
   cout << endl;

   return 0;
}

// SAMPLE OUTPUT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
IN C++ - most of this is done it's just missing the bolded part... Write a...
IN C++ - most of this is done it's just missing the bolded part... Write a program that creates a class hierarchy for simple geometry. Start with a Point class to hold x and y values of a point. Overload the << operator to print point values, and the + and – operators to add and subtract point coordinates (Hint: keep x and y separate in the calculation). Create a pure abstract base class Shape, which will form the basis...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT