Write c++ code. Include header files for defining classes: //Excecption.h #inclu
ID: 3751838 • Letter: W
Question
Write c++ code. Include header files for defining classes:
//Excecption.h
#include <iostream>
using namespace std;
class Exception
{
//data member
protected:
string error;
public:
//constructor
Exception(const string& message)
{
error=message; //set the message
}
//function getError
string getError()
{
return error; //returns error message
}
};
//Cipher.h
#include <iostream>
using namespace std;
class Cipher
{
//abstract or pure virtual functions below
public:
virtual string encode(const string&)=0;
virtual string decode(const string&)=0;
};
//main.cpp
#include <iostream>
#include <string>
#include "OneTimePad.h"
using namespace std;
/*
The following main tests the functionality of various ciphers.
Use at your own discretion, and feel free to extend and/or modify in any way.
This file will be overwritten by the automarker if submitted.
*/
void testCipher(Cipher& cipher, const string& text) {
try {
string encoded = cipher.encode(text);
cout << encoded << endl;
cout << cipher.decode(encoded) << endl << endl;
} catch(Exception e) {
cout << e.getError() << endl << endl;
}
}
int main() {
string shortText="Top Secret";
string longText="According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience, and Hubris. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.";
OneTimePad pad(1);
testCipher(pad, shortText);
testCipher(pad, longText);
try {
pad.setSeed(-1);
} catch(Exception e) {
cout << e.getError() << endl << endl;
}
try {
pad.setSeed(2);
} catch(Exception e) {
cout << e.getError() << endl << endl;
}
testCipher(pad, shortText);
testCipher(pad, longText);
try {
pad.setSeed(9999);
} catch(Exception e) {
cout << e.getError() << endl << endl;
}
testCipher(pad, shortText);
testCipher(pad, longText);
OUTPUT
KtS8ePtFRa
Top Secret
8hF(%OzBTl "M94(*_3|TbO#5FXwdF/_C#7ipYVeUg,!'yD=~Xb{REf#Kn::<U#}%m@"v3'aGVbNj$>$l;}j5zGF7os^]K6vwMEoH:W{3 o7<Q8YyuhY 4T(Ou2M(bPm_k1-8>ub7`1ldZcvey1%?V&:Nk?,4:f)va_KNms5YLu_<LW^k8y!IZ%:(P08_1$2%vTCZfcE=yS/wzoY(NaI-hC:A={ohNRh6e{CFdAH;OqMW}{)amgyD]Ney9K#lh3ceY?NH|4p{%Hk7+UBqNLN|"A#<=SNRgWO@r@G3^:%0RScZ{9zaAyc8y({>f:E$q+w)o*MX4|;eo7l.&UyBF(?YCGIf]g/[=/<GwzKLAq<^YSyV;wO}NmI;M*"QDI^zx|1#_%e#(2x#z3)1NaM?yDkb'v!U~wJ-FfPR5/=H2^d%",'<znlk9c_sC*>V].2zVw<s^1]f+xAbLAv@F t2wc3)D`Kk9-$wFb/I2.Yj/.]Wy?D]G1=i:V$dWbeNq1Rn3}6f1$u`IKOl)Nly78x[E/X4%qCg=o^wu3x`Ye_U|Z=j%`0LY.kj@/.$M) aVYV#XyNK0.>Ci43z(xx(q]IR*~=_pZvOqd&d7{VS2{K^qJj;aw/Z$kePT!MqC[X|{+tB-xxl,uzKciwQoM=UZ;uE]&Q{uSJ8}Mo`Qi)Gt#Iz w%|`U|2ZG6q&.YyvjEm.FcMC09i
According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience, and Hubris. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.
Negative number provided
i,bJ.MdxB)
Top Secret
V U:MLjtD4.l"7:#2,RM=y#:&Ai3q*Op=9?->j2$/l5.ml2->!h@/9@P:Y>{j{.`_!-+=ZLEt&Ra-bB rD=M2tYK6't+:=E.|be;'de&-}rRxXP=*N0fjmMr@nIy.)4]"oK-gfe,Cnvo^X0!;j2S&hbuCWz{o.3FkBg7B,g[zxe3htgOZ$13EFCI$uh5{XRggm1KT7.6=>_L6V;L(f[9PP)$Skd&jQ|jFbL-wlGaOE?/6&^QNl> Ja1GcBbsGv^)s^+qk#5|^dB7/>'jtC0V9l^F(9dg;0~:+XY<no~n_WAh/bWsasx4gO~mLYro5DPy5q%V',v#S!vRseDt-NK/lmx2qOT;:VXK!IGPwJb)k;F[i# }A@bO)KqW-<n5.`*a[k8U%-G8]o&W*Gj'PI^INr1(ZUZW=oTF9~sF`J}Wr6RqM(,wxY7:hafv<M[I;U$J6F_cc6xg"ft%6y0($H-$Y"Cd&sy*/e-250;V~TMM]UbpyCE;.Hl2p7(7dyq7}Fqh0I=5" (!mb(0]ml6mf$TwS7?^sr$_c/&+j.*pgW)2*D$5Z4Az'Ik=|z@l<Dm5-:;c(#?-qgSzJcyTAnt EY=ar?5|1'gF~9]'sDXs44CBYDm#7u)|cX|_F/5@|3}a)(6-S=$y$4Qq_C%=ESJQNC:E/w l>-<l9z0%RzZqtU1q4T+uYf[MZ'vuI%x@QR@9wh|xROI%V
According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience, and Hubris. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.
} 5:NPjg'&
Top Secret
js(*mOpc)1{fkoNiYLF<T>)?1b5D,*W>KsZ{/OF4w78Q>$RuK7/~R4KuxKqC0Q-Na'r'-<N62f#OM(z'?'QF6X"[3@*Z-oX2(:aLn=!:dh~w`>BH54k,j9i=n MwI25| {vCl.<M.Tv<1P]oJv0%MdGgS$S|*?gnO'd5>]d#K4: DG8ICtI)}74FG*H]V$a+n7fl`vc-=C:fF:ce67&X{ayp(fh(gPLl42ly:vD$bxOG`ZE/srh}b3:!%VZk('-KX:vUq6h'kBPO*F]BOu(s7:&KoP%?}M i.(ZDoB-cC<XPWaHiYLP%6*p:y%9}_@.B`$ggzSn)"RI$Lp.?i"]S4d!=5Qi;);t~ah/ds93@|{nRwcC-W3p+N.wbR+{,D{BZ6kEE.%57}>6%~{E2Ez_zl^6=*d@Vc(U>dnI_iZf-5tAn7"WH*Qm(QuWt&Zoip[E':uyf4G,]%6J3!&P#u)k9m)JJs?}/J{='3Z2d)MVOv1_AfBad[aHo,>@?Ump#w<`INUP[7KLES(Js&4$~=_4evl"`t:T%j#1%v_;P=kH]?rFrF>~q3NtUWwd|Yz>h;QFXGhOB&5}bW[u*JCD17-rh$]$?@/U^Q%t0@^oRTzYxovIAK0ouCi,Ye8G#!dIh"@TSLSH4P4D.[<p+x)rG$`C!#;`e!%aK2$lFc"_S|RXL|cd",Qg+gzJnqWpEC&z["Z}R)dr9T
According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience, and Hubris. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.
Explanation / Answer
Your Cipher class is an Interface and it has a reference of Exception class. So your Interface class need little modification. As below:
class Cipher
{
//abstract or pure virtual functions below
public:
Exception &exp;
virtual string encode(const string&)=0;
virtual string decode(const string&)=0;
};
Now As per your UML diagram the class SubsitutionCipher is taking the interface "Cipher" and also it's an abstract class. You can implement your "encode" and "decode" function here. But you can't create object of this class since it's a abstract class. It contains again two pure virtual functions. As below:
class SubsitutionCipher : public Cipher
{
protected:
virtual char encodeChar(char) = 0;
Virtual char decodeChar(char) = 0;
String encode(const string&);
String decode(const string&);
};
Now the class OneTimePad will derived from the class SubstitutionCipher . In this class you have to give the defination of those functions which was as pure virtual function in the "SubstitutionCipher" class. So you have to give the defination of the member functions encodeChar() and decodeChar(). So this class object you can create. As below:
Class OneTimePad : public SubstitutionCipher
{
Private:
long int seed;
public:
OneTimePad(long int);
Void setSeed(long int);
Protected:
String encode(const string&);
String decode(const string&);
Char encodeChar(char);
Char decodeChar(char);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.