-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabE.cpp
More file actions
104 lines (90 loc) · 3.17 KB
/
LabE.cpp
File metadata and controls
104 lines (90 loc) · 3.17 KB
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
//============================================================================
// Name : Test.cpp
// Author : Jenny Meadowcroft
// Version :
// Copyright : Your copyright notice
// Description : This is my C++ driver that tests the basic function of the account class, including calculate payment. WOW!!
//============================================================================
#include <iostream>
#include "Account.h"
#include <algorithm>
using namespace std;
bool isBalanceLessThan(Account* first, Account* second);
bool isAvailableLessThan(Account* first, Account* second);
int main() {
Account myAccount("Jenny Meadowcroft",400,3000);
cout << "The account of " << myAccount.getOwnerName() << " has a balance of " << myAccount.getCreditBalance() <<
" with an available credit of " << myAccount.getAvailableCredit() << "." << endl;
cout << "Enter 5 numbers separated by spaces" << endl;
Account Accounts[5] = {Account("Bobby Frank", 200, 3500),
Account("Billy Frank", 300, 1000),
Account("Rebecca Frank", 1000, 1500),
Account("Anna Frank", 800, 500),
Account("Renee Frank", 700, 3500)};
Account* AmountOwed[5];
Account* AmountAvailable[5];
for(int i = 0; i < 5; i++)
{
AmountOwed[i] = &Accounts[i];
AmountAvailable[i] = &Accounts[i];
}
sort(AmountOwed, AmountOwed+ 5, isBalanceLessThan);
sort(AmountAvailable, AmountAvailable+ 5, isAvailableLessThan);
bool going = true;
bool retrieve = true;
char selected;
Account** whichIndexToUse;
do{
cout << "Would you like to view the unsorted accounts (type U), sorted by balance (type B), "
"sorted by available credit (type A), or exit (type E)." << endl;
cin >> selected;
if(selected == "U" || selected == "u"){
for(int i = 0; i < 5; i++)
{
cout << i << " Location- " << &Accounts[i] << endl
<<" Name- " << Accounts[i].getOwnerName() << endl << " Balance- " << Accounts[i].getCreditBalance()
<< endl << " Available Credit- " << AmountOwed[i]->getAvailableCredit() << endl;
}
retrieve = false;
}
else if(selected == "B" || selected == "b"){
whichIndexToUse = AmountOwed;
retrieve = true;
}
else if(selected == "A" || selected == "a"){
whichIndexToUse = AmountAvailable;
retrieve = true;
}
else if(selected == "E" || selected == "e"){
going = false;
retrieve = false;
}
else{
cout << "Not a valid response. Please try again." << endl;
retrieve = false;
}
if(retrieve){
}
} while(going);
for(int i = 0; i < 5; i++)
{
cout << i << " Location- " << &AmountOwed[i] << " " << AmountOwed[i] << " " << &*AmountOwed[i]<< endl
<<" Name- " << AmountOwed[i]->getOwnerName() << endl << " Balance- " << AmountOwed[i]->getCreditBalance()
<< endl << " Available Credit- " << AmountOwed[i]->getAvailableCredit() << endl;
}
return 0;
}
bool isBalanceLessThan(Account* first, Account* second){
bool isSmaller = true;
if((*first).getCreditBalance() > (*second).getCreditBalance()) {
isSmaller = false;
}
return isSmaller;
}
bool isAvailableLessThan(Account* first, Account* second){
bool isSmaller = true;
if((*first).getAvailableCredit() > (*second).getAvailableCredit()) {
isSmaller = false;
}
return isSmaller;
}