In this workshop, you are to code a class with private data members and public member functions. The class will represent a book and can be used to man-age a collection of books that a person has in her possession.
Upon successful completion of this workshop, you will have demonstrated the abilities to
Design and code a module named CRA_Account. The application that uses your module is listed below. Store your class definition in a header file named CRA_Account.h and your function definitions in an implementation file named CRA_Account.cpp.
Include a compilation safeguard in the header file. Enclose all declarations and definitions within the sict namespace.
In your CRA_Account.h header file, predefine the following constants as in-tegers:
Your CRA_Account module validates any SIN that it receives. For this in-lab sub-mission, your implementation consider a SIN valid if it is a 9-digit number between the predefined limits.
Define the CRA_Account class with private members that hold the following data for the account:
Declare the following public member functions in your class definition:
Family Name: FAMILY_NAME< ENDL>
Given Name : GIVEN_NAME< ENDL>
CRA Account: SIN< ENDL>
Account object is empty!< ENDL>
IN-LAB MAIN MODULE
#include < iostream>
#include "CRA_Account.h"
#include "CRA_Account.h" // intentional
using namespace std;
using namespace sict;
int main() {
sict::CRA_Account myCRA;
int sin;
bool quit = false;
char familyName[sict::max_name_length + 1];
char givenName[sict::max_name_length + 1];
cout << "Canada Revenue Agency Account App" << endl
<< "=================================" << endl << endl;
cout << "Checking constants" << endl
<< "---------------------------------" << endl
<< "max_name_length: " << sict::max_name_length << endl
<< " min_sin: " << sict::min_sin << endl
<< " max_sin: " << sict::max_sin << endl
<< "---------------------------------" << endl << endl;
cout << "Please enter your family name: ";
cin >> familyName;
cin.ignore();
cout << "Please enter your given name: ";
cin >> givenName;
cin.ignore();
do {
cout << "Please enter your social insurance number (0 to quit): ";
cin >> sin;
cin.ignore();
if (sin != 0) {
myCRA.set(familyName, givenName, sin);
if (myCRA.isEmpty())
cout << "Invalid input! Try again." << endl;
else
quit = true;
}
else
quit = true;
} while (!quit);
cout << "----------------------------------------" << endl;
cout << "Testing the display function" << endl;
cout << "----------------------------------------" << endl;
myCRA.display();
cout << "----------------------------------------" << endl;
return 0;
}
IN-LAB EXPECTED OUTPUT
Canada Revenue Agency Account App
=================================
Checking constants
---------------------------------
max_name_length: 40
min_sin: 100000000
max_sin: 999999999
---------------------------------
Please enter your family name: Doe
Please enter your given name: Jane
Please enter your social insurance number (0 to quit): 234
Invalid input! Try again.
Please enter your social insurance number (0 to quit): 1234567890
Invalid input! Try again.
Please enter your social insurance number (0 to quit): 193456787
----------------------------------------
Testing the display function
----------------------------------------
Family Name: Doe
Given Name : Jane
CRA Account: 193456787
----------------------------------------
The at-home section of this workshop upgrades your CRA_Account module to im-prove the validation and to track the balance owing or refund due on the account over several years. Copy the original module to your at-home directory and add the following:
In your CRA_Account.h header file, predefine the following constant as an integer:
Add the following attributes to your CRA_Account class:
Declare the following public member function in your class definition:
Modify the definitions of the following public member functions:
SIN 193 456 787
_______________|
check digit is 7
add first set of alternates to themselves
9 4 6 8
9 4 6 8
18 8 12 16
add the digits of each sum 1+8+8+1+2+1+6 = 27
add the other alternates 1+3+5+7 = 16
total = 43
Next highest integer multiple of 10 = 50
Difference = 7
Matches the check digit, therefore this number is a valid SIN
Family Name: FAMILY_NAME< ENDL>
Given Name : GIVEN_NAME< ENDL>
CRA Account: SIN< ENDL>
Year (YEAR) balance owing: AMOUNT< ENDL>
Family Name: FAMILY_NAME< ENDL>
Given Name : GIVEN_NAME< ENDL>
CRA Account: SIN< ENDL>
Year (YEAR) refund due: AMOUNT< ENDL>
Family Name: FAMILY_NAME< ENDL>
Given Name : GIVEN_NAME< ENDL>
CRA Account: SIN< ENDL>
Year (YEAR) No balance owing or refund due! < ENDL>
Account object is empty!< ENDL>
AT-HOME MAIN MODULE
#include < iostream>
#include "CRA_Account.h"
#include "CRA_Account.h" // intentional
using namespace std;
using namespace sict;
int main() {
CRA_Account myCRA;
int sin;
bool quit = false;
char familyName[max_name_length + 1];
char givenName[max_name_length + 1];
cout << "Canada Revenue Agency Account App" << endl
<< "=================================" << endl << endl;
do {
cout << "Please enter your family name: ";
cin.getline(familyName, max_name_length);
cout << "Please enter your given name: ";
cin.getline(givenName, max_name_length);
cout << "Please enter your social insurance number (0 to quit): ";
cin >> sin;
cin.ignore();
if (sin != 0) {
myCRA.set(familyName, givenName, sin);
if (myCRA.isEmpty()) {
cout << "Invalid input! Try again." << endl;
}
else {
int year;
double balance;
do {
cout << "Please enter the year of your tax return (0 to quit): ";
cin >> year;
cin.ignore();
if (year != 0) {
cout << "Please enter the balance owing on your tax return (0 to quit): ";
cin >> balance;
cin.ignore();
myCRA.set(year, balance);
}
} while (year != 0);
quit = true;
}
}
else {
quit = true;
}
} while (!quit);
cout << "----------------------------------------" << endl;
cout << "Testing the display function" << endl;
cout << "----------------------------------------" << endl;
myCRA.display();
cout << "----------------------------------------" << endl;
return 0;
}
AT-HOME EXPECTED OUTPUT
Canada Revenue Agency Account App
=================================
Please enter your family name: Doe
Please enter your given name:
Please enter your social insurance number (0 to quit): 193456787
Invalid input! Try again.
Please enter your family name: Doe
Please enter your given name: Jane
Please enter your social insurance number (0 to quit): 123456789
Invalid input! Try again.
Please enter your family name: Doe
Please enter your given name: Jane
Please enter your social insurance number (0 to quit): 193456787
Please enter the year of your tax return (0 to quit): 2014
Please enter the balance owing on your tax return (0 to quit): 34.56
Please enter the year of your tax return (0 to quit): 2015
Please enter the balance owing on your tax return (0 to quit): -1234
Please enter the year of your tax return (0 to quit): 2016
Please enter the balance owing on your tax return (0 to quit): 1.23
Please enter the year of your tax return (0 to quit): 2013
Please enter the balance owing on your tax return (0 to quit): -0.12
Please enter the year of your tax return (0 to quit): 0
----------------------------------------
Testing the display function
----------------------------------------
Family Name: Doe
Given Name : Jane
CRA Account: 193456787
Year (2014) balance owing: 34.56
Year (2015) refund due: 1234.00
Year (2016) No balance owing or refund due!
Year (2013) No balance owing or refund due!
----------------------------------------
REFLECTION
Study your final solution, reread the related parts of the course notes, and make sure that you have understood the concepts covered by this workshop. This should take no less than 30 minutes of your time.
Create a file named reflect.txt that contains your detailed description of the topics that you have learned in completing this workshop and mention any issues that caused you difficulty. Include in your explanationbut do not limit it tothe following points: