-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
72 lines (58 loc) · 1.84 KB
/
Copy pathdriver.cpp
File metadata and controls
72 lines (58 loc) · 1.84 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
// myIntDriver.cpp -- Sharanya Jayaraman
//
// Driver program to demonstrate the behavior of the MyInt class
//
// You can add more tests of your own, or write other drivers to test your solution
#include <iostream>
#include "myInt.h"
using namespace std;
MyInt factorial(MyInt num);
int main()
{
// demonstrate behavior of the two constructors and the << overload
MyInt x(12345), y("9876543210123456789"), r1(-1000), r2 = "14H67", r3;
char answer;
cout << "Initial values: \nx = " << x << "\ny = " << y
<< "\nr1 = " << r1 << "\nr2 = " << r2 << "\nr3 = " << r3 << "\n\n";
// demonstrate >> overload
cout << "Enter first number: ";
cin >> x;
cout << "Enter second number: ";
cin >> y;
cout << "You entered:\n";
cout << " x = " << x << '\n';
cout << " y = " << y << '\n';
// demonstrate assignment =
cout << "Assigning r1 = y ...\n";
r1 = y;
cout << " r1 = " << r1 << '\n';
// demonstrate comparison overloads
if (x < y) cout << "(x < y) is TRUE\n";
if (x > y) cout << "(x > y) is TRUE\n";
if (x <= y) cout << "(x <= y) is TRUE\n";
if (x >= y) cout << "(x >= y) is TRUE\n";
if (x == y) cout << "(x == y) is TRUE\n";
if (x != y) cout << "(x != y) is TRUE\n";
// demonstrating + and * overloads
r1 = x + y;
cout << "The sum (x + y) = " << r1 << '\n';
r2 = x * y;
cout << "The product (x * y) = " << r2 << "\n\n";
cout << "The sum (x + 12345) = " << x + 12345 << '\n';
cout << "The product (y * 98765) = " << y * 98765 << '\n';
//create fatcorials, storead as MyInts using *, <= and ++
cout << "The factorial of 45 is "<<factorial(45)<<endl;
cout<<"The factorial of 100 is "<<factorial(100)<<endl;
cout<<"The factorial of 281 is "<<factorial(281)<<endl;
return 0;
}
MyInt factorial(MyInt num)
{
MyInt f=1, n=1;
while(n<=num)
{
f = f * n;
n++;
}
return f;
}