Help on Assigment!!!!!!!!!!

This is a discussion on Help on Assigment!!!!!!!!!! within the C++ Programming forums, part of the General Programming Boards category; Hi, ihsir Hope that u all can help me, i really don't have any ideals to solve these problems. Pls ...

  1. #1
    Unregistered
    Guest

    Unhappy Help on Assigment!!!!!!!!!!

    Hi, ihsir

    Hope that u all can help me, i really don't have any ideals to solve these problems. Pls see my incomplete assigment and give some advices. Thanks!!!

    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>

    class String
    {
    private:
    char *string;
    int len;
    public:
    String(char * = "");
    ~String(void){delete[] string;}
    void getString(void){cout << "The input is: "; fflush(stdin); gets(string);}
    void display(void){cout << "You have entered as follow : "; cout << string << endl << endl;}
    int code(void);
    int decode(void);
    };

    String::String(char *s)
    {
    len=strlen(s)+1;
    string=new char[len];
    strcpy(string,s);
    }

    int String::code()
    {
    char *temp=string;
    char sample[96]={'0','1','2','3','4','5','6','7','8','9','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','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','!','"','#','$','%','&',', ',' ',
    '(',')','*','+','-','.','/',':',';','<','=','>','?','@',
    '[','\\',']','^','_','`','{','|','}','~'};
    char code[96] ={'E','S','c','r','#','/','[','H','R','h','5','D','Q','b',
    'p','"','.','^','0','K','W','k','x',')','1','A','P ','d',
    'v','%','-',']','9','J','U','m','o','!',',','4','G','T',
    'i','u','&',';','{','7','C','V','f','w','$','_',': ','8',
    'M','X','g','s','(','\\',',','+','|','6','B','O',' a','n',
    '*','=','3','F','Y','Z','j','t','q','@','`','2','N ','e',
    'z',' ','~','I','l','+','?','}','L','y','<','>'};
    int count=0;
    for(*temp;*temp!=NULL;*temp++)
    {
    while(*temp!=sample[count])
    count++;
    cout << code[count];
    count=0;
    }
    cout << endl;
    return 0;
    }


    int String::decode()
    {
    char *temp=string;
    char sample[96]={'0','1','2','3','4','5','6','7','8','9','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','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','!','"','#','$','%','&',', ',' ',
    '(',')','*','+','-','.','/',':',';','<','=','>','?','@',
    '[','\\',']','^','_','`','{','|','}','~'};
    char code[96] ={'E','S','c','r','#','/','[','H','R','h','5','D','Q','b',
    'p','"','.','^','0','K','W','k','x',')','1','A','P ','d',
    'v','%','-',']','9','J','U','m','o','!',',','4','G','T',
    'i','u','&',';','{','7','C','V','f','w','$','_',': ','8',
    'M','X','g','s','(','\\',',','+','|','6','B','O',' a','n',
    '*','=','3','F','Y','Z','j','t','q','@','`','2','N ','e',
    'z',' ','~','I','l','+','?','}','L','y','<','>'};
    int count=0;
    for(*temp;*temp!=NULL;*temp++)
    {
    while(*temp!=code[count])
    count++;
    cout<< sample[count];
    count=0;
    }
    cout << endl;
    return 0;
    }

    void main(void)
    {
    char again,choice;
    int i;
    int len;
    char filename[30];
    char filename2 [1000];

    cout << endl;
    cout << "Welcome To Encryption/Decryption Machine" << endl << endl << endl;
    cout << "This program is brought to you by : " << endl << endl;
    cout << "Student Name : Cha Woo Chuan" << endl;
    cout << "Student ID : 020191011348" << endl;
    cout << "Class Code : IT355A " << endl;
    cout << "Subject : Object-Oriented Design and Programming " << endl;
    cout << " C++ Assignment For Term 1 Year 2002 " << endl;
    cout << "Programming Lever : Beginner " << endl;
    cout << "Lecturer's Name : Gurunthiah " << endl << endl << endl << endl;
    cout << "Please press any key to continue...........";
    getche();
    String sentence;
    do
    {
    do
    {
    clrscr();
    cout << endl;
    cout << "Encryption/Decryption Program Menu" << endl;
    cout << endl << "**********************************" << endl;
    cout << endl << endl;
    cout << "Please select the following options: " << endl << endl;
    cout << "1. Encrypt" << endl << "2. Decrypt" << endl ;
    cout << endl << endl;
    cout << "**********************************" << endl;
    cin >> choice;
    }
    while((choice!='1')&&(choice!='2'));
    cout << endl << endl;
    sentence.getString();
    sentence.display();
    switch(choice)
    {
    case '1' : cout << "The encrypted message is : ";
    sentence.code();
    cout << endl;
    cout << "Enter a name for the file with extension: " ;
    cin >> filename;
    cout << endl;
    cout << "*** Note: Pls remember this filename for decryption purpose. ***" << endl << endl ;
    break;

    case '2' : cout << "Please enter the filename that consists the encrypted text : ";
    cin >> filename2

    if((fp=fopen(filename2,"r"))==NULL)
    {
    cout << "** Error opening filename **" << endl <<endl;
    goto start;
    }

    while (!feof(fp))
    {
    }

    cout << endl << "The encrypted text in the file \'"<<filename2<<"\' is : "<< str<<endl<<endl;
    for (i=0; i<=len; ++i){
    }
    cout<<endl<<endl "The original text is: " <<endl <<endl;
    goto start;
    default;
    exit;
    }
    return (0);
    }
    default: cout << "Wrong input!\n";
    }
    cout << "You can press any key to continue or press 'q' to quit";
    again = getche();
    }while(again!='q');
    clrscr();
    cout << "Have a nice day!" << endl;
    getche();
    }

    Thanks!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    It would be helpfull if you could explain what the problem is.......

  3. #3
    Unregistered
    Guest
    Actually the problem is i not understand how to use the save and open function, their declaration, if - loop - while methods,its all mess in my head, i got made some research on book, but don't understand and don't know what is pf, fopen, feof.........

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    go here:

    http://www.stud.fim.ntnu.no/~oystesk/CPP/htm/ch16.htm

    and read the part about using files. The language is a simple as I've seen. You can also piece together a reasonable approach by searching this board.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    38
    You seem to need a better look at the fundamentals. I'd suggest going to this website's tutorials section.
    Show me a man who cannot bother to do little things, and I'll show you a man who cannot be trusted to do big things.

    -Bill Cosby

  6. #6
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Sam ?? right

    i PMed you a sample program using files to read/write the text to encode/decode. try reading that and implement it in your prog.


    i'll see your prog a little later as i have to go now, but there are other who'll help

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >void getString(void){cout << "The input is: "; fflush(stdin); gets(string);}
    I stopped reading right about here. Here's a tip, compile as you write and fix errors as they show up instead of waiting until the end and fixing 64 errors all in one chunk. It's much less frustrating that way. And please see just about any post of mine to find out why I stopped reading at that early line.

    -Prelude
    My best code is written with the delete key.

  8. #8
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Standard reply:
    AAAAH!!! NO CODE TAGS!!!
    http://www.cprogramming.com/cboard/s...threadid=13473

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overloading the assigment operator
    By Stonehambey in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2008, 01:06 PM
  2. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  3. Assigment
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 05-07-2004, 12:25 PM
  4. pointer assigment
    By spudtheimpaler in forum C Programming
    Replies: 8
    Last Post: 03-01-2004, 06:27 PM
  5. Overloading Assigment Operator. Freeing Memory.
    By Cheeze-It in forum C++ Programming
    Replies: 3
    Last Post: 11-30-2002, 05:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21