Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS301 Data Structure fall 2010 second assignment final idea solution
#1
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:
[FONT=&quot]o [/FONT]The assignment is submitted after due date.
[FONT=&quot]o [/FONT]The submitted assignment does not open or file corrupt.
[FONT=&quot]o [/FONT]The assignment is copied (from other student or ditto copy from handouts or internet).
[FONT=&quot]o [/FONT]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)
[FONT=&quot]Uploading instructions[/FONT]

[FONT=&quot]Your Submission must include:[/FONT]

  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.
Reply
#2
[SIZE="6"]Where's the solution?[/SIZE]
Reply
#3
Solution can be found after few hours.
Reply
#4
IQ-test Wrote:Solution can be found after few hours.

bhai bhej du solution
Reply
#5
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;
Reply
#6
i guess this solution is good for students i have not found any comments.
Reply
#7
there is no stake information and compile error
Reply
#8
it is just for idea dear.
[SIZE="3"]03009520262[/SIZE]
Rabeel Website
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CS301 Assignment # 4 Due Date: 02-Feb-2016 Vuhelper 0 2,324 02-03-2016, 05:38 PM
Last Post: Vuhelper
  CS703 – Advanced Operating Systems Assignment No.3 solution January 2016 Vuhelper 0 5,912 01-23-2016, 09:58 PM
Last Post: Vuhelper
  CS601 Data Communication Assignment No. 03 Solution 23rd January 2016 Vuhelper 1 1,931 01-23-2016, 06:09 PM
Last Post: Vuhelper
  CS403 Assignment No. 03 Solution 23rd January 2016 Vuhelper 2 1,168 01-23-2016, 03:18 PM
Last Post: Vuhelper
  CS506 Web Design and Development Assignment no 3 Solution 3rd January 2016 Vuhelper 0 2,247 01-23-2016, 03:16 PM
Last Post: Vuhelper
  CS724 Software Process Improvement Assignment No 01 Solution 20th January 2016 Vuhelper 0 1,970 01-20-2016, 06:26 PM
Last Post: Vuhelper
  CS711 Software Design Assignment No 01 Solution Due Date Feb 12, 2016 Vuhelper 0 1,667 01-20-2016, 06:24 PM
Last Post: Vuhelper
  CS709 Formal Methods for Software Engineering Assignment No 01 Solution January 2016 Vuhelper 0 1,808 01-20-2016, 06:22 PM
Last Post: Vuhelper
  cs703 assignment no 3 Solution 20th January 2016 Vuhelper 0 1,702 01-20-2016, 06:20 PM
Last Post: Vuhelper
  CS704 Assignment No. 01 Solution January 2016 Vuhelper 0 4,800 01-20-2016, 06:19 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)