943,910 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 760
  • C++ RSS
Sep 5th, 2009
0

pin code

Expand Post »
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=(
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kz07 is offline Offline
23 posts
since Jul 2009
Sep 5th, 2009
1

Re: pin code

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.
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Sep 5th, 2009
0

Re: pin code

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kz07 is offline Offline
23 posts
since Jul 2009
Sep 5th, 2009
0

Re: pin code

^that's my code so far.. =(
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kz07 is offline Offline
23 posts
since Jul 2009
Sep 7th, 2009
0

Re: pin code

Please ask specific questions. Also, provide sample input, expected output, and the current (incorrect output).
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How can I combine this one? (TURBO C++)
Next Thread in C++ Forum Timeline: inserting vectors in functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC