-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3_main.cpp
More file actions
77 lines (55 loc) · 2.02 KB
/
Task3_main.cpp
File metadata and controls
77 lines (55 loc) · 2.02 KB
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
/**
* @file Task3_main.cpp
*
* @brief This code implements unary operator overloading
* It also implements type-conversion operator overloading.
*
* @author Saif Ullah Ijaz
*
*/
// SYSTEM INCLUDES
#include <iostream>
using namespace std;
// LOCAL INCLUDES
#include "RationalNumber.h"
// function main begins program execution
void main() {
RationalNumber r1(4, 9), r2(2, 3), r3;
cin >> r1 >> r2 >> r3;
cout << "First Rational Number: " << r1 << endl;
cout << "Second Rational Number: " << r2 << endl;
cout << "Third Rational Number: " << r3 << endl << endl;
cout << "Unary - (minus) r1: " << -r1 << endl;
cout << "Unary - (minus) r2: " << -r2 << endl;
cout << "Unary - (minus) r3: " << -r3 << endl << endl;
cout << "Pre-increment r1: " << ++r1 << endl;
cout << "Pre-increment r2: " << ++r2 << endl;
cout << "Pre-increment r3: " << ++r3 << endl << endl;
cout << "Post-increment r1: " << r1++ << endl;
cout << "Post-increment r2: " << r2++ << endl;
cout << "Post-increment r3: " << r3++ << endl << endl;
cout << "r1: " << r1 << endl;
cout << "r2: " << r2 << endl;
cout << "r3: " << r3 << endl << endl;
cout << "Pre-decrement r1: " << --r1 << endl;
cout << "Pre-decrement r2: " << --r2 << endl;
cout << "Pre-decrement r3: " << --r3 << endl << endl;
cout << "Post-decrement r1: " << r1-- << endl;
cout << "Post-decrement r2: " << r2-- << endl;
cout << "Post-decrement r3: " << r3-- << endl << endl;
cout << "r1: " << r1 << endl;
cout << "r2: " << r2 << endl;
cout << "r3: " << r3 << endl << endl;
float f1 = 3.1429, f2 = 0.5, f3 = 1.5;
r1 = f1;
r2 = (RationalNumber)f2;
r3 = RationalNumber(f3);
cout << "Float to Rational: " << r1 << endl;
cout << "Float to Rational: " << r2 << endl;
cout << "Float to Rational: " << r3 << endl << endl;
cout << "Rational to Float: " << (float)r1 << endl;
cout << "Rational to Float: " << (float)r2 << endl;
cout << "Rational to Float: " << (float)(r3) << endl << endl;
system("pause");
}
// end main