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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
#include <iostream>
#include <string>
#include "largeIntegers.h"
#include <iomanip>
#include "math.h"
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
largeIntegers::largeIntegers()
{
readIntegers();
}
void largeIntegers::readIntegers()
{
int i = 0;
int j = 0;
int k;
cout << "Enter large integer one: ";
cin >> bigInt1;
cout << "Enter large integer two: ";
cin >> bigInt2;
for (; bigInt1[i] != '\0'; i++);
length1 = i;
integer = new int[i];
k = 0;
for (j = i - 1; j >= 0; j--)
integer[j] = bigInt1[k++] - 48; //end processing integer one
int m = 0; //begin processing integer two
int n = 0;
int o;
for (; bigInt2[m] != '\0'; m++);
length2 = m;
integer = new int[m];
o = 0;
for (n = m - 1; n >= 0; n--)
integer[n] = bigInt2[o++] - 48;
}
void largeIntegers::outputInteger1()
{
for (int i = length1 - 1; i >= 0; i--)
cout << integer[i] << endl;
}
void largeIntegers::outputInteger2()
{
for (int m = length2 - 1; m >= 0; m--)
cout << integer[m] << endl;
}
void largeIntegers::compareIntegers()
{
if (bigInt1 == bigInt2)
cout << "Integers are equal." << endl;
if (bigInt1 < bigInt2)
cout << "Integer two is larger than integer one." << endl;
if (bigInt2 < bigInt1)
cout << "Integer one is larger than integer two." << endl;
}
void largeIntegers::addIntegers()
{
convertToIntegers();
int segment1 = int1a + int2a;
int segment2 = int1b + int2b;
int segment3 = int1c + int2c;
int segment4 = int1d + int2d;
/*string segment1str;
string segment2str;
string segment3str;
string segment4str;*/
stringstream ss1,ss2,ss3,ss4;
ss1 << segment1;
ss2 << segment2;
ss3 << segment3;
ss4 << segment4;
cout << "\n";
cout << "Your integers added together is: " << ss1 << ss2 << ss3 << ss4 << endl;
}
void largeIntegers::subtractIntegers()
{
convertToIntegers();
int segment1 = int1a - int2a;
int segment2 = int1b - int2b;
int segment3 = int1c - int2c;
int segment4 = int1d - int2d;
stringstream ss1,ss2,ss3,ss4;
ss1 << segment1;
ss2 << segment2;
ss3 << segment3;
ss4 << segment4;
string segment1str, segment2str, segment3str, segment4str;
segment1str = ss1.str();
segment2str = ss2.str();
segment3str = ss3.str();
segment4str = ss4.str();
cout << "\n" << "The first integer subtracted from the second integer is: " << segment1str << segment2str << segment3str << segment4str << endl;
//cout << "\n" << "The second integer subtracted from the first integer is: " << setprecision(30) << int1 - int2 << endl;
}
void largeIntegers::multiplyIntegers()
{
convertToIntegers();
int segment1 = int1a * int2a;
int segment2 = int1b * int2b;
int segment3 = int1c * int2c;
int segment4 = int1d * int2d;
stringstream ss1,ss2,ss3,ss4;
ss1 << segment1;
ss2 << segment2;
ss3 << segment3;
ss4 << segment4;
string segment1str, segment2str, segment3str, segment4str;
segment1str = ss1.str();
segment2str = ss2.str();
segment3str = ss3.str();
segment4str = ss4.str();
cout << "\n" << "Your integers multiplied together is: " << segment1str << segment2str << segment3str << segment4str << endl;
}
double largeIntegers::convertToIntegers()
{
//start converting string1
string str1a = bigInt1.substr(0,7);
int1a = atoi(str1a.c_str());
string str1b = bigInt1.substr(8,15);
int1b = atoi(str1b.c_str());
string str1c = bigInt1.substr(16,23);
int1c = atoi(str1c.c_str());
string str1d = bigInt1.substr(24,31);
int1d = atoi(str1d.c_str());
//start converting string2
string str2a = bigInt2.substr(0,7);
int2a = atoi(str2a.c_str());
string str2b = bigInt2.substr(8,15);
int2b = atoi(str2b.c_str());
string str2c = bigInt2.substr(16,23);
int2c = atoi(str2c.c_str());
string str2d = bigInt2.substr(24,31);
int2d = atoi(str2d.c_str());
return int1a, int1b, int1c, int1d, int2a, int2b, int2c, int2d;
}
|