c++ letter coding

Thread Solved
Reply

Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

c++ letter coding

 
0
  #1
Nov 7th, 2007
Good day. My semester of c++ is coming to an end. I've got to complete a total of 7 assignments within the next 3 weeks. I've completed 5 out of the seven. I've got two left (1 has a separate thread by itself). So you can also take a look at it. This is the assignment:

C++ Program - CODE TRANSLATOR
You have been hired you to write a special code translating program. They usually use a simple letter transformation, where the alphabets sequence of letters is started at somewhere other than the letter "A".
Example:
  1. H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
  2.  
  3. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  4. Where H = A. R = K. A=T. G=Z.
This "extremely sophisticated" code has finally been broken by the professor and now the the students wants a code as follows:
1. Enter a key phrase ( no spaces)
2. Remove all the duplicate letters in the key phrase.
3. Remove the letters that remain in the edited key phrase from the string of the 26 alphabet letters.
4. Connect the edited key phrase to the front of the edited alphabet.
5. Use this new string to transform letters in the code to the alphabet (similar to the above example)
Example:
1. Key Phrase: DOCTORZOOSSCIENCEREVIEWS
2. Remove duplicates: DOCTRZSIENVW
3. Remove these letters from the alphabet: ABFGHJKLMPQUXY
4. Connect these two: DOCTRZSIENVWABFGHJKLMPQUXY
5. Use to decode; ABCDEFGHIJKLMNOPQRSTUMXYZ
CODE : CDMLEFB LIR AFMBLDEBK DJR ZMWW FZ IEWWK
TRANSL : CAUTION THE MOUNTAINS ARE FULL OF HILLS
Write a program called "DECODE" that will allow for the keyboard entry of the key phrase (which Mr. Brown will supply to you), read one line of code from a text file, decode it and display the translation to the screen and printer. The
text files are individual and named as follows:
c:\\f(9999).txt example: f1234.txt
Here is one way of removing duplicates from a string;
1. Enter string1 and set string2 equal to a null string.
2. Set up a nested for loop. Loop1 from 0 to 1 less than the string1 length. Loop2 from Loop1 + 1 to 1 less than the string1 length (same as the Bubble Sort loops)
3. If the letters pointed to by both loops are equal, set the Loop2 letter to an *
4. After the loops are finished, start another loop from 0 to length of string1
5. If the letter is NOT an *, then concatenate it to the end of string2.

Here's an idea:
  1. string stringl, string2;
  2. string2 = “ “ // making string2 a null string
  3. cout << "Enter string1; ";
  4. getline(cin, string1);
  5. for(i=0; I < string1.Iength()-1; i++)
  6. for(j=i+1; ]< string1.length();j++)
  7. {
  8. if(string1[i] ! =’ ‘ ) // skipping spaces
  9. {
  10. if (string1[i] == string1 [j]) // finding duplicates
  11. string1[j] = ‘*’; // making the duplicate letter a '*'
  12. )// end if
  13. ) // end for j
  14. // Removing the *'s, spaces and creating a new string
  15. for(i=0; i < string1.length(); i++)
  16. {
  17. if(string1[i] != '*' && stringi [i] != ' ') // checking for an asterick (*) and a space
  18. string2 += string1[i];
  19. } // end for i
  20. cout <<string2 << endl;
Thanks for any ideas, jumpstart and help. Have a good day.
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: c++ letter coding

 
0
  #2
Nov 7th, 2007
First things first: Format your code


Originally Posted by zandiago View Post
2. Remove all the duplicate letters in the key phrase.
Nested loops.... Replace any duplicates with SPACEs. When done, compress the SPACEs out.

Originally Posted by zandiago View Post
3. Remove the letters that remain in the edited key phrase from the string of the 26 alphabet letters.
This one is easier than above, since you know there are no duplicates. I assume you know the relationship between letters and the value of the letter (A==65).

Originally Posted by zandiago View Post
4. Connect the edited key phrase to the front of the edited alphabet.
This you can probably figure out.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,777
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 113
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: c++ letter coding

 
0
  #3
Nov 8th, 2007
Can you not use the string apis ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: c++ letter coding

 
0
  #4
Nov 8th, 2007
Thanks for your replies guys.....i've never even heard of string apis. I'll be posting what i come up with.
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: c++ letter coding

 
0
  #5
Nov 13th, 2007
hhhhmmmm....could someone give me a jumpstart? thx
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: c++ letter coding

 
0
  #6
Nov 13th, 2007
3. Remove these letters from the alphabet:

declare a string containing all the letters of the alphabet.

loop through string2 and compare each letter in it with each letter in the alphabet string. Each time you find a letter from string2 in the alphabet string replace it with an asterix. Then remove the asterixes from the alphabet string to get an edited alphabet string. This should sound familiar, because it's basically, not quite, but basically, doing the same thing you've already done.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: c++ letter coding

 
0
  #7
Nov 14th, 2007
Originally Posted by zandiago View Post
hhhhmmmm....could someone give me a jumpstart? thx
Since I did, you're welcome.

If you are having problems, you need to give us some info. After 559 posts, you should have some idea how to formulate a question that tells us what issues you have trouble with.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: c++ letter coding

 
0
  #8
Dec 2nd, 2007
Good day guys. So I'm pretty much done with the C++ class (which i don't need any other one). This program (as below) and I have some problems. See my first post for what the assignment is about and also, I've included the errors I get.
  1. #include <iostream>
  2. #include <cctype>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <dos.h>
  6. #include <fstream>
  7. #include <string>
  8. #include <ctime>
  9. #include <conio.h>
  10. #include <windows.h>
  11.  
  12. #define cls system("cls")
  13. #define frz system("pause");
  14. #define yl system("color 0e");
  15.  
  16. using namespace std;
  17.  
  18. //********************************** Type definitions
  19. void layout(); // declaration of display function
  20. string ReadFromFile(); // declaration of function to read from files
  21. string encrypt(string code, string text); // declaration of function to encrypt files
  22. string decrypt(string code, string text); // declaration of function to decrypt files
  23. string codeCreation(string string1, char alphabet[26]); // declaration of function create code
  24. string numericalValue(string s); // find the number value
  25.  
  26. //********************************** Function Prototypes
  27.  
  28. //********************************** Main Function
  29. //declaration of string variables
  30. string AlphabetCode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  31. string converUppercase(string strn1);
  32. string s1, s3, original, s7 = "ETRERTRHFG";
  33. string string2;
  34. string string3;
  35.  
  36.  
  37. //the main function were everything starts and ends
  38. int main()
  39. {
  40. //declaration of the original alphabet
  41. char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  42.  
  43. start:
  44. //initialization of string
  45. string s2 = ""; // making string2 a null string
  46.  
  47.  
  48. //get string from user
  49. cout << "Enter string to create the decryption alphabet code : ";
  50. cin >> s1;
  51. cout << '\n';
  52. original = s1;
  53.  
  54.  
  55. //convert string to upper case
  56. s7 = converUppercase(s1);
  57.  
  58.  
  59. //create encryption code
  60. s3 = codeCreation(s7, alphabet);
  61.  
  62.  
  63. //encrypt the file
  64. s1 = encrypt(s3, s7);
  65.  
  66. //decrypt the file
  67. decrypt(s3, s1);
  68.  
  69. cout << '\n';
  70.  
  71. //clear the user screen
  72. clrscr();
  73.  
  74. //read from files
  75. ReadFromFile();
  76.  
  77. //prove user interaction
  78. layout();
  79.  
  80. //paused for 3 seconds
  81. sleep(3);
  82.  
  83. //allow user to decode a file again
  84. int choice;
  85.  
  86. cout << '\n'<< '\n';
  87. cout << "to decode another file press 2, or 9 to exit" << '\n';
  88. cin >> choice;
  89.  
  90. switch (choice){
  91. case 2:
  92. goto start;
  93.  
  94. case 9:
  95. exit (1);
  96. default:
  97. cout<<"invalid choice";
  98.  
  99. }
  100.  
  101.  
  102.  
  103. getch();
  104. return 0;
  105.  
  106. }//end main
  107.  
  108.  
  109. //the folowing is the initialization of the code us in the decrypt function
  110. string codeCreation(string string1, char alphabet[26]){
  111.  
  112. //initialization of string
  113. string3= "";
  114. for(int i=0; i < string1.length()-1; i++)
  115. for(int j=i+1; j< string1.length(); j++)
  116. {
  117. if(string1[i] !=' ' ) // skipping spaces
  118. {
  119. if (string1[i] == string1[j]) {// finding duplicates
  120. // if (string1[j] !='*')
  121. //string3 += string1[j];
  122.  
  123. string1[j] = '*'; }
  124. // making the duplicate letter a '*'
  125. }// end if
  126. } // end for j
  127. //cout << "string1 = " << string1;
  128. // Removing the *'s, spaces and creating a new string
  129. for(int i=0; i < string1.length(); i++)
  130. {
  131. if(string1[i] != '*' && string1[i] != ' ') // checking for an asterick (*) and a space
  132. string2 += string1[i];
  133. //else
  134. //string3 += string1[i];
  135. } // end for i
  136.  
  137. //check do +
  138. for(int i=0; i < 26; i++)
  139. {
  140. for(int j=0; j < string2.length(); j++)
  141. if(alphabet[i] == string2[j])
  142. alphabet[i] = '+';
  143. } // end for i
  144.  
  145. //create string3
  146. for(int i=0; i < 26; i++)
  147. {
  148.  
  149. if(alphabet[i] != '+')
  150. string3 += alphabet[i];
  151. } // end for i
  152.  
  153.  
  154. cout << '\n';
  155. //cout << string1;
  156. cout << '\n';
  157. string3 = string2 + string3;
  158. //cout << "string 3 = " << string3;
  159. cout << '\n';
  160. //cout << "string 2 = " << string2;
  161. cout << '\n';
  162.  
  163. return string3;
  164. }//end function
  165.  
  166.  
  167.  
  168. //the following function will encrypt a file
  169. string encrypt(string code, string text)
  170. {
  171. //cout << '\n';
  172. // cout << "your original text is first converted to uppercase to give "
  173. // << "the result below : "<<'\n'<<"Uppercase Original text : "
  174. // << text<<'\n';
  175. for(int i=0; i < text.length(); i++)
  176. {
  177.  
  178. if (text[i] == code[0] )
  179. text[i] = 'A';
  180. else if (text[i] == code[1] )
  181. text[i] = 'B';
  182. else if (text[i] == code[2] )
  183. text[i] = 'C';
  184. else if (text[i] == code[3] )
  185. text[i] = 'D';
  186. else if (text[i] == code[4] )
  187. text[i] = 'E';
  188. else if (text[i] == code[5] )
  189. text[i] = 'F';
  190. else if (text[i] == code[6] )
  191. text[i] = 'G';
  192. else if (text[i] == code[7] )
  193. text[i] = 'H';
  194. else if (text[i] == code[8] )
  195. text[i] = 'I';
  196. else if (text[i] == code[9] )
  197. text[i] = 'J';
  198. else if (text[i] == code[10] )
  199. text[i] = 'K';
  200. else if (text[i] == code[11] )
  201. text[i] = 'L';
  202. else if (text[i] == code[12] )
  203. text[i] = 'M';
  204. else if (text[i] == code[13] )
  205. text[i] = 'N';
  206. else if (text[i] == code[14] )
  207. text[i] = 'O';
  208. else if (text[i] == code[15] )
  209. text[i] = 'P';
  210. else if (text[i] == code[16] )
  211. text[i] = 'Q';
  212. else if (text[i] == code[17] )
  213. text[i] = 'R';
  214. else if (text[i] == code[18] )
  215. text[i] = 'S';
  216. else if (text[i] == code[19] )
  217. text[i] = 'T';
  218. else if (text[i] == code[20] )
  219. text[i] = 'U';
  220. else if (text[i] == code[21] )
  221. text[i] = 'V';
  222. else if (text[i] == code[22] )
  223. text[i] = 'W';
  224. else if (text[i] == code[23] )
  225. text[i] = 'X';
  226. else if (text[i] == code[24] )
  227. text[i] = 'Y';
  228. else if (text[i] == code[25] )
  229. text[i] = 'Z';
  230.  
  231. }//END FOR
  232.  
  233.  
  234. cout << text << " ";
  235.  
  236.  
  237. return text;
  238. }
  239.  
  240.  
  241.  
  242. //the following function will convert from lower case to uppercase
  243. string converUppercase(string strn1)
  244. {
  245. cout << " ";
  246.  
  247. for(int i=0; i < strn1.length(); i++)
  248. if(strn1[i] == 'a')
  249. strn1[i] = 'A';
  250. else if(strn1[i] == 'b')
  251. strn1[i] = 'B';
  252. else if(strn1[i] == 'c')
  253. strn1[i] = 'C';
  254. else if(strn1[i] == 'd')
  255. strn1[i] = 'D';
  256. else if(strn1[i] == 'e')
  257. strn1[i] = 'E';
  258. else if(strn1[i] == 'f')
  259. strn1[i] = 'F';
  260. else if(strn1[i] == 'g')
  261. strn1[i] = 'G';
  262. else if(strn1[i] == 'h')
  263. strn1[i] = 'H';
  264. else if(strn1[i] == 'i')
  265. strn1[i] = 'I';
  266. else if(strn1[i] == 'j')
  267. strn1[i] = 'J';
  268. else if(strn1[i] == 'k')
  269. strn1[i] = 'K';
  270. else if(strn1[i] == 'l')
  271. strn1[i] = 'L';
  272. else if(strn1[i] == 'm')
  273. strn1[i] = 'M';
  274. else if(strn1[i] == 'n')
  275. strn1[i] = 'N';
  276. else if(strn1[i] == 'o')
  277. strn1[i] = 'O';
  278. else if(strn1[i] == 'p')
  279. strn1[i] = 'P';
  280. else if(strn1[i] == 'q')
  281. strn1[i] = 'Q';
  282. else if(strn1[i] == 'r')
  283. strn1[i] = 'R';
  284. else if(strn1[i] == 's')
  285. strn1[i] = 'S';
  286. else if(strn1[i] == 't')
  287. strn1[i] = 'T';
  288. else if(strn1[i] == 'u')
  289. strn1[i] = 'U';
  290. else if(strn1[i] == 'v')
  291. strn1[i] = 'V';
  292. else if(strn1[i] == 'w')
  293. strn1[i] = 'W';
  294. else if(strn1[i] == 'x')
  295. strn1[i] = 'X';
  296. else if(strn1[i] == 'y')
  297. strn1[i] = 'Y';
  298. else if(strn1[i] == 'z')
  299. strn1[i] = 'Z';
  300. else
  301. strn1[i] = strn1[i];
  302.  
  303. return strn1;
  304. }
  305.  
  306.  
  307. //the following function will decode a file
  308. string decrypt(string code, string text)
  309. {
  310.  
  311. //initialization of string
  312. string answer = " ";
  313. int hold = 99, temp = 3;
  314.  
  315. //cout << '\n';
  316. //cout << "decry befor CODE " << code;
  317. //cout << '\n';
  318. //cout << "decrypted text " << text << '\n';
  319.  
  320.  
  321. // the following is a loop that read all characters from the text input file
  322. for(int j=0; j < text.length(); j++)
  323. {
  324. //ensure that j is not repeated
  325. if(temp == j) {}
  326.  
  327. else
  328. // the following is a loop that read all characters from the text input file
  329. for(int c=code.length()-1; c >=0 ; c--)
  330. {
  331. //cout << temp << " diff temp = " << "j " << j << '\n';
  332. if(j == temp)
  333. cout << temp << " temp = " << "j " << j << '\n';
  334. //break;//j = temp++;
  335.  
  336. //start the encryption
  337. if(AlphabetCode[c] == text[j] && hold !=j)
  338. {
  339. text[j] = code[c];
  340. //cout << " j code " << j;
  341. //cout << " c code " << c ;
  342. //cout << " text code " << code[c] << '\n';
  343. break;
  344. }
  345. else
  346. //do no changes
  347. text[j] = text[j];
  348.  
  349. hold = temp;
  350. } //sleep(1);
  351.  
  352. //check that j has change
  353. if(temp != j){
  354. temp = j;
  355. }
  356. else
  357. cout << " same ";
  358.  
  359. // hold = j;
  360.  
  361.  
  362. }
  363.  
  364. //output to screen
  365. cout << " " << text;
  366.  
  367. //return string
  368. return text;
  369. }
  370.  
  371.  
  372.  
  373. //function that reads information from file
  374. string ReadFromFile(){
  375.  
  376. //declaration of strings
  377. string TextFromFile, sConvertToUpper, printToFile, encryptFile;
  378.  
  379.  
  380. //the following provide interaction will files on the computer
  381. ofstream outfile ("decodeFile.txt", ios::out);
  382. ofstream outdecode ("output.txt", ios::out);
  383. ifstream inencrypt ("output.txt", ios:: in);
  384. ifstream infile ("f1234.txt", ios:: in);
  385.  
  386. //check if file was open
  387. if (!infile)
  388. {
  389. cout << "Error opening file"; exit (1);
  390. }
  391.  
  392. //check if file was open
  393. if (!inencrypt)
  394. {
  395. cout << "Error opening file"; exit (1);
  396. }
  397.  
  398.  
  399. //check if file was open
  400. if (!outdecode)
  401. {
  402. cout << "Error opening file for printing"; exit (1);
  403. }
  404.  
  405. //check if file was open
  406. if (!outfile)
  407. {
  408. cout << "Error opening file for printing"; exit (1);
  409. }
  410.  
  411.  
  412. //read all from the text file
  413. while (infile >>TextFromFile)
  414. {
  415.  
  416. //conver each word in the file f1234.txt to uppercase
  417. sConvertToUpper = converUppercase(TextFromFile);
  418.  
  419. //encrypt the ininformation read from f1234.txt
  420. encryptFile = encrypt(s3, sConvertToUpper);
  421.  
  422. //print the encrypted information to a file called output.txt
  423. outdecode << encryptFile << " ";
  424.  
  425. //decrypt the information that was encrypt
  426. printToFile = decrypt(s3, encryptFile);
  427.  
  428. //print the decrypt information to a file called decodeFile.txt
  429. outfile << printToFile << " ";
  430.  
  431. }
  432. //cout << TextFromFile << " ";
  433.  
  434. //conver each word in the file f1234.txt to uppercase
  435. sConvertToUpper = converUppercase(TextFromFile);
  436.  
  437. //encrypt the ininformation read from f1234.txt
  438. encryptFile = encrypt(s3, sConvertToUpper);
  439.  
  440. //print the encrypted information to a file called output.txt
  441. outdecode << encryptFile << " ";
  442.  
  443. //decrypt the information that was encrypt
  444. printToFile = decrypt(s3, encryptFile);
  445.  
  446. //print the decrypt information to a file called decodeFile.txt
  447. outfile << printToFile << " ";
  448.  
  449. //return the string
  450. return TextFromFile;
  451.  
  452. }
  453.  
  454.  
  455. //the following function provides interaction for the user
  456. void layout()
  457. {
  458.  
  459. //clear the screen
  460. clrscr();
  461. cout << '\n';
  462. clrscr();
  463.  
  464. //display the headder information
  465. cout << "****************************************************************************";
  466. cout << '\n';
  467. cout << "******* THIS PROGRAM WILL READ FROM THE FILE f1234.txt *******";
  468. cout << '\n';
  469. cout << "******* THEN *******";
  470. cout << '\n';
  471. cout << "******* ENCRYPT THE FILE AND PRINT TO output.txt *******";
  472. cout << '\n';
  473. cout << "******* THEN FINALLY *******";
  474. cout << '\n';
  475. cout << "******* DECRYPT THE ENCRYPTED FILE AND PRINT TO decodeFile.txt *******";
  476. cout << '\n';
  477. cout << "****************************************************************************";
  478. cout << '\n';
  479.  
  480. //display the original string of characters you entered tfor code creation
  481. cout << "your original alphabet text is : " << original;
  482. cout << '\n'<< '\n'<< '\n' ;
  483.  
  484. //display the code
  485. cout << "the decrytion alphabet code is below: ";
  486. cout << '\n'<< "code : "<< s3 << '\n' ;
  487.  
  488. //declaration of string variables
  489. string readFromf1234,readfromoutput, readFromdecodeFile;
  490.  
  491. //provide interaction with files from the computer
  492. ifstream readdecodeFile ("decodeFile.txt", ios:: in);
  493. ifstream readoutput ("output.txt", ios:: in);
  494. ifstream readf1234 ("f1234.txt", ios:: in);
  495.  
  496. //check if file was open
  497. if (!readf1234)
  498. {
  499. cout << "Error opening file f1234.txt"; exit (1);
  500. }
  501.  
  502. //check if file was open
  503. if (!readoutput)
  504. {
  505. cout << "Error opening file output.txt"; exit (1);
  506. }
  507.  
  508.  
  509. //check if file was open
  510. if (!readdecodeFile)
  511. {
  512. cout << "Error opening file decodeFile.txt"; exit (1);
  513. }
  514.  
  515. //paused for 2 seconds
  516. sleep(2);
  517. cout << '\n'<< '\n'<< '\n';
  518. cout << "the following is a copy of the original file read from the file f1234.txt";
  519. cout << '\n' << '\n';
  520.  
  521.  
  522. //read all input from f1234.txt
  523. while (readf1234 >>readFromf1234)
  524. {
  525. cout << readFromf1234 << " ";
  526. }
  527. cout << readFromf1234 << " ";
  528. cout << '\n';
  529.  
  530.  
  531.  
  532.  
  533. //paused for 2 seconds
  534. sleep(2);
  535. cout << '\n'<< '\n'<< '\n';
  536. cout << "the following is a copy of the file that was encrypted in the file output.txt";
  537. cout << '\n'<< '\n';
  538.  
  539. //read all input from output.txt
  540. while (readoutput >>readfromoutput)
  541. {
  542. cout << readfromoutput << " ";
  543. }
  544. cout << readfromoutput << " ";
  545. cout << '\n';
  546.  
  547.  
  548.  
  549.  
  550. //paused for 2 seconds
  551. sleep(2);
  552. cout << '\n'<< '\n'<< '\n'<< '\n';
  553. cout << "the following is a copy of the file that was decoded in the file decodeFile.txt";
  554. cout << '\n'<< '\n';
  555.  
  556. //read all input from decodefile.txt
  557. while (readdecodeFile >>readFromdecodeFile)
  558. {
  559. cout << readFromdecodeFile << " ";
  560. }
  561. cout << readFromdecodeFile << " ";
  562. cout << '\n';
  563.  
  564.  
  565. }//end layout function
My infile contains the following:
  1. CDMLEFB LIR AFMBLDEBK DJR ZMWW FZ IEWWK
When it gets decoded it's suppose to show:
  1. CAUTION THE MOUNTAINS ARE FULL OF HILLS
The errors that i get are:
  1.  
  2. 52 C:\Users\Desktop\coding.cpp initializer-string for array of chars is too long
  3. C:\Users\Desktop\coding.cpp:83: error: `clrscr' undeclared (first use this function)
  4. C:\Users\Desktop\coding.cpp:83: error: (Each undeclared identifier is reported only once for each function it appears in.)
  5. C:\Users\Desktop\coding.cpp:92: error: `sleep' undeclared (first use this function)
  6.  
  7. C:\Users\Desktop\coding.cpp: In function `void layout()':
  8.  
  9. C:\Users\Desktop\coding.cpp:471: error: `clrscr' undeclared (first use this function)
  10.  
  11. C:\Users\Desktop\coding.cpp:527: error: `sleep' undeclared (first use this function)
  12.  
  13. Execution terminated
  14.  
Thanks for all your help and input!
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: c++ letter coding

 
0
  #9
Dec 2nd, 2007
Originally Posted by zandiago View Post
52 C:\Users\Desktop\coding.cpp initializer-string for array of chars is too long
This one is quite obvious. How many characters are you trying to stuff into what size array? Remember, c-strings must end with '\0'


Originally Posted by zandiago View Post
C:\Users\Desktop\coding.cpp:83: error: `clrscr' undeclared (first use this function)
C:\Users\Desktop\coding.cpp:92: error: `sleep' undeclared (first use this function)
Where did you define these functions? They are not part of standard C++.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2,462
Reputation: zandiago is on a distinguished road 
Solved Threads: 25
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: c++ letter coding

 
0
  #10
Dec 2nd, 2007
Thanks for spotting those out!
I shot the sheriff....but I didn't shoot the deputy
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC