| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I'm stumped here. I've been sitting here for hours trying to create a stack array that asks the user for fractions and returns them in a stack. I'm incorporating a class fraction to do this, but I'm running into a number of errors. Would you mind taking a look at my code and pointing out any glaring problems are...ANY HELP IS GREATLY APPRECIATED!!!!: CODE: #include <iostream> using namespace std; const int MAX=3; ////////////////////////////////////////////////// class fraction { private: int n; int d; public: fraction():n(0), d(1) {} fraction(int nn, int dd): n(nn), d(dd) {} void getfrac() {char dummy; cin >> n >> dummy >> d;} void printfrac() {cout << n << "/" << d;} }; ////////////////////////////////////////////////// class stack {private: fraction farray[MAX]; fraction top; public: stack() {top = -1;} void push(fraction var) {farray[++top] = var;} int pop() {return farray[top--]; } }; ////////////////////////////////////////////////// int main() { stack s1; fraction f1; cout << "Enter a fraction in a/b format: "; s1.push(f1.getfrac); cout << "Enter a fraction in a/b format: "; s1.push(f1.getfrac); cout << "Enter a fraction in a/b format: "; s1.push(f1.getfrac); cout << "1: " << s1.pop(f1.printfrac) << endl; cout << "2: " << s1.pop(f1.printfrac) << endl; cout << "3: " << s1.pop(f1.printfrac) << endl; return 0; } Here are my errors: c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(31) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(34) : error C2675: unary '++' : 'fraction' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(36) : error C2676: binary '--' : 'fraction' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(45) : error C2664: 'stack: ush' : cannot convert parameter 1 from 'void (void)' to 'fraction'No constructor could take the source type, or constructor overload resolution was ambiguous c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(47) : error C2664: 'stack: ush' : cannot convert parameter 1 from 'void (void)' to 'fraction'No constructor could take the source type, or constructor overload resolution was ambiguous c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(49) : error C2664: 'stack: ush' : cannot convert parameter 1 from 'void (void)' to 'fraction'No constructor could take the source type, or constructor overload resolution was ambiguous c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(50) : error C2660: 'stack: op' : function does not take 1 argumentsc:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(51) : error C2660: 'stack: op' : function does not take 1 argumentsc:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(52) : error C2660: 'stack: op' : function does not take 1 arguments |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > help with fraction array |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|