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
|
#include <iostream>
#include <iomanip>
#include <cstring>
#include "CRA_Account.h"
namespace sict
{
CRA_Account::CRA_Account() // <--- Added.
{
lastName[0] = '\0'; // <--- Should also be a for loop, but works this way.
firstName[0] = '\0'; // <--- Should also be a for loop, but works this way.
numSIN = 0;
for (size_t lc = 0; lc < max_yrs; lc++) taxReturnYrs[lc] = 0;
for (size_t lc = 0; lc < max_yrs; lc++) ttlBalance[lc] = 0.0;
ttlYrs = 0;
}
// This function does not have much use right now.
// Should look like above when/if needed.
void CRA_Account::setEmpty()
{
lastName[0] = '\0';
firstName[0] = '\0';
numSIN = 0;
}
void CRA_Account::set(const char* familyName, const char* givenName, int sin)
{
if (isValidSIN(sin) && '\0' != familyName && '\0' != givenName)
{
strcpy(lastName, familyName);
strcpy(firstName, givenName);
numSIN = sin;
ttlYrs = 0;
}
else
{
setEmpty();
}
}
void CRA_Account::set(int year, double balance)
{
// Removed for loop.
// This uses "ttlYrs" as the subscript so it changes each time the function is called.
// This funcion only works four times until "ttlYrs" is >= max_yrs.
if (0 != numSIN && ttlYrs < max_yrs)
{
if (0 == taxReturnYrs[ttlYrs]) // <--- Changed != to ==.
{
taxReturnYrs[ttlYrs] = year;
ttlBalance[ttlYrs] = balance;
ttlYrs++;
}
}
}
bool CRA_Account::isValidSIN(int sin)
{
int sum = 0;
int check = sin % 10;
int evens[4] = { (((sin / 10) % 10) * 2), (((sin / 1000) % 10) * 2), (((sin / 100000) % 10) * 2), (((sin / 10000000) % 10) * 2) };
int odds[4] = { (((sin / 100) % 10)), (((sin / 10000) % 10)), (((sin / 1000000) % 10)), (((sin / 100000000) % 10)) };
for (int i = 0; i < 4; i++)
{
sum += ((((evens[i] / 1) % 10) + ((evens[i] / 10) % 10)));
sum += odds[i];
}
int upIntTen = ((sum + 9) / 10) * 10;
if (((upIntTen - sum) == (sin / 1) % 10) && sin >= minSin && sin <= maxSin)
{
return true;
}
else
{
return false;
}
}
void CRA_Account::display() const
{
if (0 != numSIN || '\0' != lastName || '\0' != firstName)
{
// <--- It works, but the use of "this->" is not need here in this type of member function.
// Becuse the function has direct access to the private variables. std::cout << "Family Name: " << this->lastName << std::endl;
std::cout << "Given Name : " << this->firstName << std::endl;
std::cout << "CRA Account: " << this->numSIN << std::endl;
std::cout.setf(std::ios::fixed);
std::cout.precision(2);
for (int i = 0; i < max_yrs; i++)
{
if (taxReturnYrs[i] == 0) // <--- Added if/else.
break;
else
{
std::cout << "Year " << taxReturnYrs[i];
if (ttlBalance[i] > 2)
{
std::cout << " balance owing: $" << ttlBalance[i] << std::endl; // <--- Changed.
}
else if (ttlBalance[i] < -2)
{
std::cout << " refund due: $" << abs(ttlBalance[i]) << std::endl; // <--- Changed.
}
else
{
std::cout << " No balance owing or refund due! " << std::endl;
}
}
}
std::cout.unsetf(std::ios::fixed);
std::cout.precision(6);
}
else
{
std::cout << "Account object is empty!" << std::endl << std::endl;
}
}
bool CRA_Account::isEmpty()
{
// <--- It works, but the use of "this->" is not need here in this type of member function.
// Becuse the function has direct access to the private variables.
// An example is the next function.
if (0 == this->numSIN || this->numSIN <= minSin || this->numSIN >= maxSin || '\0' == this->firstName[0] || '\0' == this->lastName[0])
{ // <--- These not needed for a single line. Also for else statement.
return true;
}
else
{
return false;
}
}
int CRA_Account::GetTtlYrs() { return ttlYrs; } // <--- Added.
} // End namespace
|