Sponsored Links


Results 1 to 8 of 8

Thread: CS301 Data Structure fall 2010 second assignment final idea solution

  1. #1
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,251

    Icon14 CS301 Data Structure fall 2010 second assignment final idea solution

    Sponsored Links


    Instructions
    Please read the following instructions carefully before solving & submitting assignment:
    It should be clear that your assignment will not get any credit (zero marks) if:
    o The assignment is submitted after due date.
    o The submitted assignment does not open or file corrupt.
    o The assignment is copied (from other student or ditto copy from handouts or internet).
    o Student ID is not mentioned in the assignment File or name of file is other than student ID.

    Note: Kindly check the template file for submitting assignment. (see announcement)
    Uploading instructions

    Sponsored Links


    Your Submission must include:

    1. A working Make File (Dev-C++ project File).
    2. All the Source Code (.h and .cpp files) necessary to compile and run your program.
    3. Place all the files in a folder then Zip that folder and Upload it on VULMS


    Note: Use Dev-C++ 4.9.9.2 which is available at VULMS (Download section) or you can use Dev-C++ 4.0 or any other version higher than 4.0.
    Question:
    Write a program in c++ that takes an infix expression from user through command line argument and convert it into a postfix expression. You are required to use the stack data structure for the implementation of this task.




    Note: You can’t use built-in library function or templates for stack functions. All the source code should be written manually.

  2. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Where's the solution?

  3. #3
    Senior Member
    Join Date
    Oct 2010
    Posts
    116
    Solution can be found after few hours.

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Quote Originally Posted by IQ-test View Post
    Solution can be found after few hours.
    bhai bhej du solution

  5. #5
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,251

    Icon14

    IDEA Solution of cs301 second assignment
    Code:
    #include<iostream.h>
    #include<string.h>
    #include<stdlib.h>
    #include<ctype.h>
    class expression
    {
    private:
     char infix[100];
     char stack[200];
     int top;
     int r;
     char postfix[100];
    public:
     void convert();
     int input_p(char);
     int stack_p(char);
     int rank(char);
    };
    int expression::input_p(char c)
    {
     if(c==’+’ || c==’-')
      return 1;
     else if(c==’*’ || c==’/')
      return 3;
     else if(c==’^')
      return 6;
     else if(isalpha(c)!=0)
      return 7;
     else if(c==’(‘)
      return 9;
     else if(c==’)')
      return 0;
     else
     {
      cout<<”Invalid expression ::input error\n”;
      exit(0);
     }
    }
    int expression::stack_p(char c)
    {
     if(c==’+’ || c==’-')
      return 2;
     else if(c==’*’ || c==’/')
      return 4;
     else if(c==’^')
      return 5;
     else if(isalpha(c)!=0)
      return 8;
     else if(c==’(‘)
      return 0;
     else
     {
      cout<<”Invalid expression  ::stack error\n”;
      exit(0);
     }
    }
    int expression::rank(char c)
    {
     if(c==’+’ || c==’-')
      return -1;
     else if(c==’*’ || c==’/')
      return -1;
     else if(c==’^')
      return -1;
     else if(isalpha(c)!=0)
      return 1;
     else
     {
      cout<<”Invalid expression ::in rank\n”;
      exit(0);
     }
    }
    void expression::convert()
    {
     cout<<”\n*************************************************\n”
      <<”This program converts the given infix expression\n”
      <<”in to postfix form”
                    <<”\n*************************************************\n”;
     cout<<”Enter an infix expression ::\n”;
     cin>>infix;
     int l=strlen(infix);
     infix[l]=’)';
     infix[l+1]=”;
     //Convertion starts
     top=1;
     stack[top]=’(‘;
     r=0;
     int x=-1;
     int i=0;
     char next=infix[i];
     while(next!=”)
     {
      //Pop all the elements to outputin stack which have higher precedence
      while( input_p(next) < stack_p(stack[top]) )
      {
       if(top<1)
       {
        cout<<”invalid expression ::stack error\n”;
        exit(0);
       }
       postfix[++x]=stack[top];
       top–;
       r=r+rank(postfix[x]);
       
       if(r<1)
       {
        cout<<”Invalid expression  ::r<1\n”;
        exit(0);
       }
      }
      if(input_p( next ) != stack_p( stack[top]))
       stack[++top]=next;
      else
       top–;
      i++;
      next=infix[i];
     }
     postfix[++x]=”;
     if(r!=1 || top!=0)
     {
      cout<<”Invalid expression ::error in rank or stack\n”;
      exit(0);
     }
     cout<<”\n\nThe corresponding postfix expression is ::\n”;
     cout<<postfix<<endl;
    }
    int main()
    {
     expression obj;
     obj.convert();
     return 0;

  6. #6
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,251
    i guess this solution is good for students i have not found any comments.

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    there is no stake information and compile error

  8. #8
    Administrator
    Join Date
    Oct 2011
    Posts
    468
    it is just for idea dear.
    03009520262
    Rabeel Website

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 07-18-2014, 01:32 PM
  2. CS301 Data Structure Assignments No.2 Solution and Discussion Fall 2014
    By vuassignments in forum Assignments & Solutions
    Replies: 1
    Last Post: 05-28-2014, 05:41 PM
  3. CS301 Data Structure VU Current Assignment No. 1 semester Fall November 2012
    By vuassignments in forum Assignments & Solutions
    Replies: 0
    Last Post: 11-01-2012, 10:59 PM
  4. CS301 data structure final term current paper required February 2012
    By Vuhelper in forum Mid Term & Final Term Papers
    Replies: 0
    Last Post: 02-03-2012, 07:48 PM
  5. Replies: 8
    Last Post: 11-07-2010, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft