Recent Question/Assignment

CSC2402 Assignment 3
Full mark = 100% and is equivalent to 10 % of course mark.
Submit your assignment on-line using the course web page.
Assignment 3 consists of three tasks:
• For task 1, submit randomInt.cpp randomInt.h, and random_app.cpp and task1.txt.
• For task 2, submit serial.cpp serial.h, and serial_app.cpp and task2.txt.
• For task 3, submit bankacct.cpp, bankacct.h, and bankUSQ_app.cpp and task3.txt.
RandomInt and Serial class files should be the same as in task 1 and 2.
The .cpp file should have the program code and comments about the algorithm and the coding. We may compile the .cpp files if required. The documentation files should contain the compilation messages and sample runs for each application program. All files must be in pure text format. No PDF, HTML, Word files, Open Office files, RTF etc. and no compression or archiving such as zip, rar, tar etc (unless absolutely necessary do to Moodle checks) .
If you are using Codelite, the compilation messages can be copied and pasted with the usual crtl-c and crtl-v. For output of sample runs, right click the title bar of the command window, select EDIT/MARK and then highlight the output. With the output selected, right click the title bar of the command window, select EDIT/COPY. Position your cursor to a (new) text file opened in a text editor such as Notepad, and crtl-v will paste the copied output to the text file.
If you are using MinGW, right click the title bar of the command window; select EDIT/MARK and then high light the output. With the output selected, right click the title bar of the command window, select EDIT/COPY. Position your cursor to a (new) text file opened in a text editor such as Notepad, and crtl-v will paste the copied output to the text file.
If you are using Linux, you can cut and paste the output on the terminal window into a text such as vim.
SUBMIT THE COMMANDS USED TO COMPILE AND RUN.

Task 1 (10%)
Implement class RandomIntusing randomInt.cpp and randomInt.h.
For the RandomInt class:
• The function call operator is overloaded and will generate a random number each time the operator is used.
• Objects can be created with the lower and upper bound of the random number specified.
• Objects can also be created without the lower and upper bound of the random number specified. In this case, the upper and lower bound are taken as 1000 and 9999 respectively.
• The function operator of an object from the class is expected to generate a different succession of results every time the application is run.
Implement an application random_app.cpp which creates a RandomInt object R, and use it to generate 10 random numbers of 4 digits (1000 – 9999). It will then create another RandomInt object r, and use it to generate another 10 random numbers of 3 digits (100 – 999).
Your application should generate different sets of random numbers each time the application is run.
Submit randomInt.cpp randomInt.h, and random_app.cpp and task1.txt.
Marking Scheme:
Criteria Marks
Class RandomInt implemented correctly 2%
Using class RandomInt correctly 1%
Program compiles and runs correctly 5%
Sample runs for programs which runs correctly 1%
Program layout for programs which runs correctly 1%

Task 2 (25%)
Implement class Serial using serial.cpp and serial.h:
• The function call operator is overloaded and will generate a sequential integer each time the operator is used.
• The object can be created with the sequence start value specified.
Implement an application serial_app.cpp which creates a Serial object S, and use it to generate 10 serial number starting from 3407 and then another 10 serial numbers staring from 2402.
Submit serial.cpp serial.h, and serial_app.cpp and task2.txt.
Marking Scheme:
Criteria Marks
Class Serial implemented correctly 10%
Using class Serial correctly 3%
Program compiles and runs correctly 10%
Sample runs for programs which runs correctly 1%
Program layout for programs which runs correctly 1%

Task 3 (65%)
Implement class BankAcct, for Bank of USQ, using bankacct.cpp and bankacct.h:
• The BSB for Bank of USQ at Towoomba is 324-001.
• A BankAcct object will have a 3 digit bank account number larger than 100 which is a serial number generated by a Serial object. E.g. 324-001-101, 324-001-102,324-001-103 are the first three possible bank account number for Bank of USQ.
• A BankAcct object will have a bank account pin code which is a 4 digit random number generated by a RandomInt object.
• Class BankAcct should provide a member function to screen display the bank BSB plusaccount number and the pin code.
Implement an application bankUSQ_app.cpp:
• It will read bankUSQ_account.txt and print out all accounts and pins from the file.
• Itwill ask user input for the number of bank accounts to generate, and the starting account number.
• Uses class Serial and class RandomInt to generate the account number and the pin code.
• Create BankAcct objects to hold the account number and pin code.
• The BSB (324-001) can be hard coded for screen display only. You do not need to write BSB as part of the account number in bankUSQ_account.txt.
• All generated bank accounts will be store in a vector.
• Before the application exits, it will append the generated accounts to an existing text file named bankUSQ_account.txt.You will need to create an empty bankUSQ_account.txt before you run the application for the first time.
• Repeat the above steps until the number of bank accounts to generate is 0.
• Assume that all bank accounts generated in each call of the application are unique and not overlapping.
Use Exception to check
• The number of accounts to be created is less than 10.(Assume no negative integers entered.)
• If the input is not valid, the program will ask for user input again.
• You have to use BankError class which is derived from logic_error for exception handling.
• Implement BankError in bankUSQ_app.cpp.
Submit bankacct.cpp, bankacct.h, and bankUSQ_app.cpp and task3.txt. RandomInt class and Serial class files are the same as in Task 1 and 2.

/* Expected output
// bankUSQ_account.txt is empty
Account number: 324-001-1975521678
Pin Code: 0
// 13 is too many, ask for input again
Enter the number of bank account ( 10), 0 to quit:
13
Too many accounts requested. You requested 13 account numbers. Enter the number
of bank account ( 10), 0 to quit:
// 2 is OK
Enter the number of bank account ( 10), 0 to quit:
2
Enter the start value of account number:
111
Account number: 324-001-111
Pin Code: 8327
Account number: 324-001-112
Pin Code: 3620
// another 2
Enter the number of bank account ( 10), 0 to quit:
2
Enter the start value of account number:
222
Account number: 324-001-222
Pin Code: 8350
Account number: 324-001-223
Pin Code: 7554
Enter the number of bank account ( 10), 0 to quit:
0
Quit ...
c a
// There are 4 accounts in bankUSQ_account.txt
Account number: 324-001-111
Pin Code: 8327
Account number: 324-001-112
Pin Code: 3620
Account number: 324-001-222
Pin Code: 8350
Account number: 324-001-223
Pin Code: 7554
// too many
Enter the number of bank account ( 10), 0 to quit:
45
Too many accounts requested. You requested 45 account numbers. Enter the number
of bank account ( 10), 0 to quit:
// 3 is OK
Enter the number of bank account ( 10), 0 to quit:
3
Enter the start value of account number:
333
Account number: 324-001-333
Pin Code: 8435
Account number: 324-001-334
Pin Code: 6869
Account number: 324-001-335
Pin Code: 5797
Enter the number of bank account ( 10), 0 to quit:
0
Quit ...
// there are 7 accounts in bankUSQ_account.txt now
*/
/* bankUSQ_account.txt
111
8327
112
3620
222
8350
223
7554
333
8435
334
6869
335
5797
*/
Marking Scheme:
Criteria Marks
Class BankAcct implemented and used correctly 8%
Class BankError implemented and used correctly 8%
Class RandomInt and class Serial used correctly 8%
Program compiles and runs correctly 35%
Comments for programs which runs correctly 2%
Sample runs for programs which runs correctly 2%
Program layout for programs which runs correctly 2%
--- End of Assignment 3 ---