Question please

Hello all, what's is line 5- line 9 here, it doesn't look like a function. Is it a class? how does it work here if so?

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
  #include<iostream> 
#include<conio.h> 
using namespace std;

struct Fract
{	
	int num;
	int deno;
};

Fract sum(Fract, Fract);

int main()
{
	int num1, deno1, num2, deno2;
	cout << "Enter fraction 1: numerator denominator:";
	cin >> num1 >> deno1;
	cout << "Enter fraction 2:numerator denominator:";
	cin >> num2 >> deno2;

	Fract f1 = { num1, deno1 };/* 1/2 */
	Fract f2 = { num2, deno2 };/* 2/5 */
	Fract result = sum(f1, f2);//sum the fractions 
	cout << result.num << "/" << result.deno;  //display the result 


	getch();
	return 0;

}

Fract sum(Fract f1, Fract f2)
{
	Fract result = { (f1.num * f2.deno) + (f2.num * f1.deno), f1.deno * f2.deno };
	return result;

}
Last edited on
It is another custom C++ data-type (in addition to class) called struct :
http://www.cplusplus.com/doc/tutorial/structures/
And it differs from class as follows: http://stackoverflow.com/questions/54585/when-should-you-use-a-class-vs-a-struct-in-c
Thank you Gunnerfunner!
closed account (48T7M4Gy)
One example here on fractions, I coincidentally found for other reasons, might be of use too!

http://en.cppreference.com/w/cpp/language/operators
Topic archived. No new replies allowed.