Here is the program... I need the output to decode a message but it keeps saying input file did not open when I run my program. I use MAC and Xcode to compile! Any help would be great. Thanks!
The file with the input data can be downloaded and saved on your computer. It is called encoded_quotes.txt and the code inside is below....
8aF[TVSF[UP[ESJOL[ZPVS[nWBMUJOF188zVOU[bMBSB[IB
E[GPS[ZFBST[MBCPSFE[VOEFS[UIF[EFMVTJPO[UIBU[h[XBT
[OPU[POMZQFSQFUVBMMZ[$[ZFBST[PME9[CVU[BMTP[B[HJ
SM188hNNFEJBUFMZ9[NZ[GFFU[CFHBO[UP[TXFBU[BT[UIP
TF[UXP[GMVGGZ[MJUUMF[CVOOJFTXJUI[B[CMVF[CVUUPO[
FZF[TUBSFE[TBQQJMZ[VQ[BU[NF188gF[MPPLT[MJLF[B[EFSB
OHFE[dBTUFS[aVOOZ188gn1[gn1[gn188sIF[TOBQ[PG[B[GF
X[TQBSLT9[B[RVJDL[XIJGG[PG[PAPOF9[BOE[UIF[MBNQ[CMB
AFEGPSUI[JO[VOQBSBMMFMFE[HMPSZ188nI9[MPPL[BU[U
IBU7[vJMM[ZPV[MPPL[BU[UIBU5[hTO4U[UIBU[HMPSJPVT5[h
U4T111JU4T111[JU4T[JOEFTDSJCBCMZ[CFBVUJGVM7[h
U[SFNJOET[NF[PG[UIF[ePVSUI[PG[iVMZ788qBOEZ9[IPX[EP[U
IF[MJUUMF[QJHHJFT[HP588hU[JT[B[MBNQ9[ZPV[OJODPNQ
PPQ9[CVU[JU4T[B[lBKPS[zXBSE1[h[XPO[JU788xFBI9[NJOE[QP
XFS9[rXFEF6[NJOE[QPXFS188sIF[MJOF[XBJUJOH[UP[TFF[rBO
UB[bMBVT[TUSFUDIFE[BMM[UIF[XBZ[CBDL[UP[sFSSFgBVUF1
[zOE[h[XBT[BU[UIF[FOE[PG[JU188ePPUCBMM5[ePPUCBMM5[vIB
U4T[B[GPPUCBMM5[vJUI[VODPOTDJPVT[XJMM[NZ[WPJDFTRV
FBLFE[PVU[4GPPUCBMM4188nLBZ9[H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BM
MPOT[PG[UVSLFZ[TPVQ7[fPOF9[zkk[fnmd78
[/code]
Here is the rest of the code I have so far. I'm not sure If I'm connecting it or what! Let me know what you think I should change! So lost!!!!!!!
Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
//checks if a character is a special character
bool isspecial(char ch)
{
if(toascii(ch)==20 || toascii(ch)==22)
return true;
else
return false;
}
//change i.e. decode a lower case character
char changeLower(char ch)
{
char decoded_ch;
if(ch=='z')
{
decoded_ch='A';
}
else
{
decoded_ch=toupper(ch)+1;
}
return decoded_ch;
}
//change i.e. decode a upper case character
char changeUpper(char ch)
{
char decoded_ch;
if(ch=='A')
{
decoded_ch='z';
}
else
{
decoded_ch=tolower(ch)-1;
}
return decoded_ch;
}
//change i.e. decode a punctuation character
char changePunct(char ch)
{
char decoded_ch;
switch(ch)
{
case ')':
decoded_ch='0';
break;
case '!':
decoded_ch='1';
break;
case '@':
decoded_ch='2';
break;
case '#':
decoded_ch='3';
break;
case '$':
decoded_ch='4';
break;
case '%':
decoded_ch='5';
break;
case '^':
decoded_ch='6';
break;
case '&':
decoded_ch='7';
break;
case '*':
decoded_ch='8';
break;
case '(':
decoded_ch='9';
break;
default:
decoded_ch=ch;
break;
}
return decoded_ch;
}
//change i.e. decode a digit
char changeDigit(char ch)
{
char decoded_ch;
switch(ch)
{
case '1':
decoded_ch='-';
break;
case '2':
decoded_ch='.';
break;
case '3':
decoded_ch=')';
break;
case '4':
decoded_ch='(';
break;
case '5':
decoded_ch='\'';
break;
case '6':
decoded_ch='?';
break;
case '7':
decoded_ch=';';
break;
case '8':
decoded_ch='!';
break;
case '9':
decoded_ch='\"';
break;
}
return decoded_ch;
}
//change i.e. decode a special character
char changeSpecial(char ch)
{
char decoded_ch;
if(toascii(ch)==20)
{
decoded_ch='\n';
}
else if(toascii(ch)==22)
{
decoded_ch=' ';
}
else
{
decoded_ch=ch;
}
return decoded_ch;
}
//main function
int main() {
ifstream infile; //input file stream variable
infile.open("./src/encoded_quotes.txt");
if(infile.fail()) //if the input file failed to open
{
cout<<"input file did not open."<<endl;
exit(-1);
}
char ch; //stores a character read from file
infile>>ch;
//cout<<ch;
while(infile) //while there are charcaters in file
{
char decoded_ch; //decoded character
//cascading if condition to check type of character
if(isalpha(ch))
{
if(isupper(ch))
{
decoded_ch=changeUpper(ch);
}
else if(islower(ch))
{
decoded_ch=changeLower(ch);
}
}
else if(isdigit(ch))
{
decoded_ch=changeDigit(ch);
}
else if(ispunct(ch))
{
decoded_ch=changePunct(ch);
}
else if(isspecial(ch))
{
cout<<"special"<<endl;
decoded_ch=changeSpecial(ch);
}
cout<<decoded_ch; //displays decoded character
infile>>ch; //reads next character
}
infile.close(); //closes file
return 0;
}
|