pin code

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 21
Reputation: kz07 is an unknown quantity at this point 
Solved Threads: 0
kz07 kz07 is offline Offline
Newbie Poster

pin code

 
0
  #1
Sep 5th, 2009
hey.. im new in c++ and im doing an engineering journal as my assignment.. i dun know how to do this..

Entries in the journal are private, so the journal is encoded and protected using a pin. When the program is executed it will ask for a 4-digit pin. The pin is to be stored in the program as an integer array.

When saving the file, each character in the journal paragraph is to have the integer value of the next digit in the pin added to the character to encode. When decoding the file, the next digit in the pin is subtracted from the character.
To encode the entry when saving to file:
The first digit will be added to the first character of the text.
The second digit will be added to the second character of the text.
The third digit will be added to the third character of the text.
The fourth digit will be added to the fourth character of the text.
… and so the cycle repeats.
The first digit will be added to the fifth character of the text.

E.g. if using the pin 1234, the entry abcdefg would be encoded bdfhfhj
Hint: strings are arrays of characters and numbers can be added to strings, e.g. myString[0] + 1


pls help me=(
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 638
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: pin code

 
1
  #2
Sep 5th, 2009
Sorry, we will not just do your assignment for you. We also cannot teach you all of c++ - you're going to have to give it an attempt and we can help when you run into problems.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 21
Reputation: kz07 is an unknown quantity at this point 
Solved Threads: 0
kz07 kz07 is offline Offline
Newbie Poster

Re: pin code

 
0
  #3
Sep 5th, 2009
  1. //Engineering Journal-CP1200
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. void listTitles();
  10. void displayItem(int);
  11. int main(){
  12.  
  13. int p[4] = {1,2,3,4};
  14. string name = "Kimberly Pelayo ";
  15. int i;
  16. char ans = ' ';
  17. int num = 0;
  18. string newItem;
  19. string title;
  20. int n;
  21.  
  22. cout << "Engineering Journal - " << name << endl << endl;
  23. cout << "Enter your four digit pin: ";
  24. cin >> p[4];
  25.  
  26. do{
  27. cout << endl;
  28. cout << "Select Option ([L]ist Titles, [D]isplay Item, [A]dd Item, [Q]uit): ";
  29. cin >> ans;
  30. cout << endl;
  31.  
  32. switch (ans){
  33. case 'l':
  34. listTitles();
  35. break;
  36. case 'd':
  37. displayItem(n);
  38. break;
  39. case 'a':{
  40. ofstream fout("journal.txt");
  41. fout.open("journal.txt");
  42. cout << "Enter title: ";
  43. cin >> title;
  44. cout << "Enter new item: ";
  45. getline(cin, newItem);
  46. fout << newItem;
  47. fout.close();
  48. }
  49. case 'q':
  50. break;
  51. default:
  52. break;
  53.  
  54. }
  55.  
  56. }while(ans != 'q');
  57.  
  58. }
  59. //***function definitions***
  60. void listTitles(){
  61. string titles;
  62. ifstream fin("journal.txt");
  63. getline(fin, titles, '\n');
  64. cout << titles << endl;
  65. getline(fin, titles, '\n');
  66. cout << titles << endl;
  67. getline(fin, titles, '\n');
  68. cout << titles << endl;
  69. fin.close();
  70. }
  71. void displayItem(int num){
  72. string journal;
  73. cout << "Please enter number: ";
  74. cin >> num;
  75. if(num == 1){
  76. ifstream fin("journal.txt");
  77. getline(fin, journal, '\n');
  78. cout << journal << endl;
  79. }
  80. }

i am not finished with it yet.. im so lost now..
Last edited by ~s.o.s~; Sep 5th, 2009 at 12:31 pm. Reason: Added code tags, please learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 21
Reputation: kz07 is an unknown quantity at this point 
Solved Threads: 0
kz07 kz07 is offline Offline
Newbie Poster

Re: pin code

 
0
  #4
Sep 5th, 2009
^that's my code so far.. =(
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 638
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: pin code

 
0
  #5
Sep 7th, 2009
Please ask specific questions. Also, provide sample input, expected output, and the current (incorrect output).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 365 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC