balance.cpp
资源名称:balance.zip [点击查看]
上传用户:yxdoors
上传日期:2022-07-15
资源大小:1k
文件大小:2k
源码类别:
金融证券系统
开发平台:
C/C++
- #include <iostream>
- using namespace std;
- void printMonth(int);
- int main () {
- double amount, start, end, current, max, min;
- double depTotal, checkTotal, atmTotal;
- int mon, day, year;
- int mon1, day1, year1;
- int mon2, day2, year2;
- int checknum, deposits, checks, atm;
- int count = 0;
- deposits = checks = atm = 0;
- depTotal = checkTotal = atmTotal = 0;
- // Read starting balance
- cin >> start;
- max = min = current = start;
- // Read year
- cin >> year;
- while (year != -1) {
- // Read rest of line
- cin >> mon >> day >> amount;
- if (count == 0) {
- mon1 = mon2 = mon;
- day1 = day2 = day;
- year1 = year2 = year;
- }
- else {
- mon2 = mon;
- day2 = day;
- year2 = year;
- }
- count++;
- // Check for positive or negative amount
- if (amount < 0) {
- cin >> checknum;
- if (checknum == 0) {
- atm++;
- atmTotal -= amount;
- }
- else {
- checks++;
- checkTotal -= amount;
- }
- }
- else {
- deposits++;
- depTotal += amount;
- }
- // Update current balance
- current += amount;
- // Determine if high or low
- if (current > max)
- max = current;
- else if (current < min)
- min = current;
- // Read next year
- cin >> year;
- }
- // Print results
- cout << "Starting Balance: " << start << endl;
- cout << "Ending Balance: " << current << "nn";
- cout << "Date of first transaction: ";
- printMonth(mon1);
- cout << " " << day1 << ", " << year1 << endl;
- cout << "Date of last transaction: ";
- printMonth(mon2);
- cout << " " << day2 << ", " << year2 << "nn";
- cout << "# of Deposits: " << deposits << ". Total: $" << depTotal << endl;
- cout << "# of Checks: " << checks << ". Total: $" << checkTotal << endl;
- cout << "# of ATM Withdrawals: " << atm << ". Total: $" << atmTotal << "nn";
- cout << "Minimum balance during this period: $" << min << endl;
- cout << "Maximum balance during this period: $" << max << endl;
- return(0);
- }
- void printMonth(int mon) {
- if (mon == 1) cout << "January";
- else if (mon == 2) cout << "February";
- else if (mon == 3) cout << "March";
- else if (mon == 4) cout << "April";
- else if (mon == 5) cout << "May";
- else if (mon == 6) cout << "June";
- else if (mon == 7) cout << "July";
- else if (mon == 8) cout << "August";
- else if (mon == 9) cout << "September";
- else if (mon == 10) cout << "October";
- else if (mon == 11) cout << "November";
- else cout << "December";
- }