Problem with argument list

This is a discussion on Problem with argument list within the C++ Programming forums, part of the General Programming Boards category; I am trying to learn how to build a class and I am having trouble. My simple program reads in ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    49

    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;
    }
    Semper Fi!

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    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;
    }
    Last edited by major_small; 04-19-2004 at 12:22 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 07:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21