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
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...
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...
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...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the following CFG: 1. exps --> exp | exp NEWLINE exps 2. exp --> term {addop term} 3. addop --> + | - 4. term --> factor {mulop factor} 5. mulop --> * | / 6. factor --> ( exp ) | INT The 1st production defines exps as an individual expression, or a sequence expressions separated by NEWLINE token. The 2nd production describes an...
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...
Using C# and Windows Forms (WinForms), design and implement a standalone desktop application that fulfils the...
Using C# and Windows Forms (WinForms), design and implement a standalone desktop application that fulfils the following requirements: 1. The user shall be able to enter the following values: a. Gross monthly income (before deductions). b. Estimated monthly tax deducted. c. Estimated monthly expenditures in each of the following categories: i. Groceries ii. Water and lights iii. Travel costs (including petrol) iv. Cell phoneand& telephone v. Other expenses 2. The user shall be able to choose between renting accommodation or...
#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 <<...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...