الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطا في الكود في using std

بدأه aimn mohamed في 27 مارس 2010 · 1 رد · 470 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

الملف بالمرفقات

Caesar.txt

تم تعديل هذه المشاركة بواسطة aimn mohamed في 27 مارس 2010 في 02:05

#2

لقد نسيت أن تضمن تعريف

#include <string.h> في أو الملف

البرنامج بعد التعديل

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

class CaesarCipher
{
      private:
              static const int KEY = 3 ;       // the key for caesar cipher

      public:
             string encryption (string str) 
             {
                  string str2 = "" ;

                  for (unsigned int i=0 ; i<str.length() ; i++)
                  {
                      int x = ( ( ((int)str - 65) + KEY ) % 26 ) + 65 ;
                      str2 += (char) x ;
                  }

                   return str2 ;
             }

             string decryption (string str) 
             {
                  string str2 = "" ;

                  for (unsigned int i=0 ; i<str.length() ; i++)
                  {
                      int x =  ( ( ((int)str - 65) - KEY ) % 26 )  ;
			          x = (x<0) ? (26- abs(x)) : x ;
			          str2 += (char)x+65 ;
                   }

                   return str2 ;
             }


};

int menu () ;

int main()
{
    CaesarCipher caesar ;

    bool state = true ;

    while (state)
    {
          switch ( menu() )
          {
                 case 1:
                      {
                      cout << "\nEnter The Plain Text : \n";
                      string str ;
                      char ch ;

                      while ( (ch=_getche()) != '\r'  )
                      {
                            if ( ch == ' ')
                               continue ;

                            str += ch ;
                      }

                      cout << "\nThe Plain Text  : " << str << endl;
                      cout << "\nThe Cipher Text : " << caesar.encryption(str) << endl;
                      break;
                      }

                 case 2:
                      {
                      cout << "\nEnter The Cipher Text : \n";
                      string str = ""; 
                      char ch ;

                      while ( (ch=_getche()) != '\r'  )
                      {
                            if ( ch == ' ')
                               continue ;

                            str += ch ;
                      }

                      cout << "\nThe Cipher Text  : " << str << endl;
                      cout << "\nThe Plain  Text  : " << caesar.decryption(str) << endl;

                      break;
                      }

                 case 3:
                      {
                        state = false;
                        cout << "Good Luck !\n";
                        break;
                      }

                 default:
                        cout << "Error Choice , Try Again !";
                        break;

          }
          _getch();
          system("cls");
    }

    cout << "\n\n";
    return 0;
}

int menu ()
{
    cout << "\t\t Caesar Cipher \n";
    cout << "\t\t-----------------\n";

    cout << "Encryption ................ [1]\n";
    cout << "Decryption ................ [2]\n";
    cout << "Exit Now   ................ [3]\n";
    cout << "\n \t >> " ;
    int choice ;

    cin >> choice ;

    return choice ;
}

ايضاً قمت باستبدال الgetch و الgetche بgetch_ و getche_

تم تعديل هذه المشاركة بواسطة motamayez في 27 مارس 2010 في 06:04

مصري في بلاد الفرنجة.

قريباً اقرأ مقالاتي على It-scoop

مواضيع مشابهة