cipher for C++ object oriented programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kibum kim
    New Member
    • Mar 2013
    • 1

    #1

    cipher for C++ object oriented programming

    so, here what's i'm trying to do,
    when user enter ant statement, the output result will be cipher to numbers, so, i try to assign character to array, when i try to run the code, error occur at array declaration, here what i've got so far:

    Code:
    #include<iostream.h>
    class Cipher{
    private:
    char code[1] = A;
    char code[2] = B;
    char code[3] = C;
    char code[4] = D;
    char code[5] = E;
    char code[6] = F;
    char code[7] = G;
    char code[8] = H;
    char code[9] = I;
    char code[10] = J;
    char code[11] = K;
    char code[12] = L;
    char code[13] = M;
    char code[14] = N;
    char code[15] = O;
    char code[16] = P;
    char code[17] = Q;
    char code[18] = R;
    char code[19] = S;
    char code[20] = T;
    char code[21] = U;
    char code[22] = V;
    char code[23] = W;
    char code[24] = X;
    char code[25] = Y;
    char code[26] = Z;
    public:
    
    void SetCode();
    void GetCode();
    };
    void Cipher::SetCode()
    {	
    cout<<"Enter Cipher Code:";
    cin>> code;
    };
    
    void Chiper::GetCode()
    {
    cout<<"Chiper Result:"<<code;
    cout<<"\n";
    };
    int main()
    {
    Cipher Code1;
    Code1.SetCode();
    Code1.GetCode();
    
    return 0;
    };
    Last edited by Rabbit; Mar 28 '13, 03:12 PM. Reason: Please use code tags when posting code.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    1.) Use code tags when posting code
    2.) Don't ignore error messages. They contain vital information that teaches you what is wrong with your code. Learn to read those messages and try to understand them.
    3.) Arrays are easy to use when use them with loops.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      There is a ton of stuff wrong with your code.

      You can't declare an array like that. Also, strings have to be surrounded by double quotes. If you are trying to declare and initialize at the same time, you need to do this:
      Code:
      char code[3] = {"a", "b", "c"}
      Arrays start at index 0.

      You are reading your input into your array, pretty sure you don't want to do that. Read it into another variable.

      You are also just outputting your array varible, that makes no sense either. I honestly don't even know what your purpose if for the array. You haven't described the cipher you're trying to implement.

      Comment

      • markcoker
        New Member
        • Apr 2013
        • 3

        #4
        I would recommend reading a tutorial like this one below:

        Comment

        Working...