/
CISP400V9A6.cpp
110 lines (94 loc) · 4.35 KB
/
CISP400V9A6.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// NAME : Yevgeniy Lankin
// CLASS : CISP 400, Online
// Assignment #: A6
// PURPOSE : Test program for class Complex.h, Date.h,
// and functions defined in Complex.cpp, Date.cpp
// To show my understand of operation overloading.
// Software Change (Modifications) Record
// date what who
// 11/11/2015 created program Yev
#include "Complex.h" // Complex class definition
#include "Date.h" // Date class definition
//template function to test with different types
template <class Type>
bool isEqualTo(Type left, Type right)
{
return (left == right);
} // end function isEqualTo
int main()
{
// test if two ints are equal or not
cout << "*** Integers Tests ***" << endl;
int leftInts[4] = { 1, 2, -1, -1 }; // lhs integers used for testing equality
int rightInts[4] = { 1, 4, 1, -1 }; // rhs integers used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Integers: " << leftInts[a] << " and " << rightInts[a] << " are "
<< (isEqualTo(leftInts[a], rightInts[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two chars are equal or not
cout << "\n\n*** Chars Tests ***" << endl;
char leftChars[4] = { 'a', 'a', 'c', 'c' }; // lhs chars used for testing equality
char rightChars[4] = { 'a', 'c', 'a', 'c' }; // rhs chars used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Characters: " << leftChars[a] << " and " << rightChars[a] << " are "
<< (isEqualTo(leftChars[a], rightChars[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two doubles are equal or not
cout << "\n\n*** Double Tests ***" << endl;
double leftDoubles[4] = { 2.2, 2.2, -2.2, -2.2 }; // lhs integers used for testing equality
double rightDoubles[4] = { 2.2, 2.3, 2.2, -2.2 }; // rhs integers used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "Double numbers: " << leftDoubles[a] << " and " << rightDoubles[a] << " are "
<< (isEqualTo(leftDoubles[a], rightDoubles[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
// test if two Complex objects are equal
cout << "\n\n*** Complex Tests ***" << endl;
Complex a(10, 5); // Complex objects used
Complex a1(10, 5); // for testing equality
cout << "Class objects: " << a << " and " << a1 << " are "
<< (isEqualTo(a, a1) ? "equal" : "\"NOT\" equal");
Complex b(10, 5); // Complex objects used
Complex b1(10, 54); // for testing equality
cout << "\nClass objects: " << b << " and " << b1 << " are "
<< (isEqualTo(b, b1) ? "equal" : "\"NOT\" equal");
Complex c(10, -5); // Complex objects used
Complex c1(10, 5); // for testing equality
cout << "\nClass objects: " << c << " and " << c1 << " are "
<< (isEqualTo(c, c1) ? "equal" : "\"NOT\" equal");
Complex d(-10, -5); // Complex objects used
Complex d1(-10, -5); // for testing equality
cout << "\nClass objects: " << d << " and " << d1 << " are "
<< (isEqualTo(d, d1) ? "equal" : "\"NOT\" equal");
//test if two strings are equal or not
cout << "\n\n\n*** String Tests ***" << endl;
string leftStrings[4] = { "abcdefg", "abcdefg", "-abcdefg", "-abcdefg" }; // lhs chars used for testing equality
string rightStrings[4] = { "abcdefg", "abcdefh", "abcdefg", "-abcdefg" }; // rhs chars used for testing equality
for (int a = 0; a < 4; a++)
{
cout << "String objects: " << leftStrings[a] << " and " << rightStrings[a] << " are "
<< (isEqualTo(leftStrings[a], rightStrings[a]) ? "equal" : "\"NOT\" equal") << '\n';
}
//test if two dates are equal or not
cout << "\n\n*** Date Tests ***";
Date dayA(2, 31, 2016); // create date object
Date dayB(2, 31, 2016); // create date object
cout << "\nDate objects: " << dayA << " and " << dayB << " are "
<< (isEqualTo(dayA, dayB) ? "equal" : "\"NOT\" equal");
Date dayC(-2, 13, 2016); // create date object
Date dayD(2, 14, 2016); // create date object
cout << "\nDate objects: " << dayC << " and " << dayD << " are "
<< (isEqualTo(dayC, dayD) ? "equal" : "\"NOT\" equal");
Date dayE(-2, 13, 2016); // create date object
Date dayF(2, 13, 2016); // create date object
cout << "\nDate objects: " << dayE << " and " << dayF << " are "
<< (isEqualTo(dayE, dayF) ? "equal" : "\"NOT\" equal");
Date dayG(-2, 13, 2016); // create date object
Date dayH(2, 31, 2016); // create date object
cout << "\nDate objects: " << dayG << " and " << dayH << " are "
<< (isEqualTo(dayG, dayH) ? "equal" : "\"NOT\" equal") << '\n';
cout << endl << endl;
return 0;
} // end main