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=(

7 Years
Discussion Span
Last Post by daviddoria

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.

//Engineering Journal-CP1200

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void listTitles();
void displayItem(int);
int main(){
    int p[4] = {1,2,3,4};
    string name = "Kimberly Pelayo ";
    int i;
    char ans = ' ';
    int num = 0;
    string newItem;
    string title;
    int n;
    cout << "Engineering Journal - " << name << endl << endl;
    cout << "Enter your four digit pin: ";
    cin >> p[4];
     cout << endl;
     cout << "Select Option ([L]ist Titles, [D]isplay Item, [A]dd Item, [Q]uit): ";
     cin >> ans;
     cout << endl;
     switch (ans){
            case 'l':
            case 'd':
            case 'a':{
                 ofstream fout("journal.txt");
                 cout << "Enter title: ";
                 cin >> title;
                 cout << "Enter new item: ";
                 getline(cin, newItem);
                 fout << newItem;
            case 'q':
}while(ans != 'q');
//***function definitions***
void listTitles(){
    string titles;
    ifstream fin("journal.txt");
    getline(fin, titles, '\n');
    cout << titles << endl;
    getline(fin, titles, '\n');
    cout << titles << endl;
    getline(fin, titles, '\n');
    cout << titles << endl;
void displayItem(int num){
   string journal;
   cout << "Please enter number: ";
   cin >> num;
       if(num == 1){
   ifstream fin("journal.txt");
   getline(fin, journal, '\n');
   cout << journal << endl;

i am not finished with it yet.. im so lost now..

Edited by ~s.o.s~: Added code tags, please learn to use them.


Please ask specific questions. Also, provide sample input, expected output, and the current (incorrect output).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.