static function problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 4
Reputation: Guppy25 is an unknown quantity at this point 
Solved Threads: 0
Guppy25 Guppy25 is offline Offline
Newbie Poster

static function problem

 
0
  #1
Feb 5th, 2005
I've created a class Fraction, and declared a private static character to hold the slash for displaying the fraction in fraction form later on. I can't seem to get the static char to compile and I need to figure out what I've done wrong, thank you for the help, jennie

class Fraction
{
private:
double num, den;
double decimal;
static char slash;

void calculateDecimalValue(double decimal);

public:
void enterFractionValue();
void displayFraction();
static void displaySlash();
};
//implementation part-to be named-fraction.cpp
char Fraction::slash="/";
void Fraction::displaySlash()
{
cout<<slash<<endl;
}

void Fraction::enterFractionValue()
{
cout <<"Please enter a numerator "<<endl;
cin >>num;
cin.ignore(80,'\n');
cout <<"The numerator is "<<num<<endl;

cout <<"Please enter a denominator "<<endl;
cin >>den;
cin.ignore(80,'\n');

while (den == 0)
{
cout<<"Enter a number greater than zero."<<endl;
cin >>den;
cin.ignore(80,'\n');
}
cout <<"The denominator is "<<den<<endl;
}

void Fraction::calculateDecimalValue(double decimal)
{
decimal = den/num;
}


void Fraction::displayFraction()
{
int input;

cout<<"Enter the number 1 to see fraction in fraction format or "<<endl;
cout<<"the number 2 to see it in decimal form"<<endl;
cin>>input;
cin.ignore(80,'\n');
while (input != 1 && input !=2)
{
cout<<"Your entry must be a 1 or a 2, please try again."<<endl;
cin>>input;
cin.ignore(80,'\n');
}
if (input == 1)

cout<<"The fraction in traditional form is "<<num <<slash<<den<<endl;

if (input == 2)
cout<<"The fraction in decimal form is " <<decimal<<endl;

}
//main function to be named testfraction.cpp
#include <iostream.h>
#include "fraction.h"
#include "fraction.cpp"
int main()
{
Fraction oneFraction;
oneFraction.enterFractionValue();
oneFraction.displayFraction();
cout << "Press Enter to continue";
getchar();
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,349
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: static function problem

 
0
  #2
Feb 5th, 2005
char Fraction::slash="/";
This should be:
char Fraction::slash='/';
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC