佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 889|回复: 8

急需!!!关于C++的问题!!如何才能link function??

[复制链接]
发表于 30-11-2008 05:39 PM | 显示全部楼层
基本上我的program三个都Ok了...

只是不会link罢了...





回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 30-11-2008 05:17 PM | 显示全部楼层
这是我的Encryption Module的source code-

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

void encrypt(char plaintext_filename[], char ciphertext_filename[], char publicKey[])
{
FILE *plaintext, *ciphertext;
char ch;
int position;
position=0;
plaintext=fopen(plaintext_filename, "r");
ciphertext=fopen(ciphertext_filename, "w");
fseek(plaintext, 0, SEEK_SET);
do
{
  ch=fgetc(plaintext);
  if(ch!=EOF)
  {
   if(strcmp(publicKey,"")!=0)
   {
    ch=ch+publicKey[position];
    position++;
    if(position==strlen(publicKey))
    {
     position=0;
    }
   }
   cout << ch;
   fputc(ch, ciphertext);
  }
} while(ch!=EOF);
fclose(plaintext);
fclose(ciphertext);
}
void main()
{
char publicKey[20];
char plaintext_filename[20];
clrscr();
cout<< "Encryption Module"<<endl<<endl;
cout<< "--------------------------------------------------------------------------------"<<endl<<endl;
cout<< "Please Enter The File Name: ";
cin >> plaintext_filename;
cout << "\n\nPlease Enter The Public Key: ";
cin >> publicKey;
cout << "\n\nOriginal Message from "<< plaintext_filename << endl;
cout << "-------------" << endl;
encrypt("plain.txt", "cipher.txt", "");
cout << endl;
cout << "\n\nEncrypted Message to CIPHER.txt" << endl;
cout << "--------------" << endl;
encrypt("plain.txt", "cipher.txt", publicKey);
getch();
}
回复

使用道具 举报

 楼主| 发表于 30-11-2008 05:18 PM | 显示全部楼层
这是我的Decryption Module-

#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
void decrypt(char plaintext_filename[], char ciphertext_filename[], char publicKey[])
{
FILE *plaintext, *ciphertext;
char ch;
int position;
position=0;
ciphertext=fopen(ciphertext_filename, "r");
plaintext=fopen(plaintext_filename, "w");
fseek(ciphertext, 0, SEEK_SET);
do
{
  ch=fgetc(ciphertext);
  if(ch!=EOF)
  {
   if(strcmp(publicKey,"")!=0)
   {
    ch=ch-publicKey[position];
    position++;
    if(position==strlen(publicKey))
    {
     position=0;
    }
   }
   cout << ch;
   fputc(ch, plaintext);
  }
} while(ch!=EOF);
fclose(ciphertext);
fclose(plaintext);
}
void main()
{
char publicKey[20];
char ciphertext_filename[20];
clrscr();
cout<< "Decryption Module"<<endl<<endl;
cout<< "--------------------------------------------------------------------------------"<<endl<<endl;
cout<< "Please Enter The File Name: ";
cin >> ciphertext_filename;
cout << "\n\nPlease Enter The Public Key: ";
cin >> publicKey;
cout << "\n\nEncrypted Message from "<< ciphertext_filename << endl;
cout << "-------------" << endl;
decrypt("receive.txt", "cipher.txt", "");
cout << endl;
cout << "\n\nOriginal Message from PLAIN.txt" << endl;
cout << "--------------" << endl;
decrypt("receive.txt", "cipher.txt", publicKey);
getch();
}
回复

使用道具 举报

 楼主| 发表于 30-11-2008 05:11 PM | 显示全部楼层 |阅读模式
请教~有哪位学长能告诉我C++如何让function A的Interface link去function B/ C.
Example:


function A Interface

[1]: Encryption Module
[2]: Decryption Module
[3]: Exit the Program
Your Choice: (如果我选择1,然后就会link去Encryption Module)  


谢谢大家鼎立相救~P/S:能否告知了coding source后,在向我解释~

回复

使用道具 举报

发表于 30-11-2008 06:31 PM | 显示全部楼层
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int encrypt(char plaintext_filename[], char ciphertext_filename[], char publicKey[])
{
        FILE *plaintext, *ciphertext;
        char ch;
        int position;
       
        char publicKey[20];
        char plaintext_filename[20];

        clrscr();
        cout<< "Encryption Module"<<endl<<endl;
        cout<< "--------------------------------------------------------------------------------"<<endl<<endl;
        cout<< "Please Enter The File Name: ";
        cin >> plaintext_filename;
        cout << "\n\nPlease Enter The Public Key: ";
        cin >> publicKey;
        cout << "\n\nOriginal Message from "<< plaintext_filename << endl;
        cout << "-------------" << endl;
       
        //encrypt("plain.txt", "cipher.txt", "");
        position=0;
        plaintext=fopen(plaintext_filename, "r");
        ciphertext=fopen(ciphertext_filename, "w");
        fseek(plaintext, 0, SEEK_SET);
        do
        {
                ch=fgetc(plaintext);
                if(ch!=EOF)
                {
                        if(strcmp(publicKey,"")!=0)
                        {
                                ch=ch+publicKey[position];
                                position++;
                                if(position==strlen(publicKey))
                                {
                                        position=0;
                                }
                        }
                        cout << ch;
                        fputc(ch, ciphertext);
                }
        } while(ch!=EOF);
        fclose(plaintext);
        fclose(ciphertext);

        cout << endl;
        cout << "\n\nEncrypted Message to CIPHER.txt" << endl;
        cout << "--------------" << endl;
       
        //encrypt("plain.txt", "cipher.txt", publicKey);       
        position=0;
        plaintext=fopen(plaintext_filename, "r");
        ciphertext=fopen(ciphertext_filename, "w");
        fseek(plaintext, 0, SEEK_SET);
        do
        {
                ch=fgetc(plaintext);
                if(ch!=EOF)
                {
                        if(strcmp(publicKey,"")!=0)
                        {
                                ch=ch+publicKey[position];
                                position++;
                                if(position==strlen(publicKey))
                                {
                                        position=0;
                                }
                        }
                        cout << ch;
                        fputc(ch, ciphertext);
                }
        } while(ch!=EOF);
        fclose(plaintext);
        fclose(ciphertext);
}

int decrypt(char plaintext_filename[], char ciphertext_filename[], char publicKey[])
{
        FILE *plaintext, *ciphertext;
        char ch;
        int position;

        char publicKey[20];
        char ciphertext_filename[20];

        clrscr();
        cout<< "Decryption Module"<<endl<<endl;
        cout<< "--------------------------------------------------------------------------------"<<endl<<endl;
        cout<< "Please Enter The File Name: ";
        cin >> ciphertext_filename;
        cout << "\n\nPlease Enter The Public Key: ";
        cin >> publicKey;
        cout << "\n\nEncrypted Message from "<< ciphertext_filename<< endl;
        cout << "-------------" << endl;
       
        //decrypt("receive.txt", "cipher.txt", "");
        position=0;
        ciphertext=fopen(ciphertext_filename, "r");
        plaintext=fopen(plaintext_filename, "w");
        fseek(ciphertext, 0, SEEK_SET);
        do
        {
                ch=fgetc(ciphertext);
                if(ch!=EOF)
                {
                        if(strcmp(publicKey,"")!=0)
                        {
                                ch=ch-publicKey[position];

                                position++;
                                if(position==strlen(publicKey))
                                {
                                        position=0;
                                }
                        }
                        cout << ch;
                        fputc(ch, plaintext);
                }
        } while(ch!=EOF);
        fclose(ciphertext);
        fclose(plaintext);
        }

        cout << endl;
        cout << "\n\nOriginal Message from PLAIN.txt" << endl;
        cout << "--------------" << endl;

        //decrypt("receive.txt", "cipher.txt", publicKey)       
        position=0;
        ciphertext=fopen(ciphertext_filename, "r");
        plaintext=fopen(plaintext_filename, "w");
        fseek(ciphertext, 0, SEEK_SET);
        do
        {
                ch=fgetc(ciphertext);
                if(ch!=EOF)
                {
                        if(strcmp(publicKey,"")!=0)
                        {
                                ch=ch-publicKey[position];

                                position++;
                                if(position==strlen(publicKey))
                                {
                                        position=0;
                                }
                        }
                        cout << ch;
                        fputc(ch, plaintext);
                }
        } while(ch!=EOF);
        fclose(ciphertext);
        fclose(plaintext);
}

void main()
{
        int answer;

                boolean(false)
                {

                clrscr();
                cout<<"\t\tSure Secure Symmetric Security System\t\t\t"<< endl<< endl;
                cout<<"\t\t\t\tMain Menu\t\t\t"<< endl<< endl;
                cout<<"=============================================================================="<< endl<< endl;
                cout<<"\t\t\t[1] Encrypt File\t\t\t"<< endl;
                cout<<"\t\t\t[2] Decrypt File\t\t\t"<< endl;
                cout<<"\t\t\t[3] Exit the Programme"<< endl;
                cout<<"\t\t\tYour Choice: ";

                cin >> answer;

                if (answer==1)
                {
                        cout<< "\n\t\t\tLoading to Encrytion Module....."<< endl;
                        encrypt();
                }
                else
                if (answer==2)
                {
                        cout<< "\n\t\t\tLoading to Decrytion Module....."<< endl;
                        decrypt();
                }
                else
                if (answer==3)
                {
                        cout<< "\n\t\t\tExiting the programme, GoodBye!"<< endl;
                        exit();

                }
                else
                {
                        cout<< "\n\t\t\tError Input, Please Try Again!" << endl;
                        //use boolean here, i forgot how to write already, the true false one, i simply write only.
                }
                }



                getch();

}
回复

使用道具 举报

 楼主| 发表于 30-11-2008 05:14 PM | 显示全部楼层
这是我的Interface的source code-


#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
int answer;
  clrscr();
  cout<<"\t\tSure Secure Symmetric Security System\t\t\t"<< endl<< endl;
  cout<<"\t\t\t\tMain Menu\t\t\t"<< endl<< endl;
  cout<<"=============================================================================="<< endl<< endl;
  cout<<"\t\t\t[1] Encrypt File\t\t\t"<< endl;
  cout<<"\t\t\t[2] Decrypt File\t\t\t"<< endl;
  cout<<"\t\t\t[3] Exit the Programme"<< endl;
  cout<<"\t\t\tYour Choice: ";
  cin >> answer;
  if (answer==1)
  {
   cout<< "\n\t\t\tLoading to Encrytion Module....."<< endl;
  }
  else
  if (answer==2)
  {
   cout<< "\n\t\t\tLoading to Decrytion Module....."<< endl;
  }
  else
  if (answer==3)
  {
   cout<< "\n\t\t\tExiting the programme, GoodBye!"<< endl;
  }
  else
  {
   cout<< "\n\t\t\tError Input, Please Try Again!" << endl;
  }
  getch();
}
回复

使用道具 举报

Follow Us
发表于 1-12-2008 12:53 PM | 显示全部楼层
弄成object oriented一点。。把他们包成DLL/class
省你时间,省我口水
回复

使用道具 举报

发表于 5-12-2008 12:14 AM | 显示全部楼层
原帖由 yeenfei 于 1-12-2008 12:53 PM 发表
弄成object oriented一点。。把他们包成DLL/class
省你时间,省我口水

我也知道,可是要present的不是我啊,是楼主。楼主还没学oop的。
回复

使用道具 举报


ADVERTISEMENT

发表于 5-12-2008 07:32 AM | 显示全部楼层
这是assignment吧。。。
楼主的问题是在所谓的interface没有叫到(new)XXXXXXXXXXclass.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 10-2-2025 08:54 PM , Processed in 0.121856 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表