Feb 23, 2017 at 1:25am Feb 23, 2017 at 1:25am UTC
Need some hints/tips on how this might look. I am a beginner to C++ so any help or details that look wrong please help!
Also I am unsure why I keep getting an error for
bool Expression::isOperator(){
prototype for 'bool Expression::isOperator()' does not match any in class 'Expression'|
Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
#include <iostream>
#include <fstream>
#include <stack>
#include <string>
using namespace std;
class Expression{
public :
Expression (string input, int direction); //edited this in
string inToPost();
string inToPre();
string postToIn();
string preToIn();
string convertThis; // Expression that we want converted
double evaluate();
bool isOperator();
Expression();
char symbol;
int direction;
private :
string infix;
string postfix;
string prefix;
};
Expression::Expression(){ // Constructor
switch (direction){
case 1: infix = convertThis;
case 2: postfix = convertThis;
case 3: prefix = convertThis;
}
}
//Function checks to see if convertThis contains valid symbol
bool Expression::isOperator(){ // error is occurring here.
if ((symbol == '*' )||(symbol == '+' )||(symbol == '-' )||(symbol == '/' ))
return true ;
else
return false ;
}
string Expression::inToPost(){
//converting with stack "S"
stack<char > S;
string postfix = "" ; // Initialize postfix as empty string.
for (int i = 0;i< convertThis.length();i++){
// Checking characters from left
// If character is delimitter.. skip
if (convertThis[i] == ' ' || convertThis[i] == ',' ) continue ;
// If character is operator, pop two elements from stack, perform operation and push the result back.
else if (isOperator(convertThis[i])){
S.push(convertThis[i]);
}
}
}
string Expression::inToPre(){
}
string Expression::postToIn(){
}
string Expression::preToIn(){
}
double Expression::evaluate(){
}
int main(){
string convertThis;
int choice;
cout << "|-----Here is my conversion menu-----|" << endl;
cout << "|----What are you converting to?-----|" << endl << endl;
cout << "1- Infix to postfix" << endl;
cout << "2- Infix to prefix" << endl;
cout << "3- postfix to infix?" << endl;
cout << "4- prefix to infix?" << endl;
cin >> choice;
cin.ignore();
cout << "Now enter the expression you want to convert " ;
getline(cin,convertThis);
bool isOperator();
string inToPost();
string inToPre();
}
Last edited on Feb 23, 2017 at 2:22am Feb 23, 2017 at 2:22am UTC
Feb 23, 2017 at 2:15am Feb 23, 2017 at 2:15am UTC
Yes it is line 64 I am sorry. Not sure how I can fix this issue just by reading what you said.
I added Expression (string input, int direction); to the public class.
Last edited on Feb 23, 2017 at 2:23am Feb 23, 2017 at 2:23am UTC