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

زخااارف لل ++ C

بدأه توليـــــن في 6 يونيو 2010 · 1 رد · 570 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

اتمنى ان تتحفوني ببعض الزخاااارف التي استطيع ان استخدمها في لغة ++c

لتظهر لي في الشااشة

1
#2

قم بطباعة الأسكي كود لما بعد 128 وستجد بعض الرموز يمكنك ان تستخدمها..

مثال قديم وجدته من 2006 ، يعمل على بورلاند :

404669_l.jpg

404670_l.jpg

// Hospital Software  ( Beta Version ) 
// Coded By : Romansy ( romansy_766@hotmail.com) 
// FeedBack : http://www.enashir.com/blogs/romansy 
// Date  : 9/8/2006 
// End   : 13/8/2006  ....  Don't be Amazed :) every day i worked about 1 hours 
// Total Of Work : 4 Hours .... 
// Final Release : Coming Soon .. 
// The Program Use the Linked List Technique . But Not File Saved is available . 

#include <iostream.h> 
#include <conio.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <dos.h> 
#include <Stdio.h> 
#include <windows.h> 

struct node 
{ 
    int num ; 
   char name[10]; 
   int tel ; 
   int b ; 
   node* next ; 
}; 

class Person 
{ 
    private: 
       node* first ; 
      node* Rechead ; 
   public: 
       Person() : first(NULL) , Rechead(NULL) 
      {        } 
      ~Person() 
      {    } 

      void AddPerson (void) ; 
      void DeletePerson (void); 
      void SearchPerson (void); 
      void DisplayPerson (void); 
      //int CountPerson (void); 
      void SetData (node* ); 
      void RecycleBin (node* ); 
      void DisplayRecycle (void); 
      //int CountAfterDelete(void); 
      static int count = 0; 
}; 

void Person :: AddPerson (void) 
{ 
    node* newperson = new node ; 

    if (first == NULL) 
   { 
       newperson->next = first ; 
      first = newperson ; 
   } 
   else 
   { 
       node* current = first ; 
      while ( current->next != NULL) 
          current = current->next ; 

      current->next = newperson ; 
      newperson->next = NULL ; 
   } 
   // Now Set Data to new person 
   SetData(newperson); 
} 

void Person :: DisplayPerson (void) 
{ 
    node* current = first ; 
   int space = 1; 

   while (current != NULL) 
   { 
       if (space % 4 == 0) 
      { 
          cout << "\nPress Any Key to clear screen and Print the other"; 
         getch(); 
         clrscr(); 
      } 
       cout << "_______________\n\n"; 
      cout << "Number º " << current->num   << endl; 
      cout << "Name   º " << current->name  << endl; 
      cout << "Phone  º " << current->tel   << "\n" ; 
      cout << "Blood  º " ; 
      if ( current->b == 1) 
          cout << "A+\n" ; 
      else if (current->b == 2) 
          cout << "O+\n" ; 
      else if (current->b == 3) 
          cout << "O-\n"; 
      else 
          cout << "Unknown\n"; 
      cout << "_______________\n"; 

      space++ ; 
      current = current->next ; 
   } 

} 

/* 
int Person :: CountPerson (void) 
{ 
    node* current = first ; 
   int co = 1; 

   if ( first->next == NULL) 
       return co ; 

      else 
      { 
   while (current != NULL ) 
   { 
          co++; 
         if ( !current->num == co) 
              co = current->num ; 
         //count = current->num ; 
          current = current->next ; 
   } 



       return co; 
      } 
} 

*/ 

void Person :: SetData (node* per) 
{ 
    per->num = ++count ; 
    cout << "patient number [" << per->num << "] : \n" ; 
   cout << "Enter name : "  ; cin >> per->name ; 
   cout << "Enter tel  : "  ; cin >> per->tel ; 
   cout << "Enter Blood form :  " ; 
   cout << "(1)- A+ \n\t\t    (2)- O+\n\t\t    (3)- O- \n" ; 
   cout << "Enter number  : " ; cin >> per->b ; 

} 


void Person :: SearchPerson (void) 
{ 
    int choice; 

    cout << "\n\n\t Search By :  (1) - Number \n"  ; 
   cout << "                      (2) - Name   \n" ; 
   cout << " \nEnter Your Choice >> " ; 
   cin >> choice; 

   if (choice == 1) 
   { 
       bool flag = false ; 
       node* current = first ; 
      cout << "\n Enter the number of patient : " ; 
      int number ; 
      cin >> number ; 

      while (current != NULL) 
      { 
          if (current->num == number) 
         { 
             cout << "\nFound the patient .... \n" ; 
            cout << "\nName  : " << current->name << endl; 
            cout << "Tel   : " << current->tel  << endl; 
            cout << "Blood : " << current->b    << endl; 
            flag = true ; 
         } 
         current = current->next ; 
      } 

      if (flag == false) 
          cout << "Can not Found patient ... \n" ; 
   } 

   else if (choice == 2) 
   { 
       bool flag = false ; 
       node* current = first ; 
      cout << "\n Enter the Name of patient : " ; 
      char name[10] ; 
      cin >> name ; 

      while (current != NULL) 
      { 
          if (current->name == name) 
         { 
             cout << "\nFound the patient .... \n" ; 
            cout << "Name  : " << current->name << endl; 
            cout << "Tel   : " << current->tel  << endl; 
            cout << "Blood : " << current->b    << endl; 
            flag = true ; 
         } 
         current = current->next ; 
      } 

      if (flag == false) 
          cout << "Can not Found patient ... \n" ; 
   } 
   else 
       cout << "Error .... \n"; 

} 



void Person :: DeletePerson (void) 
{ 
    int choice; 
   bool flag = false ; 
    cout << "\n\n\t Delete By :  (1) - Number \n"  ; 
   cout << "                      (2) - Name   \n" ; 
   cout << " \nEnter Your Choice >> " ; 
   cin >> choice; 

   if (choice == 1) 
   { 
       node* tmp = first; 
       node* current = first ; 
      cout << "\n Enter the number of patient : " ; 
      int number ; 
      cin >> number ; 

      while (current != NULL) 
      { 
          if (current->num == number) 
         { 
             flag = true ; 
             if ( current == first) 
            { 
                first = current->next ; 
               RecycleBin(current); 
               delete current ; 
               break; 
            } 
             else 
            { 
                tmp->next = current->next; 
               RecycleBin(current); 
               delete current ; 

               break; 
            } 
         } 
         tmp = current ; 
         current = current->next ; 
      } 

      if (flag == false) 
          cout << "\nCan not Found the patient \n" ; 
   } 
   else 
       cout << "Error \n" ; 
} 

void Person :: RecycleBin (node* per) 
{ 
    node* myrec = new node ; 
   node* current = Rechead ; 

   if (Rechead == NULL) 
   { 
       myrec->next = Rechead ; 
      Rechead = myrec ; 
   } 
   else 
   { 
       while ( current->next != NULL) 
          current = current->next ; 
      current->next = myrec ; 
      myrec->next = NULL ; 
   } 
   myrec->num = per->num ; 
   strcpy(myrec->name,per->name); 
   myrec->tel = per->tel; 
   myrec->b = per->b; 
} 


void Person :: DisplayRecycle (void) 
{ 
    if (Rechead == NULL) 
   { 
       cout << "\n\n\t" ; 
       textcolor(11); 
       cprintf("Recycle Bin Is Empty now"); 
      textcolor(15); 
   } 
   else 
   { 
       cout << "\t"; 
       cprintf("  Number          Name "); 
      cout << "\n\n"; 
       node* current = Rechead; 
      while (current != NULL) 
      { 
          cout << "\t   " << current->num << "\t           " << current->name << endl << endl; 
         current = current->next ; 
      } 
   } 
} 


//////////////////////////////////////// 
void Border (void); 
void MiniBorder (void) ; 
void Download (void) ; 
void PrintMenu (Person) ; 
void InitialWindow (void); 
////////////////////////////////////// 


int main (void) 
{ 
    InitialWindow(); 
   Person person ; 
   PrintMenu(person); 

   return 0; 
} 


void Border(void) 
{ 
    gotoxy(2,2); 
   printf("É"); 

   for (int i=0 ; i<36 ; i++) 
       printf("Í"); 

   printf("»"); 

   for (int i=3 ; i<=23 ; i++) 
   { 
       gotoxy(2,i); 
      printf("º"); 
      gotoxy(39,i); 
      printf("º"); 
   } 

   gotoxy(2,24); 
   printf("È"); 

   for (int i=0 ; i<36 ; i++) 
       printf("Í"); 

   printf("¼"); 

   textcolor(14); 
   gotoxy(5,25); 
   cprintf("Press ESC to Exit && Good Luck :)") ; 
   textcolor(7); 
} 


void MiniBorder (void) 
{ 
      gotoxy(14,11); 
     printf("É"); 

   for (int i=0 ; i<12 ; i++) 
       printf("Í"); 

   printf("»"); 

   gotoxy(14,12); 
   printf("º"); 
   gotoxy(27,12); 
   printf("º"); 
   gotoxy(14,13); 
   printf("È"); 

   for (int i=0 ; i<12 ; i++) 
         printf("Í"); 

   printf("¼"); 

} 

void Download (void) 
{ 
    gotoxy(15,12); 
    for (int i=0 ; i<12 ; i++) 
   { 
         textcolor(14); 
      cprintf("Û"); 
      sleep(1); 
   } 
} 

void InitialWindow (void) 
{ 
    gotoxy(13,1); 
   system("date /t"); 
   textmode(C40); 
   _setcursortype(0); 
   Border(); 
   MiniBorder(); 
   Download(); 
   clrscr(); 
   gotoxy(13,1); 
   system("date /t"); 
   Border(); 
} 

void PrintMenu (Person person) 
{ 
    char menu[7][25] = { "Add New patients" , "Delete  patients" , "Search  patients", "Display patients","The Recycle Bins","About Programmer", "Exit From System" }; 
   int current = 0; 
   char ch; 

   do 
   { 

      // Print All Menu in white color 
      current = 0; 
       textcolor(7); 
       textbackground(0); 
       clrscr(); 
      Border(); 
      gotoxy(13,1); 
       system("date /t"); 

       for (int i=0 ; i<7 ; i++) 
       { 
           gotoxy(13,9+i); 
          cprintf("%s",menu) ; 

       } 

      // make first element is current (change its color) 

       gotoxy(13,9); 
       textcolor(0); 
       textbackground(7); 
       cprintf("%s",menu[current]); 

       do 
       { 
          // if user press any key , change color of first elment 
         // or the current element 

            ch = getch(); 
          int kk ; 

         for (int i=0 ; i<7 ; i++) 
             if (current == i) 
                kk = 9+i ; 

          gotoxy(13,kk); 
          textcolor(7); 
          textbackground(0); 
          cprintf("%s",menu[current]); 

          if ( ch == 72)             // press UP 
          { 

              if ( current==1 || current == 2 || current == 3 || current == 4 || current == 5 || current == 6) 
                 current-- ; 
              else 
                 current = 6 ; 
          } 

          else if ( ch == 80)      // press Down 
          { 
              if (current == 0 || current == 1 || current == 2 || current == 3 || current == 4 || current == 5) 
                 current++; 
             else 
                 current = 0; 
          } 

          textcolor(0); 
          textbackground(7); 
          int k ; 

         for (int i=0 ; i<7 ; i++) 
             if (current == i) 
                k = 9+i ; 

          gotoxy(13,k); 
          cprintf("%s",menu[current]); 

       } while ( (ch != 13) && (ch != 27) );    // if press ENTER or ESC break 

    textcolor(7); 
    textbackground(0); 



    if ( ch == 13) 
    { 
            if (current == 0) 
         { 
            char ch ; 
            do 
            { 
                clrscr(); 
                cout << "\t Add New patient \n" ; 
cout << "\t\t ============\n\n\n" ;
                person.AddPerson(); 
               cout << "\n\n Enter another patient (Y|N) ? " ; 
               ch = getch(); 
            } while (ch == 'y' || ch == 'Y' ) ; 

         } 

         else if (current == 1) 
         { 
             char ch ; 
            do 
            { 
                clrscr(); 
               cout << "\t Delete patient \n" ; 
cout << "\t\t ============\n\n\n" ;
               person.DeletePerson(); 
               cout << "\n\n Delete Another patient (Y|N) ? " ; 
                ch = getch(); 
            }while (ch == 'y' || ch == 'Y') ; 
         } 

         else if (current == 2) 
         { 
             char ch ; 
             do 
            { 
                clrscr(); 
                 cout << "\t Search On patient \n" ; 
                 cout << "\t\t ============\n\n\n" ;
                person.SearchPerson(); 
               cout << "\n\n Search on another patient (Y|N) ? " ; 
               ch = getch(); 
            } while (ch == 'y' || ch == 'Y' ) ; 

         } 

         else if (current == 3) 
         { 
              clrscr(); 
              person.DisplayPerson(); 
              getch(); 
         } 
         else if (current == 4) 
         { 
               clrscr();     
               cout << "\t  The Recycle Bin \n" ; 
cout << "\t\t ============\n\n\n" ;
              person.DisplayRecycle(); 
              getch(); 
         } 

         else if (current == 5) 
         { 

                 clrscr(); 

                 cout << "\t\t     About Programmer \n" ; 
                 cout << "\t\t ============\n\n\n" ; 
               textmode(C80); 
               textcolor(14); 
                    cout << "Wajdy Essam ,known As Romansy :-)..\nhe is a Student of Computer Sceince and he finish now\ 
the Second year on\nthe Collage in Neelin University\n\nNow he intresting in Programming in c++ and\ 
the Object Orinted Programming (OOP)\nhe like c++ very much and impelemntation\ 
any Course in this Language such as\nData Structure , Numerical Computation .. etc\ 
\nhe now Learn The Design and Develpment of web .... \ 
\n\n\nI will be Very happy when i see your comments about my programm :)\ 
\nyou can meet me at my Email - romansy_766@hotmial.com , \nor my blogs :\ 
http://www.enashir.com/blogs/romansy\n\n"; 
cprintf("Feel It :)"); 
               getch(); 
               textmode(C40); 
               textcolor(7); 
         } 

         else if (current == 6) 
         { 
             clrscr(); 
            char ch ; 
            cout << "\n\n Do you Want to Exit (Y|N) ?" ; 
            ch = getch (); 
            if ( ch == 'y' || ch == 'Y') 
                FatalAppExit(0 , "Thanks For use our system :)"); 
         } 

    } 

    }while (ch != 27) ; 

}

وهذا مثال من أخي Sudanix باستخدام windows.h :

404737_l.jpg

/************** Expression Evaluator v1.0  ************************ 
*************** Athour: Ahmad Essam.******************************* 
************* Date: 2/11/2006 , 8:42 PM *************************** 
********************************************************************/ 

#include <iostream> 
#include <windows.h> 
using namespace std; 

/*class Node 
{ 
private: 
    Node *Next; 
    char symbol; 

public: 
    Node(char c):symbol(c),Next(NULL){} 
    void SetSymbol(char c){symbol=c;} 
    void SetNext(Node *p){Next=p;} 

    char GetSymbol()const{return symbol;} 
    Node * GetNext()const {return Next;} 
}; 


class LinkedStack 
{ 
private: 
    Node *Head; 

public: 
    LinkedStack():Head(NULL){} 
    ~LinkedStack(){Destroy();} 

    void Push(char); 
    bool IsEmpty(); 
    char Pop(); 
    void Destroy(); 
    char Get()const; 
}; 

void LinkedStack::Push(char a) 
{ 
    Node *New=new Node(a); 
    New->SetNext(Head); 
    Head=New; 
} 

bool LinkedStack::IsEmpty() 
{ 
    if(Head == NULL) 
        return true; 
    return false; 
} 


char LinkedStack::Pop() 
{ 
    if(IsEmpty()) 
    { 
        cout<<"List Is Empty\n"; 
        exit(1); 
    } 

    char c=Head->GetSymbol(); 
    Node *del=Head; 
    Head=Head->GetNext(); 
    delete del; 
    return c; 
} 


void LinkedStack::Destroy()     
{ 
    Node *del; 
    for(Node *Cur=Head;Cur != NULL;) 
    { 
        del=Cur; 
        Cur=Cur->GetNext(); 
        delete del; 
    } 
} 



char LinkedStack::Get() const 
{ 
    return Head->GetSymbol(); 
} 
*/ 

/********************************************************************************/ 

// Stack Declaration and definition. 
class Stack 
{ 
private: 
    enum {SIZE=20,MIN=-1}; 
    char *pArray; 
    int itsTop; 

public: 
    //constructor and destructor 
    Stack(int s=SIZE); 
    ~Stack(); 

    // operation on the stack 
    void Push(char); 
    char Pop(); 
    bool IsFull(); 
    bool IsEmpty(); 
    char Get()const{return pArray[itsTop];} 
}; 

Stack::Stack(int s): 
itsTop(MIN) 
{ 
    pArray=new char; 
} 

Stack::~Stack() 
{ 
    delete [] pArray; 
    pArray=0; 
} 

bool Stack::IsFull() 
{ 
    if(itsTop == SIZE -1) 
        return true; 
    return false; 
} 

bool Stack::IsEmpty() 
{ 
    if(itsTop == MIN) 
        return true; 
    return false; 
} 


void Stack::Push(char c) 
{ 
    if(IsFull()) 
    { 
        cout<<"Stack is Full\n"; 
        exit(1); 
    } 

    pArray[++itsTop]=c; 
} 

char Stack::Pop() 
{ 
    if(IsEmpty()) 
    { 
        cout<<"Stack is Empty\n"; 
        exit(1); 
    } 

    return pArray[itsTop--]; 
} 


/*******************************************************************/ 

// Enumorator and Function Prototype: 
enum HighOrLow {LOW,HIGH}; 

//return     name                  parameter 
HighOrLow Precedence         (const char op,const char top); 
void      Menu               (); 
bool      ItsOperator        (char a,char op[]); 
bool      ItsNumber          (char a); 
int       EvaluatePostfix    (const char postfix[],char op[]); 
int       Exp                (int x,int y);   
int       Calculate          (int x,int y,char op);  
void      InfixToPosfix      (char infix[],char postfix[],char op[]); 
void      ShowPostfix        (char postfix[]); 
void      ShowEvaluate       (int r); 
void      ClearScreen        (); 
bool      CheckExpression    (char infix[],char op[]); 
void      SetColor           (int);  

/*******************************************************************/ 

// ** Function Name: main 
// ** parameter    : N/A 
// ** return type  : int 
// ** Explain: 
// the main function that call other functions 
int main() 
{ 
    const int SIZE = 20; 
    char infix[SIZE]; 
    char op[]={'^','*','/','+','-','(',')'}; 
    char c; 
    do 
    { 
        ClearScreen();  // clear the screen  
        Menu(); // call Menu() 

        SetColor(31); 

        fflush(stdin); 

        cin.get(infix,SIZE); 

        char *postfix=new char[strlen(infix) + 1];  // +1 for '\0' char 
        SetColor(7); 
        if(!CheckExpression(infix,op)) 
        { 
            cout<<"So the Expression is Not Vaild,,pleas try again: \n"; 
            cout<<"\nEnter Another Infix Expression [y/n]:  "; 
            cin>>c; 
            if( c == 'n' || c == 'N') break; 
            delete [] postfix; 
            continue; 
        } 

        InfixToPosfix(infix,postfix,op); // call InfixToPosfix() 

        cout<<"\n\n"; 

        ShowPostfix(postfix);  // call ShowPostfix() 
        int r=EvaluatePostfix(postfix,op);  // call EvaluatePostfix() 
        ShowEvaluate(r);    // call ShowEvaluate() 
        cout<<endl;  
        delete [] postfix; 

        cout<<"\nEnter Another Infix Expression [y/n]:  "; 
        cin>>c; 

    }while(c !='n' &&  c!='N'); 

    return 0; 
} 

/*******************************************************************/ 

void SetColor(int x) 
{ 
    //gets std handle 
    HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);  
    //Sets Console Text Attribute HCon color. 
    SetConsoleTextAttribute(hCon,x); 
} 


/******************************************************************/ 
bool CheckExpression(char infix[],char op[]) 
{ 
    Stack Operator; 
    for(int i=0;i<strlen(infix);i++) 
    { 
        if( ItsNumber(infix) ); 

        else if (ItsOperator(infix,op) ) 
        { 
            if( infix == '(') 
                Operator.Push(infix); 

            else if( infix == ')') 
            { 
                if(Operator.IsEmpty()) 
                { 
                    cout<<"\nError: exrta ')' character !\n"; 
                    return false; 
                } 
                Operator.Pop(); 
            } 
        } 

        else 
        { 
            // Error:its not an opeartor and not a number 
            cout<<"\nError: "<<infix<<" is an illegal character\n"; 
            return false; 
        } 
    } 

    if (!Operator.IsEmpty()) 
    { 
        cout<<"\nError: extra '(' character  has no closing ')' !\n"; 
        return false; 
    } 

    return true; 
} 




/******************************************************************/ 
void ShowPostfix(char postfix[]) 
{ 
    SetColor(11); 
    cout<<"\n\t\tThe Postfix Expression: \t>> "; 
    SetColor(31); 
    cout<<postfix<<endl; 
    SetColor(7); 
} 


/*******************************************************************/ 

void ShowEvaluate(int r) 
{ 
    SetColor(11); 
    cout<<"\n\t\tthe Expression Evaluation: \t>> "; 
    SetColor(31); 
    cout<<r<<endl; 
    SetColor(7); 
} 


/*******************************************************************/ 

// ** Function Name: Precedence 
// ** parameter    : current operator, top of stack 
// ** return type  : high,low 
// ** Explain: 
// this function to determined the precedence of operators. 
// if the opeartor in the stack hava high precedence than in the 
// infix array it return HIGH 
// else LOW  

HighOrLow Precedence (const char op,const char top) 
{ 
    switch ( top ) 
    { 
        case '(': 
            return LOW;     

        case '^': 
            if(op == '(') 
                return LOW; 
            break; 

        case '*': 
            if(op == '^' || op == '(' ) 
                return LOW; 
            break; 

        case '/': 
            if(op == '^' || op == '(' ) 
                return LOW; 
            break; 

        case '+': 
            if (op== '^' || op == '*' || op =='/' || op == '(' ) 
                return LOW; 
            break; 

        case '-': 
            if(op == '^' || op == '*' || op == '/' || op =='(' ) 
                return LOW; 
            break; 

        //default: 
            //cout<<"catch error !!\n"; 
    } 

    return HIGH; 
} 

/*******************************************************************/ 

// ** Function Name: Menu 
// ** parameter    : N/A 
// ** return type  : void 
// ** Explain: 
// this function draw the main menu. 

void Menu() 
{ 
    SetColor(14); 
    cout<<"\n\t\t ---------------------------------------"; 
    cout<<"\n\t\t|                                       |"; 
    cout<<"\n\t\t|       Expression Evaluater v1.0       |"; 
    cout<<"\n\t\t|                                       |"; 
    cout<<"\n\t\t|       "; 
    SetColor(12); 
    cout<<" Coded by: Ahmad Essam"; 
    SetColor(14); 
    cout<<"          |"; 
    cout<<"\n\t\t ---------------------------------------"; 

    SetColor(10);  
    cout<<"\n\n\t\tEnter The Infix Expression: \n\n\t\t\t>> "; 

    // return Text Attribute to defualt 
    SetColor(7);  
} 
/*******************************************************************/ 

// ** Function Name: ItsOperator 
// ** parameter    : current char ,op[]={'^','*','/','+','-','(',')'}; 
// ** return type  : bool 
// ** Explain: 
// check the character, if it equal to any element of op:return true 
// if not equal return false (its not an operator) 

bool ItsOperator(char a,char op[]) 
{ 
    for(int i=0;i<strlen(op);i++) 
    { 
        if(a == op) 
            return true; 
    } 

    return false; 
} 

/*******************************************************************/ 

// ** Function Name: ItsNumber 
// ** parameter    : current char. 
// ** return type  : bool 
// ** Explain: 
// check the character, if it equal to any number [0-9]:return true 
// if not equal return false (its not a number) 

bool ItsNumber(char a) 
{ 
    int x=(int)a; 
    x-=48;   // convert from ASCII Code to decimal number 
    for(char i=0;i<10;i++) 
    { 
        if(x == i) 
            return true; 
    } 
    return false; 
} 

/*******************************************************************/ 


// ** Function Name: InfixToPosfix 
// ** parameter    : infix array,postfix array,op[]={'^','*','/','+','-','(',')'}; 
// ** return type  : void 
// ** Explain: 
// Convert infix expression to postfix expression> 
/* ** Algorithm: 

1- scan the infix array from the ****. 
2- if the character is : 
    a- an operand copy it to the posfix array. go to step 1 

    b- an operator : 
        I- if the stack is empty push the opeartor . go to step 1 
       II- if its not, copmare the precedence of the top of stack 
        with the current opeartor >> 
        # if the top of stack is high precedence than the current 
        operator, then:pop stack to the postfix array 
        (untill its empty or its top has low precedence than  
        the current operator), and push the current operator 
        .go to step 1 

        # else:push the operator.go to step 1 

    c- '\0' : pop the stack until its empty 
    . 
    d-: anything else: show an error msg and exit. 
*/ 
void InfixToPosfix(char infix[],char postfix[],char op[]) 
{ 
    Stack stk; 
    for(int i=0,j=0;i<strlen(infix) && infix !='\0' ;i++ ) 
    { 
        if(ItsNumber(infix)) 
        { 
            // its Number. 
            postfix[j++]=infix; 
        } 

        else if(ItsOperator(infix,op)) 
        { 
            // its operator 

            if( infix == ')') 
            { 
                while( stk.Get() != '(' ) 
                { 
                    postfix[j++]=stk.Pop(); 
                } 
                stk.Pop(); 
                continue; 
            } 

            if((stk.IsEmpty()) == false) 
            { 

                // if top is high prec then op  >> pop top 
                while( (Precedence(infix,stk.Get()) == HIGH) && !(stk.IsEmpty()) ) 
                { 
                    postfix[j++]=stk.Pop(); 
                } 

                stk.Push(infix); 
            } 

            // its empty 
            else 
            { 
                stk.Push(infix); 
            } 
        } 
    } 

    while( !(stk.IsEmpty())) 
    { 
        postfix[j++]=stk.Pop(); 
    } 

    postfix[j]='\0'; 

} 

/*******************************************************************/ 

// ** Function Name: Evaluate 
// ** parameter    : postfix array, op[]={'^','*','/','+','-',')','('}; 
// ** return type  : int (result) 
// ** Explain: 
// this function evaluate the postfix expression. 
// ** Algorithm: 
// 1) while postfix != '\0' do 
//    if char is an operand: 
//       push it in the stack but after convert it to integer. 

//    else if char is an operator: 
//      pop the last two operand 
//      and perform the operation (operator) on the operand. 
//      push the result in the stack. go to 1 

// 2) pop the stack (the result). 

int EvaluatePostfix(const char postfix[],char op[]) 
{ 
    int x=0; 
    Stack s; 
    for(int i=0; postfix != '\0' ; i++) 
    { 
        if( ItsNumber(postfix) ) 
        { 
            s.Push(postfix -'0'); 
        } 

        else if (ItsOperator(postfix,op)) 
        { 
            x=Calculate(s.Pop(),s.Pop(),postfix); 
            s.Push(x); 
        } 

        else 
        { 
            // Error:its not an opeartor and not a number 
            cout<<"Error: "<<postfix<<" is an illegal character\n"; 
        } 
    } 

    return s.Pop(); 

} 


/*******************************************************************/ 

// ** Function Name: Calculate 
// ** parameter    : integer,integer,the operator. 
// ** return type  : int (result) 
// ** Explain: 
// perform the operator on the two integer, and return the result 

int Calculate(int x,int y,char c) 
{ 
    switch(c) 
    { 
    case '+': 
        return x+y; 
    case '-': 
        return x-y; 
    case '*': 
        return x*y; 
    case '/': 
        return x/y; 
    case '^': 
        return (Exp(x,y)); 
    } 
    return 0;  
} 

/*******************************************************************/ 

// ** Function Name: Exp 
// ** parameter    : integer,integer. 
// ** return type  : int (result) 
// ** Explain: 
// perform the x ^ y, and return the result 

int Exp(int x,int y) 
{ 
    int sum=1; 
    for(int i=1;i<=y;i++) 
        sum*=x; 

    return sum; 
} 

/***************************************************************/ 

void ClearScreen()  
{   
    COORD coordScreen = { 0, 0 };  
    DWORD cCharsWritten;  
    CONSOLE_SCREEN_BUFFER_INFO csbi;   
    DWORD dwConSize;  
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);  
    GetConsoleScreenBufferInfo(hConsole, &csbi);  
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;  
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);  
    GetConsoleScreenBufferInfo(hConsole, &csbi);  
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);  
    SetConsoleCursorPosition(hConsole, coordScreen);  
}  


/************************************************************/ 


// EOF

بالتوفيق،

1

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science