CPP Exercises1
CPP Exercises1
Write a program that, given a date, three ints (for example, 11 27 1997), will print the number
of that day within its year: i.e. Jan 1st is always 1, Dec 31st is either 365 or 366.
2. Write a program to manage 100 bank accounts. The details of an account should be stored in
a class. Use member functions for the transactions on the accounts. The accounts have numbers
ranging from 1001 to 1100 (decimal). There are several types of transactions, which the program
will read. If allowed, the program may modify the account balance. Otherwise a warning
message will be printed. The dialogue for the transactions, have the following forms:
In the following, the bold type represents questions the program types to the user. Each response
to the transaction type question is a single character. Any attempted illegal transaction causes an
error message. Amounts are in dollars and can have 0, 1 or 2 digits after the point: 2765 or 123.4
or 8864.57:
Interaction Explanation
Open an account, giving the initial deposit.
Transaction type?: O
Allowed if less than 100 accounts now open.
Initial deposit?: amount
Prints the new account number.
Transaction type?: B A Balance inquiry, prints the account number
Account number?: account_number and the balance, only allowed if the account is open.
Transaction type?: D
A Deposit, prints the account number
Account number?: account_number
and new balance, only allowed if account open.
Amount?: amount
Transaction type?: W A Withdrawal, only allowed if account open
Account number?: account_number and sufficient funds available, prints
Amount?: amount account number and new balance.
Transaction type?: C Close the account. Only allowed if account
Account number?: account_number is open.
Transaction type?: I Compute interest at given % rate.
Interest rate?: interest_rate and apply to all accounts
Transaction type?: P Print all the account numbers and amounts.
Transaction type?: E Close all accounts and exit program
3. Add pin numbers to the bank accounts and add a special pin number for the bank manager.
Add a transaction type S to open the bank. Only the manager should be allowed to do
transactions S, P, I, and E. For each transaction, the computer must ask for the pin number. In an
Open transaction, the user chooses the pin number for the account.
4. Modify your bank program to store the accounts in a file when the program closes
(transaction E) and to restore the accounts from the file when the bank is opened (transaction S).
5. Create a class date and overload the << and >> operators for input and output of dates (operator>>
and operator<<). Dates should be output in the form 2013-01-10. The input operator should accept dates
in the same format. Overload the operator + and to add or subtract an integer from the date. That is
2014-02-26 + 5 should output 2014-03-02 and 2014-02-01 3 should give 2014-01-30.