C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 15th, 2004, 12:08 PM
evanmichael evanmichael is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 evanmichael User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy help with fraction array

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 arguments
c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(51) : error C2660: 'stack:op' : function does not take 1 arguments
c:\Documents and Settings\Picc\Desktop\C++\fraction_stack.cpp(52) : error C2660: 'stack:op' : function does not take 1 arguments

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > help with fraction array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT