# Problem with argument list

• 04-19-2004
RedZippo
Problem with argument list
I am trying to learn how to build a class and I am having trouble. My simple program reads in a fraction, and inverts it. I will do much more with it later if I can get past this problem. Currently I have two warnings, one about missing an argument list, and the other about using frac1 without it being initialized. I've banged my head on this for 2 days now, so I think it is time I ask for some help. Here is the code...
Code:

#include <iostream>
using namespace std;

char oper;

class SingleFraction
{
public:
void getFrac(SingleFraction ff1)
{
char misc;
cin >> num >> misc >> den >> oper;
}
void invert(SingleFraction ff1)
{
num = ff1.den;
den = ff1.num;
}
void display()
{
cout << num << '/' << den;
}
private:
int num, den;
};

int main()
{
SingleFraction frac1, fracAns;
char choice = 99;

while (choice != 'n' && choice != 'N')
{
cout << "Enter a fraction and operator: ";
frac1.getFrac;  // warning here about missing argument list
switch(oper)
{
case 'i': fracAns.invert(frac1); break;  // warning here about frac1 not being initialized
//default: cout << "Illegal operator.";
continue;
}
fracAns.display();
cout << "Answer = "; fracAns.display();
cout << "\nAgain(y/n)?: "; cin >> choice;
}
return 0;
}

• 04-19-2004
major_small
try some thing more like this:

fracClass.h
Code:

#ifndef _fracClass_h_
#define _fracClass_h_

class SingleFraction
{
public:
void getFrac();
void invert();
void display();
char retOper()
private:
int num, den;
char oper;
};

#endif

fracClass.cpp
Code:

#include "fracClass.h"

void singleFraction::getFrac()
{
char misc;
cin >> num >> misc >> den >>oper;
}
void SingleFrac::invert()
{
int temp=num;
num = den;
den = temp;
}
void SingleFrac::display()
{
cout << num << '/' << den;
}
char SingleFrac::retOper()
{ return oper; }

main.cpp
Code:

#include<iostream>
#include "fracClass.h"

int main()
{
SingleFraction frac1, fracAns;
char choice = 99;

while (choice != 'n' && choice != 'N')
{
cout << "Enter a fraction and operator: ";
frac1.getFrac;  // warning here about missing argument list
switch(frac1.oper)
{
case 'i': fracAns.invert(frac1); break;  // warning here about frac1 not being initialized
//default: cout << "Illegal operator.";
continue;
}
fracAns.display();
cout << "Answer = "; fracAns.display();
cout << "\nAgain(y/n)?: "; cin >> choice;
}
return 0;
}