Undefined reference error? Rational class lab

Why does my code give me this error when I try to compile it?

"/tmp/cciZVFen.o: In function `main':
Lab6rational.cpp:(.text+0x22): undefined reference to `rational::rational()'
Lab6rational.cpp:(.text+0x2e): undefined reference to `rational::rational()'
Lab6rational.cpp:(.text+0x3a): undefined reference to `rational::rational()'
Lab6rational.cpp:(.text+0x55): undefined reference to `rational::read()'
Lab6rational.cpp:(.text+0x70): undefined reference to `rational::read()'
Lab6rational.cpp:(.text+0x7f): undefined reference to `rational::sum(rational, rational)'
Lab6rational.cpp:(.text+0x9e): undefined reference to `rational::write()'
Lab6rational.cpp:(.text+0xf2): undefined reference to `rational::get_numerator()'
Lab6rational.cpp:(.text+0x10d): undefined r"


If anyone knows any help is appreciated!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  #include <iostream> 
using namespace std; 

// Add appropriate headers

/*  KEEP THIS COMMENT
* class Rational
*    represents a Rational number. Remember rational means ratio-nal
*    which means there is a numerator and denominator having
*    integer values. Using good ADT techniques, we have made member
*    variable private (also known as instance variables) and made member
*    functions public.
*/

class rational
{
    public: 
	// ToDo: Constructor that takes int numerator and int denominator
        rational(int numerator, int denominator);
	// ToDo: Constructor that takes int numerator
        rational(int numerator);
	// ToDo: Default Constructor
        rational();
	// ToDo: Member function to read a rational in the form: n/d
        void read();
         
	// ToDo: Member function to write a rational as n/d 
        void write();
        
        
	// ToDo: declare an accessor function to get the numerator
        int get_numerator();
	// ToDo: declare an accessor function to get the denominator
        int get_denominator();
	// ToDo: delcare a function called Sum that takes two rational objects
	    void sum (rational rat1, rational rat2);
	    
	    
	// sets the current object to the sum of the given objects using the
	// formula: a/b + c/d = ( a*d + b*c)/(b*d)
        

};
//void rational::input()
// char c;
// cin >> numerator >> c >> denominator; 


//rational3.sum(rational1,rational2);

int main()
{
	// ToDo: declare three rational objects using the default constructor
	
    rational rat1,rat2,rat3;
	char answer;

	// Main loop to read in rationals and compute the sum
	do {
		cout << "\nEnter op1 (in the format of p/q): ";
		
		// ToDo: use your input member function to read the first rational;;;;
		 rat1.read();

		cout << "\nEnter op2 (in the format of p/q): ";
		// ToDo: use your input member function to read the second rational
		 rat2.read();

		// ToDo: use the third rational to call Sum with first and second as parameters
	     rat3.sum(rat1,rat2);
         
		cout << "\nThe sum of op1 and op2 is: ";
		// ToDo: ouptput the third rational
	      rat3.write();

		cout << "\nTry again (Y/N)?";
		cin >> answer;

	} while (answer == 'y' || answer == 'Y');

	// ToDo: test getters 
	cout << "\nC's numerator is: " ;
    rat3.get_numerator();

	cout << "\nC's denominator is: ";
    rat3.get_denominator();
    
	return 0;
}

// ToDO: Implement your class member functions below. 
You never defined the functions under the class.. how is the compiler supposed to know what you want to happen?

You're supposed to fill the helper functions yourself so have a go at it. You haven't written them in that program, you probably didn't realize.
Topic archived. No new replies allowed.