تبلیغات :
ماهان سرور
آکوستیک ، فوم شانه تخم مرغی ، پنل صداگیر ، یونولیت
دستگاه جوجه کشی حرفه ای
فروش آنلاین لباس کودک
خرید فالوور ایرانی
خرید فالوور اینستاگرام
خرید ممبر تلگرام

[ + افزودن آگهی متنی جدید ]




نمايش نتايج 1 به 2 از 2

نام تاپيک: راهنمایی در ساخت یک برنامه لطفا سریع کمک کنید عجله دارم مرسی

  1. #1
    اگه نباشه جاش خالی می مونه
    تاريخ عضويت
    Sep 2011
    محل سكونت
    اهواز
    پست ها
    259

    پيش فرض راهنمایی در ساخت یک برنامه لطفا سریع کمک کنید عجله دارم مرسی

    سلام دوستان
    استاد ما 2تا کد داده که باهاشون یک برنامه میشه نوشت لطفا اگه میشه کمکم کنید.
    خروجی باید این چیزهارو داشته باشه
    1-print queue
    2-add to queue
    3-remove from queue
    4-retrieve from
    5-exit
    برنامه استک داره وقتی استک پر میشه باید با شماره سه از استک خالی کرد کسی اگر میدونه قسمت 4 چی میکنه به منم یه توضیح بده ممنونش میشم.
    استاد به ما این دو کد رو برای ساخت برنامه داده.
    کد اول:

    #include "iostream.h"
    #include "conio.h"
    #include "stdlib.h"
    #define SIZE 5
    class queue{
    public:
    queue();
    int empty();
    void addQ(int, int &);
    void retrieve(int &, int &);
    void qremove(int &, int &);
    void print();
    private:
    int items[SIZE];
    int front;
    int rear;
    };
    //******************
    queue::queue()
    {
    front = rear = 0;
    }
    //******************
    int queue::empty()
    {
    if(rear == front)
    return 1;
    return 0;
    }
    //******************
    void queue::addQ(int x, int &overflow)
    {
    int newRear;
    newRear = (rear + 1) % SIZE;
    if(front == newRear)
    overflow = 1;
    else
    {
    overflow = 0;
    items[rear] = x;
    rear = newRear;
    }
    }
    //******************
    void queue::retrieve(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front];
    }
    }
    //*******************
    void queue::qremove(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front];
    front = (front + 1) % SIZE;
    }
    }
    //*******************
    void queue::print()
    {
    int i;
    if(empty())
    cout << "Queue is empty.";
    else
    {
    if(front < rear)
    for(i = front; i < rear; i ++)
    cout << items[i] << " ";
    else if (front > rear)
    {
    for(i = front; i < SIZE ; i ++)
    cout << items[i] << " ";
    for(i = 0; i < rear; i ++)
    cout << items[i] << " ";
    }
    }
    cout << "\nPress a key to continue.";
    getch();
    }
    //*******************
    int menu();
    int main()
    {
    queue q;
    int x, overflow, underflow;
    while(1)
    {
    clrscr();
    switch(menu())
    {
    case 1:
    q.print();
    break;
    case 2:
    cout << "Enter a value to enter q:";
    cin >> x;
    q.addQ(x, overflow);
    if(overflow)
    {
    cout << "queue is full. press a key to continue.";
    getch();
    }
    break;
    case 3:
    q.qremove(x, underflow);
    if(underflow)
    {
    cout << "queue is empty. press a key to continue.";
    getch();
    }
    else {
    cout << "Removed value is:" << x;
    getch();
    }//end of else
    break;
    case 4:
    q.retrieve(x, underflow);
    if(underflow){
    cout << "queue is empty. press a key to continue.";
    getch();
    } //end of if
    else {
    cout << "Retrieved value is:" << x;
    getch();
    }//end of else
    break;
    case 5:
    exit(1);
    }//end of switch
    }//end of while
    }//end of program
    //********************
    int menu()
    {
    int c;
    cout << "1. Print queue.\n";
    cout << "2. Add to quue.\n";
    cout << "3. Remove from queue.\n";
    cout << "4. Retrieve from queue.\n";
    cout << "5. Exit.\n";
    cout << "Enter your select(1-5):";
    cin >> c;
    return c;
    }

    کد دوم:

    #include "iostream.h"
    #include "conio.h"
    #include "stdlib.h"
    #define SIZE 5
    class queue {
    public:
    queue();
    int empty();
    void addQ(int &, int &);
    void retrieve(int &, int &);
    void qremove(int &, int &);
    void print();
    private:
    int items[SIZE];
    int front;
    int rear;
    };
    //**************
    queue::queue()
    {
    front = 0;
    rear = -1;
    }
    //*************
    int queue::empty()
    {
    if(rear < front)
    return 1;
    return 0;
    }
    //*************
    void queue::addQ(int &x, int &overflow)
    {
    if(rear == SIZE-1)
    overflow = 1;
    else
    {
    overflow = 0;
    items[++rear] = x;
    }
    }
    //*************
    void queue::retrieve(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front];
    }
    }
    //*************
    void queue::qremove(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front++];
    }
    }
    //*************
    void queue::print()
    {
    if(empty())
    cout << "Queue is empty.";
    for(int i = front; i <= rear; i ++)
    cout << items[i] << " ";
    cout << "\nPress a key to continue.";
    getch();
    }
    //*************
    int menu();
    int main()
    {
    queue q;
    int x, overflow, underflow;
    while(1)
    {
    clrscr();
    switch(menu())
    {
    case 1:
    q.print();
    break;
    case 2:
    cout << "Enter a value to enter q:";
    cin >> x;
    q.addQ(x, overflow);
    if(overflow) {
    cout << "queue is full. press a key to continue.";
    getch();
    }
    break;
    case 3:
    q.qremove(x, underflow);
    if(underflow){
    cout << "queue is empty. press a key to continue.";
    getch();
    }
    else {
    cout << "Removed value is:" << x;
    getch();
    }
    break;
    case 4:
    q.retrieve(x, underflow);
    if(underflow) {
    cout << "queue is empty. press a key to continue.";
    getch();
    }
    else {
    cout << "Retrieved value is:" << x;
    getch();
    }
    break;
    case 5:
    exit(1);
    }//end of switch
    }//end of while
    }//end of program
    //*******************
    int menu()
    {
    int c;
    cout << "1. Print queue.\n";
    cout << "2. Add to quue.\n";
    cout << "3. Remove from queue.\n";
    cout << "4. Retrieve from queue.\n";
    cout << "5. Exit.\n";
    cout << "Enter your select(1-5):";
    cin >> c;
    return c;
    }


    #include "iostream.h"
    #include "conio.h"
    #include "stdlib.h"
    #define SIZE 5
    class queue {
    public:
    queue();
    int empty();
    void addQ(int &, int &);
    void retrieve(int &, int &);
    void qremove(int &, int &);
    void print();
    private:
    int items[SIZE];
    int front;
    int rear;
    };
    //**************
    queue::queue()
    {
    front = 0;
    rear = -1;
    }
    //*************
    int queue::empty()
    {
    if(rear < front)
    return 1;
    return 0;
    }
    //*************
    void queue::addQ(int &x, int &overflow)
    {
    if(rear == SIZE-1)
    overflow = 1;
    else
    {
    overflow = 0;
    items[++rear] = x;
    }
    }
    //*************
    void queue::retrieve(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front];
    }
    }
    //*************
    void queue::qremove(int &x, int &underflow)
    {
    if(empty())
    underflow = 1;
    else
    {
    underflow = 0;
    x = items[front++];
    }
    }
    //*************
    void queue::print()
    {
    if(empty())
    cout << "Queue is empty.";
    for(int i = front; i <= rear; i ++)
    cout << items[i] << " ";
    cout << "\nPress a key to continue.";
    getch();
    }
    //*************
    int menu();
    int main()
    {
    queue q;
    int x, overflow, underflow;
    while(1)
    {
    clrscr();
    switch(menu())
    {
    case 1:
    q.print();
    break;
    case 2:
    cout << "Enter a value to enter q:";
    cin >> x;
    q.addQ(x, overflow);
    if(overflow) {
    cout << "queue is full. press a key to continue.";
    getch();
    }
    break;
    case 3:
    q.qremove(x, underflow);
    if(underflow){
    cout << "queue is empty. press a key to continue.";
    getch();
    }
    else {
    cout << "Removed value is:" << x;
    getch();
    }
    break;
    case 4:
    q.retrieve(x, underflow);
    if(underflow) {
    cout << "queue is empty. press a key to continue.";
    getch();
    }
    else {
    cout << "Retrieved value is:" << x;
    getch();
    }
    break;
    case 5:
    exit(1);
    }//end of switch
    }//end of while
    }//end of program
    //*******************
    int menu()
    {
    int c;
    cout << "1. Print queue.\n";
    cout << "2. Add to quue.\n";
    cout << "3. Remove from queue.\n";
    cout << "4. Retrieve from queue.\n";
    cout << "5. Exit.\n";
    cout << "Enter your select(1-5):";
    cin >> c;
    return c;
    }

  2. #2
    کاربر فعال تالار .Net senaps's Avatar
    تاريخ عضويت
    Jul 2008
    محل سكونت
    خونمون
    پست ها
    4,547

    پيش فرض

    اقا سوال رو یه جا مطرح بکن!! این چه ربطی داره به دات نت عاخه؟! همون انجمن C درسته...

    شما یه زحمتی بکش لطفا و کد ها رو درست بذار و از تگ کد استفاده کد براشون تا بشه فهمید که چی نوشتین!!! یه خورده سخته خوندن کد ها اینجوری....

Thread Information

Users Browsing this Thread

هم اکنون 1 کاربر در حال مشاهده این تاپیک میباشد. (0 کاربر عضو شده و 1 مهمان)

User Tag List

قوانين ايجاد تاپيک در انجمن

  • شما نمی توانید تاپیک ایحاد کنید
  • شما نمی توانید پاسخی ارسال کنید
  • شما نمی توانید فایل پیوست کنید
  • شما نمی توانید پاسخ خود را ویرایش کنید
  •