php hit counter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS301 Data Structures Assignment No 02 SEMESTER FALL 11 November 2011
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
Write a C++ program to evaluate postfix expressions. Your program should take postfix expression as an input, process it with the help of stack and display the result after performing required calculations.
Only following Binary operators are allowed for this program:
+, -, *, /, ^ [addition, subtraction, multiplication, division, exponentiation]
If some error occurs while processing postfix expression, your program should display a meaningful message, like:
Error: Division by zero not allowed
Error: Two operands required for __ operator
Error: Invalid postfix expression

Sample Run:
Enter postfix expression to evaluate:
10 20 + Entered by user
The result is: 30
Do you want to enter another postfix expression to evaluate? [Y/N]
Y Entered by user

Enter postfix expression to evaluate:
30 40 + * Entered by user

Error: Two operands required for * operator

Do you want to enter another postfix expression to evaluate? [Y/N]
Y Entered by user
Enter postfix expression to evaluate:
30 40 + 50 60 * Entered by user

Error: Invalid postfix expression
Do you want to enter another postfix expression to evaluate? [Y/N]
Y Entered by user
Enter postfix expression to evaluate:
6 2 3 + - 3 8 2 / + * 2 ^ 3 + Entered by user
The result is: 52
Do yu want to enter another postfix expression to evaluate? [Y/N]
N Entered by user
Thank you for using this program.






Attached Files
.doc   CS301_2.doc (Size: 166 KB / Downloads: 221)

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#2
please upload solution of assignment no-2 cs301 plz plz
Reply
#3
Dear sir send the solution of Assignment#2 of cs301 fall 2011.
Thanks
Reply
#4
bht ajeeb bat ha yar...aj extended day ha aur ubi tak solution upload nai kiya...

wat you doing admin sir???????????///
Reply
#5
help me in cs301 assignment no.2
Reply
#6
Code:
#include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<string> #define MAX_SIZE 20 using namespace std; template<class T> class Stack{ private: T item[MAX_SIZE]; int top; public: Stack(){ top = -1; } void push(T data){ if(!this->is_full()) item[++top] = data; else{ cout"Stack Error"endl; exit(10); } } T pop(){ if(!this->is_empty()) return item[top--]; else{ cout"Stack is Empty"endl; exit(11); } } int size(){ return top+1; } bool is_empty(){ if(top==-1) return true; else return false; } bool is_full(){ if(top==MAX_SIZE-1) return true; else return false; } void display(){ for(int i=0; i<this->size(); i++){ coutitem[i]" "; } coutendl; } T return_top(){ return item[top]; } }; class Convert{ private: bool num_flag; bool tow_digit_flag; public: Convert(); string return_with_bracket(string infix); void to_Postfix(string infix,char postfix[]); bool prcd(char op1, char op2); int isOperand(char op); int isOperator(char op); bool return_flag(){ return num_flag; } }; Convert::Convert(){ this->num_flag = false; this->tow_digit_flag = false; } string Convert::return_with_bracket(string infix){ return("(" + infix + ")"); } bool Convert::prcd(char op1, char op2){ if((op1=='+' || op1=='-' || op1=='*' || op1=='/') && op2=='(' ) return true; if(op1=='+' && op2=='+') return true; if(op1=='-' && op2=='-') return false; if(op1=='-' && op2=='+') return false; if(op1=='+' && op2=='-') return false; if(op1=='/' && op2=='/') return false; if(op1=='/' && (op2=='-' || op2=='+')) return true; if(op1=='*' && (op2=='+' || op2=='-')) return true; if((op1 == '-' || op1 == '+') && (op2 =='*' || op2 == '/')) return false; if((op1=='$' || op1 == '+') && (op2 =='*' || op2 == '/' || op2=='-')) return true; if((op1 == '-' || op1 == '+' || op1 =='*' || op1 == '/')&& op2=='^') return false; if(op1 == '^' && ( op2 == '+' || op2 =='*' || op2 == '/' || op2=='-')) return false; } int Convert::isOperand(char op){ return(op>= '0' && op <= '9'); } int Convert::isOperator(char op){ return(op=='+' || op=='-' || op == '/' || op=='*' || op=='^'); } void Convert::to_Postfix(string infix, char postfix[]){ int position, outpos=0; char c; int count = 0; char temp; char stacktop ; Stack<char> stack; for(position = 0; (c = infix[position])!='\0'; position++){ if(this->isOperand(c)){ postfix[outpos++] = c; this->num_flag = true; count++; if(count>=2){ this->tow_digit_flag = true; } }else if(this->isOperator(c)){ count = 0; if(isOperator(infix[position]) && isOperator(infix[position+1])){ cout"\aMissing argument in between "infix[position]" and "infix[position+1] " in column " position+1endl; exit(9); } if(this->prcd(c, stacktop)){ stacktop=stack.return_top(); stack.push(c); stacktop = c; }else{ while(true){ temp = stack.pop(); postfix[outpos++] =temp; stacktop = stack.return_top(); if(prcd(c, stacktop) || stacktop=='(') break; } stack.push(c); stacktop = stack.return_top(); } } else if(c=='('){ count = 0; stack.push(c); stacktop = stack.return_top(); }else if(c==')'){ count = 0; while(1){ if(stack.size()==0){ cout"Warning!! Number of ')' is greater than '('" endl; exit(2); } temp = stack.pop(); if(temp!='('){ postfix[outpos++] = temp; }else{ break; } } stacktop =stack.return_top(); } else{ cout"Invalid input"; exit(3); } if(infix[position]==')' && infix[position+1]=='('){ stack.push('*'); stacktop = stack.return_top(); } } if(stack.size()!=0){ cout"Warning!!Number of '(' is greater than ')'"endl; // exit(6); } if(!this->return_flag()){ cout"You must Enter Numeric value for calculation"endl; cout"This program cannot perform operations on variables"; exit(5); } if(this->tow_digit_flag){ cout"Sory! Althoug u may have entered right string"endl; cout"this program is only for single digit operation"endl; exit(8); } postfix[outpos] = '\0'; } class Evaluate{ public: double eval(char expr[], Convert &); double oper(int symb, double op1, double op2); }; double Evaluate::oper(int symb, double op1, double op2){ switch(symb){ case '+': return (op1 + op2); case '-': return (op1 - op2); case '*': return (op1 * op2); case '/': return (op1 / op2); case '^': return (pow(op1, op2)); } } double Evaluate::eval(char expr[],Convert &convert){ int c, position; char temp1; int count = 0; double opnd1, opnd2, value; Stack<double> stack; for(position = 0; (c = expr[position])!='\0'; position++){ if(convert.isOperand(c)){ temp1 = double(c-'0'); stack.push(temp1); }else{ opnd2 = stack.pop(); if(stack.size()==0){ cout"This program cannot process unary operation"; exit(1); } opnd1 = stack.pop(); value = oper(c, opnd1, opnd2); stack.push(value); } } if(stack.size()>=2){ cout"Sory! this program cannot calculate this"endl; cout"Enter +, *, /, - or ^ between bracket"endl; exit(4); } return (stack.pop()); } int main(){ Convert convert; Evaluate evaluate; string bracketted_infix; char infix[50], postfix[50]; char choice; while(1){ cout"Enter operation: "; cin>>infix; coutendl; cout"Entered operation: "infixendl; bracketted_infix = convert.return_with_bracket(infix); convert.to_Postfix(bracketted_infix, postfix); cout"Equivalent Postfix operation: "postfixendl; cout"RESULT: "; coutevaluate.eval(postfix, convert); cout"\nCalculate another operation?(y/n) "; cin>>choice; coutendl; if(choice=='n') break; } return 0; }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#7
Thanx......
Reply
#8
kya thanks....
kisey na kaam ka solution ha...
itnay zyada errors
Reply
#9
thank u so much
Reply
#10
error kub nekal loo kuch tuu karo

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support