SlideShare a Scribd company logo
1 of 23
Download to read offline
I am having trouble writing the individual files for part 1, which is as follows:
part 1
Purpose
This assignment reviews object-oriented programming concepts such as classes, methods,
constructors, accessor methods, and access modifiers. It makes use of an array of objects as a
class data member, and introduces the concept of object serialization or "binary I/O".
Set Up
(Yes, these commands are rather tedious to type repeatedly. Part 2 of this assignment introduces
a new technique for compiling and linking your program files called a makefile. Makefiles
require a bit more work up front, but save a lot of typing at the command line once the makefile
has been created.)
As in Assignment 1, you should create a subdirectory to hold your files for Assignment 2.
In that directory, make a symbolic link to the data file for this part of the assignment:
In this assignment, you will be creating several source code and header files, as described below.
You can create each of these files separately using the nano editor, just as you did on Assignment
1.
To compile and link the program you've created, type:
Once you've added the AccountDB class, you should type:
To run the executable file created by the previous command, type:
Program
For this assignment, you will need to write three source code files as well as two header files.
Each of these files is relatively short, but many inexperienced programmers are overwhelmed by
the idea of writing a program as multiple files. "Where do I start?!!" is a common refrain. This
assignment sheet attempts to walk you through the steps of writing a multi-file program.
The steps outlined below should not be thought of as a purely linear process, but rather an
iterative one - For example, work a little on Step 1, then a little on Step 2, then test what you've
written (Step 3).
Step 1: Write the CreditAccount class declaration
The CreditAccount class represents information about a credit card account. The code for the
CreditAccount class will be placed in two separate files, which is the norm for non-template C++
classes.
The header file for a class contains the class declaration, including declarations of any data
members and prototypes for the methods of the class. The name of the header file should be of
the form ClassName.h (for example, CreditAccount.h for the header file of theCreditAccount
class).
A skeleton for the CreditAccount.h file is given below. As shown, a header file should begin and
end with header guards to prevent it from accidentally being #included more than once in the
same source code file (which would produce duplicate symbol definition errors). The symbol
name used in the header guards can be any valid C++ name that is not already in use in your
program or the C/C++ libraries. Using a name of the format CLASSNAME_H (like
CREDIT_ACCOUNT_H in the code below) is recommended to avoid naming conflicts.
Data Members
The CreditAccount class should have the following private data members:
an account number (a char array with room for 19 characters PLUS the null character, i.e. 20
elements total)
a customer name (a char array with room for 20 characters PLUS the null character)
a credit limit (a double variable)
a current account balance (a double variable)
Note: Make that sure you code your data members in THE EXACT ORDER LISTED ABOVE
and with THE EXACT SAME DATA TYPES. If you use float instead of double or only make
the name array 20 characters long instead of 21, your final program will not work correctly!
C++11 Initialization Option for Data Members
C++11 adds the ability to initialize the non-static data members of a class at the time you declare
them using a "brace-or-equal" syntax. This is very convenient, and can eliminate most or all of
the code from your default constructor. Here are a few examples of the kind of initializations you
can do in a class declaration:
Feel free to use this option if you want to.
Method Prototypes
The CreditAccount class declaration should (eventually) contain public prototypes for all of the
methods in the CreditAccount.cpp source code file described in Step 2 below.
Step 2: Write the CreditAccount class implementation
The source code file for a class contains the method definitions for the class. The name of the
source code file should be of the form ClassName.cpp or ClassName.cc (for example,
CreditAccount.cpp for the source code file of the CreditAccount class).
The CreditAccount class implementation should (eventually) contain definitions for all of the
methods described below. Make sure to #include "CreditAccount.h" at the top of this file.
CreditAccount default constructor - This "default" constructor for the CreditAccount class takes
no parameters. Like all C++ constructors, it does not have a return data type.
This method should set the account number and customer name data members to "null strings".
This can be done by copying a null string literal ("") into the character array using strcpy() or
by setting the first element of the array to a null character ('0'). The credit limit and account
balance data members should be set to 0.
(If you're working in C++11 and you initialized the data members at declaration as described
above under C++11 Initialization Option for Data Members, this method's body can be empty.
You still need to code the method though, even though it won't actually do anything.)
Alternate CreditAccount constructor - Write another constructor for the CreditAccount class that
takes four parameters: 1) a character array that contains a new account number, 2) a character
array that contains a new customer name, 3) a double variable that contains a new credit limit,
and 4) a double variable that contains a new balance. DO NOT GIVE THESE PARAMETERS
THE SAME NAMES AS YOUR DATA MEMBERS.. Like all C++ constructors, this
constructor does not have a return data type.
Use strcpy() to copy the new account number parameter into the account number data member
and the new customer name parameter into the customer name data member. The new credit
limit and new account balance parameters can be assigned to the corresponding data members.
getAccountNumber() - This accessor method takes no parameters. It should return the account
number data member. In C++, the usual return data type specified when you are returning the
name of a character array is char* or "pointer to a character" (since returning an array's name
will convert the name into a pointer to the first element of the array, which in this case is data
type char.
getName() - This accessor method takes no parameters. It should return the customer name data
member.
getLimit() - This accessor method takes no parameters. It will have a return data type of double.
It should return the credit limit data member.
getBalance() - This accessor method takes no parameters. It will have a return data type of
double. It should return the account balance data member.
processPayment() - This method takes one parameter, a double payment amount. It returns
nothing. The payment amount should be subtracted from the current account balance data
member. (Note that it is possible to have a negative balance on an account as a result of
overpayment.)
processCharge() - This method takes one parameter, a double charge amount. It returns a
Boolean value. If the charge amount plus the current account balance is greater than the credit
limit, the method should return false without altering the balance (because this charge has been
declined). Otherwise, the charge amount should be added to the account balance and the method
should return true.
print() - This method takes no parameters and returns nothing. The method should print the
values of the data members for the account in a format similar to the following:
If the balance is negative, it should be printed as a positive number but followed by the letters
"CR" (for credit). For example, the sample output shown above is for an account with a balance
of -127.65.
Step 3: Test and debug the CreditAccount class
As you write your declaration and implementation of the CreditAccount class, you should begin
testing the code you've written. Create a basic main program called assign2.cpp that tests your
class. This is not the final version of assign2.cpp that you will eventually submit. In fact, you'll
end up deleting most (or all) of it by the time you're done with the assignment. An example test
program is given below.
You do not have to have written all of the methods for the CreditAccount class before you begin
testing it. Simply comment out the parts of your test program that call methods you haven't
written yet. Write one method definition, add its prototype to the class declaration, uncomment
the corresponding test code in your test program, and then compile and link your program. If you
get syntax errors, fix them before you attempt to write additional code. A larger amount of code
that does not compile is not useful - it just makes debugging harder! The goal here is to
constantly maintain a working program.
Once your CreditAccount class has been thoroughly tested and debugged, it's time to write the
second class for this assignment.
Step 4: Write the AccountDB class declaration
The AccountDB class represents a database of CreditAccount objects. Like the CreditAccount
class, the code for this class will be placed in two separate files.
Place the class declaration in a header file called AccountDB.h. Like the file CreditAccount.h
you wrote in Step 1, this file should begin and end with header guards to prevent it from
accidentally being #included more than once in the same source code file.
After the header guard at the top of the file but before the class definition, make sure to #include
"CreditAccount.h".
Data Members
The AccountDB class should have the following two private data members:
An array of 20 CreditAccount objects
An integer that specifies the number of CreditAccount objects actually stored in the array
Note: Once again, make sure you code your data members in THE EXACT ORDER LISTED
ABOVE and with THE EXACT SAME DATA TYPES.
Method Prototypes
The AccountDB class declaration should (eventually) contain public prototypes for all of the
methods in the AccountDB.cpp source code file described in Step 5 below.
Step 5: Write the AccountDB class implementation
The AccountDB class implementation should (eventually) contain definitions for all of the
methods described below. Make sure to #include "AccountDB.h" at the top of this file.
AccountDB default constructor - This "default" constructor for the AccountDB class takes no
parameters. Like all C++ constructors, it does not have a return data type.
This constructor is called to create an empty database, so this method should set the number of
accounts data member to 0.
(As with the CreditAccount class, if you initialize the number of accounts data member to 0
when you declare it, this method's body can be empty. You still need to code the method with an
empty body.)
Alternate AccountDB constructor - Write a second constructor for the AccountDB class that
takes one parameter: a C++ string that contains the name of an existing database file. Like all
C++ constructors, this constructor does not have a return data type.
This constructor should do the following:
Declare an input file stream variable (the code below assumes it is named inFile).
Open the file stream for binary input. Check to make sure the file was opened successfully as
usual.
Read the database file into your AccountDB object. You can do this with a single statement:
Close the file stream.
print() - This method takes no parameters and returns nothing.
This method should first print a descriptive header line (e.g., "Credit Card Account Listing"). It
should then loop through the array of CreditAccount objects and print each of the elements that
contains account data, with a blank line between each account. Here we see some of the power of
object-oriented programming: since each element of the array is an object, we can call a method
for that object. We've already written a print() method for the CreditAccount class, so printing
an element of the account array is as easy as calling print() for the array element. The syntax for
calling a method using an array element that is an object is pretty straightforward:
Step 6: Write the main program
Since most of the logic of the program is embedded in the two classes you wrote, the main()
routine logic is extremely simple.
Create an AccountDB object using the alternate constructor you wrote. Pass the filename string
literal "accounts" as an argument to the constructor.
Call the print() method for the AccountDB object.
here is part 2 and what I have coded for it:
Part 2
Purpose
This part of the assignment introduces the insertion sort and binary search algorithms. It also
introduces the use of makefiles for compiling and linking your programs.
Set Up
In your Assignment 2 directory, make a symbolic link to the data file for this part of the
assignment:
In this assignment, you will be creating several source code and header files, as described below.
You can create each of these files separately using the nano editor, just as you did on Assignment
1.
Once you've written a makefile for your program, you can compile and link it by simply typing:
Running the executable file is unchanged from Part 1.
To remove the executable and object code files for your program (conserving disk space), you
can type:
Program
For this part of the assignment, you'll need to write one new file and then modify two of the files
you wrote for Part 1.
Step 1: Write a makefile
The file named makefile tells the make utility how to build the final executable file from your
collection of C++ source code and header files. The makefile for this assignment is given in its
entirety below. Makefiles for future assignments will follow this basic pattern.
IMPORTANT NOTE: The commands that appear in the makefile below MUST be indented as
shown. Furthermore, the indentation MUST be done using a tab character, not spaces. If you
don't indent your makefile commands, or indent using spaces, your makefile WILL NOT
WORK.
Once you've written the file makefile, try using the make utility to compile and link your
program.
Step 2: Add the following methods to the AccountDB class
sortAccounts() - This method takes no parameters and returns nothing.
This method should sort the array of CreditAccount objects in ascending order by account
number using the insertion sort algorithm.
The sort code linked to above sorts an array of integers called numbers of size size. You will
need to make a substantial number of changes to that code to make it work in this program:
This will be a method, not a function. Change the parameters for the method to those described
above.
In the method body, change the data type of bucket to CreditAccount. This temporary storage
will be used to swap elements of the array of CreditAccount objects.
In the method body, change any occurrence of numbers to the name of your array of
CreditAccount objects and size to numAccounts (or whatever you called the data member that
tracks the number of valid CreditAccount objects stored in the array).
The comparison of accountArray[j-1] and bucket will need to use the C string library function
strcmp() to perform the comparison. Also, you'll need to use the getAccountNumber() method to
access the accountNumber data member within each CreditAccountobject. The final version of
the inner for loop should look something like this:
It is legal to assign one CreditAccount object to another; you don't need to write code to copy
individual data members.
Add a call to the sortAccounts() method to the end of the alternate constructor you wrote for the
AccountDB class. This will sort the array of CreditAccount objects that were read in from the
input file.
searchForAccount() - This method should take one parameter: a character array containing the
account number code of the CreditAccount to search for (searchNumber). The method should
return an integer.
The logic for this method is a variation of the binary search of a sorted list strategy.
As usual, you'll need to use strcmp() to perform the comparison of account numbers.
processTransactions() - This method should take one parameter: a C++ string containing the
name of a file of credit card transaction data. The method should return nothing.
The method should open the specified transaction file for input (not binary input - this file is a
text file). Make sure to test that the file was opened successfully; if it wasn't, print an error
message and exit the program.
Before reading any transactions, the function should print a report header and column headers.
The function should then read transaction data from the file until end of file is reached. A typical
transaction is shown below. The first field on the transaction record is the date of the transaction,
followed by an account number, then the transaction type ('C' for charge or 'P' for payment),
and finally a transaction amount.
Once all of the data for a given transaction has been read, call the searchForAccount() method to
search the accounts array for the account number given in the transaction. If the account number
is present in the array, then the transaction may be processed. For a payment, simply call the
processPayment() method for the object that contains a matching account number, passing it the
transaction amount. For a charge, call the processCharge() method for the object that contains a
matching account number, passing it the transaction amount.
For each transaction record processed, print a line in a transaction report with the data from the
record and the updated balance for that account. If the balance is negative, it should be printed as
a positive number but followed by the letters "CR". If the transaction account number was not
found in the account array or if a charge exceeded the account's credit limit (i.e., if the
processCharge() method returned false), print an appropriate error message instead of the
account balance.
After all transactions have been processed, close the transaction file.
Step 3: Add two method calls to the main program
The main() routine logic will now look like this:
Create an AccountDB object using the alternate constructor you wrote. Pass the filename string
"accounts" as an argument to the constructor.
Call the print() method for the AccountDB object.
Call the processTransactions() method for the AccountDB object. Pass the filename string
"transactions.txt" as an argument to the method.
Call the print() method for the AccountDB object.
And what I have for part 2, though it may not be correct:
# PROGRAM: assign2
# PROGRAMMER:
# LOGON ID:
# DATE DUE:
#
#include
#include
#include
#include
#define SIZE 20
#define ACCOUNTS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/accounts
#define TRANS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/transactions.txt
using namespace std;
class CreditAccount
{
public:
CreditAccount();
char* get_accountNumber();
float get_balance();
void process_payment( float );
bool process_charge( float );
void print();
private:
char acctNum[20];
char custName[21];
int expMonth;
int expYear;
float creditLimit;
float currentBal;
};
CreditAccount::CreditAccount()
{
acctNum[0] = '0';
custName[0] = '0';
expMonth = 0;
expYear = 0;
creditLimit = 0;
currentBal = 0;
}
char* CreditAccount::get_accountNumber()
{
return & acctNum[0];
}
float CreditAccount::get_balance()
{
return currentBal;
}
void CreditAccount::process_payment(float paymentAmt)
{
currentBal = currentBal - paymentAmt;
}
bool CreditAccount::process_charge( float chargeAmt )
{
if( ( chargeAmt + currentBal ) > creditLimit )
{
return false;
}
else
{
currentBal += chargeAmt;
return true;
}
}
void CreditAccount::print()
{
cout << left << showpoint << fixed << setprecision(2)
<< setw(22) << acctNum << setw(20) << custName;
if( expMonth < 10 )
{
cout << "0" << expMonth;
}
else
{
cout << expMonth;
}
cout << "/"<< setw(7) << expYear;
cout << right << setw(10) << creditLimit << setw(14);
if( currentBal < 0 )
{
currentBal = currentBal * (-1);
cout << currentBal << " CR" << endl;
}
else
cout << currentBal << endl;
}
// Function Prototypes:
int read_accounts( CreditAccount[] );
void print_accounts( CreditAccount[], int );
void process_transactions( CreditAccount[], int );
void sort_accounts( CreditAccount[], int );
int main()
{
CreditAccount creditArr[SIZE];
int validAccts = 0;
validAccts = read_accounts( creditArr );
sort_accounts(creditArr, validAccts);
print_accounts( creditArr, validAccts );
process_transactions( creditArr, validAccts );
print_accounts( creditArr, validAccts );
cout << endl;
system( "pause" );
return 0;
}
int read_accounts( CreditAccount Arr[] )
{
CreditAccount temp;
ifstream inFile;
int i = 0;
inFile.open( "ACCOUNTS", ios::binary );
if( inFile.fail() )
{
cout << "file failed to open";
exit( -1 );
}
inFile.read( (char * ) &temp, sizeof( temp ) );
while( inFile )
{
Arr[i] = temp;
i++;
inFile.read( (char * ) &temp, sizeof( temp ) );
}
inFile.close();
return i;
}
void print_accounts( CreditAccount Arr[], int validAccts )
{
int i;
cout << endl << " " << setw(48) << "Credit Account Listing" << endl << endl
<< setw(61) << "Credit" << setw(15) << "Account" << endl
<< "Account Number" << setw(12) << "Name" << setw(24)
<< "Exp. Date" << setw(10) << "Limit" << setw(16)
<< "Balance" << endl
<< "----------------------------------------------------------------------------"
<< endl << endl;
for( i = 0; i < validAccts; i++ )
{
Arr[i].print();
}
}
void process_transactions( CreditAccount Arr[], int validAccts)
{
bool notExceeded;
char* oldNum;
char acctNum[SIZE];
string date, type;
float amt, oldAmt, newAmt;
ifstream inFile;
int i = 0;
int j = 0;
inFile.open( "TRANS" );
if( inFile.fail() )
{
cout << "Error: File failed to open";
exit ( -1 );
}
cout << endl << " " << setw(48) << "Transaction Report" << endl << endl
<< "Date" << setw(10) << "Account" << setw(10) << "Type" << setw(10)
<< "Amount" << setw(15) << "New Balance" << endl << endl;
inFile >> date; // set first date
while( !inFile.eof() )
{
bool noMatch = true;
inFile.get();
for( i = 0; i < SIZE; i++ )
{
acctNum[i] = inFile.get(); // set 1st acc number
}
inFile >> type >> amt;
inFile.get();
for( i = 0; i < validAccts; i++ )
{
bool acctsMatch = true; //set acctsMatch to true
oldNum = Arr[i].get_accountNumber(); //get acctNum
//oldAmt = Arr[i].get_balance(); //get original balance from class
for( j = 0; (j < SIZE-1); j++ )
{
if( acctNum[j] != oldNum[j] )
{
acctsMatch = false;
}
}
if ( acctsMatch )
{
noMatch = false;
if( type == "P" )
{
Arr[i].process_payment( amt );
newAmt = Arr[i].get_balance();
cout << date << setw(3);
for(i = 0; i < SIZE; i++ )
{
cout << acctNum[i];
}
cout << " " << setw(3) << type << setw(10)
<< amt << setw(24);
if( newAmt < 0 ) //if negative balance, print as positive with CR appended
{
newAmt = newAmt * (-1);
cout << newAmt << " CR" << endl;
}
else
cout << newAmt << endl;
}
else if( type == "C" )
{
bool notExceeded = Arr[i].process_charge( amt );
newAmt = Arr[i].get_balance();
cout << date << setw(3);
for(i = 0; i < SIZE; i++ )
{
cout << acctNum[i];
}
if( notExceeded )
{
cout << " " << setw(3) << type << setw(10)
<< amt << setw(24) << newAmt << endl;
}
else //if credit limit exceeded print err message
{
cout << " " << setw(3) << type << setw(10)
<< amt << setw(35) << "*** Credit Limit Exceeded ***" << endl;
}
}
}
}
if( noMatch )
{
cout << date << setw(3);
for(i = 0; i < SIZE; i++)
{
cout << acctNum[i];
}
cout << " " << setw(3) << type << setw(10)
<< amt << setw(35) << "*** Invalid Account Number ***" << endl;
}
inFile >> date; // set the next date
}
inFile.close();
}
void sort_accounts( CreditAccount Arr[], int validAccts )
{
int i,j;
char* temp;
CreditAccount cred; // added
for(i = 1; i < validAccts; i++)
{
temp = Arr[i].get_accountNumber();
cred = Arr[i]; // assign here
j = i - 1;
for( ;(j > 0) && strcmp( temp, Arr[j].get_accountNumber() ) < 0; j-- )
{
Arr[j + 1] = Arr[j];
j--;
}
Arr[j + 1] = cred; // changed
}
}
Help would be appreciated, thank you.
Solution
#include
#include
#include
#include
#define SIZE 20
#define ACCOUNTS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/accounts
#define TRANS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/transactions.txt
using namespace std;
class CreditAccount
{
public:
CreditAccount();
char* get_accountNumber();
float get_balance();
void process_payment( float );
bool process_charge( float );
void print();
private:
char acctNum[20];
char custName[21];
int expMonth;
int expYear;
float creditLimit;
float currentBal;
};
CreditAccount::CreditAccount()
{
acctNum[0] = '0';
custName[0] = '0';
expMonth = 0;
expYear = 0;
creditLimit = 0;
currentBal = 0;
}
char* CreditAccount::get_accountNumber()
{
return & acctNum[0];
}
float CreditAccount::get_balance()
{
return currentBal;
}
void CreditAccount::process_payment(float paymentAmt)
{
currentBal = currentBal - paymentAmt;
}
bool CreditAccount::process_charge( float chargeAmt )
{
if( ( chargeAmt + currentBal ) > creditLimit )
{
return false;
}
else
{
currentBal += chargeAmt;
return true;
}
}
void CreditAccount::print()
{
cout << left << showpoint << fixed << setprecision(2)
<< setw(22) << acctNum << setw(20) << custName;
if( expMonth < 10 )
{
cout << "0" << expMonth;
}
else
{
cout << expMonth;
}
cout << "/"<< setw(7) << expYear;
cout << right << setw(10) << creditLimit << setw(14);
if( currentBal < 0 )
{
currentBal = currentBal * (-1);
cout << currentBal << " CR" << endl;
}
else
cout << currentBal << endl;
}
// Function Prototypes:
int read_accounts( CreditAccount[] );
void print_accounts( CreditAccount[], int );
void process_transactions( CreditAccount[], int );
void sort_accounts( CreditAccount[], int );
int main()
{
CreditAccount creditArr[SIZE];
int validAccts = 0;
validAccts = read_accounts( creditArr );
sort_accounts(creditArr, validAccts);
print_accounts( creditArr, validAccts );
process_transactions( creditArr, validAccts );
print_accounts( creditArr, validAccts );
cout << endl;
system( "pause" );
return 0;
}
int read_accounts( CreditAccount Arr[] )
{
CreditAccount temp;
ifstream inFile;
int i = 0;
inFile.open( "ACCOUNTS", ios::binary );
if( inFile.fail() )
{
cout << "file failed to open";
exit( -1 );
}
inFile.read( (char * ) &temp, sizeof( temp ) );
while( inFile )
{
Arr[i] = temp;
i++;
inFile.read( (char * ) &temp, sizeof( temp ) );
}
inFile.close();
return i;
}
void print_accounts( CreditAccount Arr[], int validAccts )
{
int i;
cout << endl << " " << setw(48) << "Credit Account Listing" << endl << endl
<< setw(61) << "Credit" << setw(15) << "Account" << endl
<< "Account Number" << setw(12) << "Name" << setw(24)
<< "Exp. Date" << setw(10) << "Limit" << setw(16)
<< "Balance" << endl
<< "----------------------------------------------------------------------------"
<< endl << endl;
for( i = 0; i < validAccts; i++ )
{
Arr[i].print();
}
}
void process_transactions( CreditAccount Arr[], int validAccts)
{
bool notExceeded;
char* oldNum;
char acctNum[SIZE];
string date, type;
float amt, oldAmt, newAmt;
ifstream inFile;
int i = 0;
int j = 0;
inFile.open( "TRANS" );
if( inFile.fail() )
{
cout << "Error: File failed to open";
exit ( -1 );
}
cout << endl << " " << setw(48) << "Transaction Report" << endl << endl
<< "Date" << setw(10) << "Account" << setw(10) << "Type" << setw(10)
<< "Amount" << setw(15) << "New Balance" << endl << endl;
inFile >> date; // set first date
while( !inFile.eof() )
{
bool noMatch = true;
inFile.get();
for( i = 0; i < SIZE; i++ )
{
acctNum[i] = inFile.get(); // set 1st acc number
}
inFile >> type >> amt;
inFile.get();
for( i = 0; i < validAccts; i++ )
{
bool acctsMatch = true; //set acctsMatch to true
oldNum = Arr[i].get_accountNumber(); //get acctNum
//oldAmt = Arr[i].get_balance(); //get original balance from class
for( j = 0; (j < SIZE-1); j++ )
{
if( acctNum[j] != oldNum[j] )
{
acctsMatch = false;
}
}
if ( acctsMatch )
{
noMatch = false;
if( type == "P" )
{
Arr[i].process_payment( amt );
newAmt = Arr[i].get_balance();
cout << date << setw(3);
for(i = 0; i < SIZE; i++ )
{
cout << acctNum[i];
}
cout << " " << setw(3) << type << setw(10)
<< amt << setw(24);
if( newAmt < 0 ) //if negative balance, print as positive with CR appended
{
newAmt = newAmt * (-1);
cout << newAmt << " CR" << endl;
}
else
cout << newAmt << endl;
}
else if( type == "C" )
{
bool notExceeded = Arr[i].process_charge( amt );
newAmt = Arr[i].get_balance();
cout << date << setw(3);
for(i = 0; i < SIZE; i++ )
{
cout << acctNum[i];
}
if( notExceeded )
{
cout << " " << setw(3) << type << setw(10)
<< amt << setw(24) << newAmt << endl;
}
else //if credit limit exceeded print err message
{
cout << " " << setw(3) << type << setw(10)
<< amt << setw(35) << "*** Credit Limit Exceeded ***" << endl;
}
}
}
}
if( noMatch )
{
cout << date << setw(3);
for(i = 0; i < SIZE; i++)
{
cout << acctNum[i];
}
cout << " " << setw(3) << type << setw(10)
<< amt << setw(35) << "*** Invalid Account Number ***" << endl;
}
inFile >> date; // set the next date
}
inFile.close();
}
void sort_accounts( CreditAccount Arr[], int validAccts )
{
int i,j;
char* temp;
CreditAccount cred; // added
for(i = 1; i < validAccts; i++)
{
temp = Arr[i].get_accountNumber();
cred = Arr[i]; // assign here
j = i - 1;
for( ;(j > 0) && strcmp( temp, Arr[j].get_accountNumber() ) < 0; j-- )
{
Arr[j + 1] = Arr[j];
j--;
}
Arr[j + 1] = cred; // changed
}
}

More Related Content

Similar to I am having trouble writing the individual files for part 1, which i.pdf

3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.netRavi Bansal
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 
Event Registration System Part 2
Event Registration System Part 2Event Registration System Part 2
Event Registration System Part 2Adolfo Nasol
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfNathan2rSPeakes
 
Bt0082 visual basic2
Bt0082 visual basic2Bt0082 visual basic2
Bt0082 visual basic2Techglyphs
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docxDIPESH30
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxaman341480
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdflonkarhrishikesh
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reportsquest2900
 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.docabdulhaq467432
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse studentsAbdur Rahim
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Warren0989
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net FundamentalsLiquidHub
 

Similar to I am having trouble writing the individual files for part 1, which i.pdf (20)

3 tier architecture in asp.net
3 tier architecture in asp.net3 tier architecture in asp.net
3 tier architecture in asp.net
 
Jazz
JazzJazz
Jazz
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
Event Registration System Part 2
Event Registration System Part 2Event Registration System Part 2
Event Registration System Part 2
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdf
 
Bt0082 visual basic2
Bt0082 visual basic2Bt0082 visual basic2
Bt0082 visual basic2
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdf
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Intro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm ReviewIntro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm Review
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
C programming languag for cse students
C programming languag for cse studentsC programming languag for cse students
C programming languag for cse students
 
Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...Solutions manual for c++ programming from problem analysis to program design ...
Solutions manual for c++ programming from problem analysis to program design ...
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Online CPP Homework Help
Online CPP Homework HelpOnline CPP Homework Help
Online CPP Homework Help
 
Ch03
Ch03Ch03
Ch03
 

More from mallik3000

Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfExplain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfmallik3000
 
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfExercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfmallik3000
 
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfestion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfmallik3000
 
Discuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfDiscuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfmallik3000
 
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfDiels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfmallik3000
 
Create a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfCreate a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfmallik3000
 
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfCompare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfmallik3000
 
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfChoose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfmallik3000
 
Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfmallik3000
 
Canon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfCanon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfmallik3000
 
Can someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfCan someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfmallik3000
 
Write a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfWrite a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfmallik3000
 
What happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfWhat happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfmallik3000
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfmallik3000
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
 
Why are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfWhy are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfmallik3000
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfmallik3000
 
What is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfWhat is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfmallik3000
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfmallik3000
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfmallik3000
 

More from mallik3000 (20)

Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfExplain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
 
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfExercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
 
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfestion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
 
Discuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfDiscuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdf
 
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfDiels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
 
Create a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfCreate a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdf
 
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfCompare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
 
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfChoose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
 
Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdf
 
Canon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfCanon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdf
 
Can someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfCan someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdf
 
Write a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfWrite a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdf
 
What happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfWhat happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdf
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Why are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfWhy are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdf
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdf
 
What is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfWhat is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdf
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdf
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdf
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 

I am having trouble writing the individual files for part 1, which i.pdf

  • 1. I am having trouble writing the individual files for part 1, which is as follows: part 1 Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data member, and introduces the concept of object serialization or "binary I/O". Set Up (Yes, these commands are rather tedious to type repeatedly. Part 2 of this assignment introduces a new technique for compiling and linking your program files called a makefile. Makefiles require a bit more work up front, but save a lot of typing at the command line once the makefile has been created.) As in Assignment 1, you should create a subdirectory to hold your files for Assignment 2. In that directory, make a symbolic link to the data file for this part of the assignment: In this assignment, you will be creating several source code and header files, as described below. You can create each of these files separately using the nano editor, just as you did on Assignment 1. To compile and link the program you've created, type: Once you've added the AccountDB class, you should type: To run the executable file created by the previous command, type: Program For this assignment, you will need to write three source code files as well as two header files. Each of these files is relatively short, but many inexperienced programmers are overwhelmed by the idea of writing a program as multiple files. "Where do I start?!!" is a common refrain. This assignment sheet attempts to walk you through the steps of writing a multi-file program. The steps outlined below should not be thought of as a purely linear process, but rather an iterative one - For example, work a little on Step 1, then a little on Step 2, then test what you've written (Step 3). Step 1: Write the CreditAccount class declaration The CreditAccount class represents information about a credit card account. The code for the CreditAccount class will be placed in two separate files, which is the norm for non-template C++ classes. The header file for a class contains the class declaration, including declarations of any data members and prototypes for the methods of the class. The name of the header file should be of the form ClassName.h (for example, CreditAccount.h for the header file of theCreditAccount
  • 2. class). A skeleton for the CreditAccount.h file is given below. As shown, a header file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file (which would produce duplicate symbol definition errors). The symbol name used in the header guards can be any valid C++ name that is not already in use in your program or the C/C++ libraries. Using a name of the format CLASSNAME_H (like CREDIT_ACCOUNT_H in the code below) is recommended to avoid naming conflicts. Data Members The CreditAccount class should have the following private data members: an account number (a char array with room for 19 characters PLUS the null character, i.e. 20 elements total) a customer name (a char array with room for 20 characters PLUS the null character) a credit limit (a double variable) a current account balance (a double variable) Note: Make that sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES. If you use float instead of double or only make the name array 20 characters long instead of 21, your final program will not work correctly! C++11 Initialization Option for Data Members C++11 adds the ability to initialize the non-static data members of a class at the time you declare them using a "brace-or-equal" syntax. This is very convenient, and can eliminate most or all of the code from your default constructor. Here are a few examples of the kind of initializations you can do in a class declaration: Feel free to use this option if you want to. Method Prototypes The CreditAccount class declaration should (eventually) contain public prototypes for all of the methods in the CreditAccount.cpp source code file described in Step 2 below. Step 2: Write the CreditAccount class implementation The source code file for a class contains the method definitions for the class. The name of the source code file should be of the form ClassName.cpp or ClassName.cc (for example, CreditAccount.cpp for the source code file of the CreditAccount class). The CreditAccount class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "CreditAccount.h" at the top of this file. CreditAccount default constructor - This "default" constructor for the CreditAccount class takes no parameters. Like all C++ constructors, it does not have a return data type. This method should set the account number and customer name data members to "null strings". This can be done by copying a null string literal ("") into the character array using strcpy() or
  • 3. by setting the first element of the array to a null character ('0'). The credit limit and account balance data members should be set to 0. (If you're working in C++11 and you initialized the data members at declaration as described above under C++11 Initialization Option for Data Members, this method's body can be empty. You still need to code the method though, even though it won't actually do anything.) Alternate CreditAccount constructor - Write another constructor for the CreditAccount class that takes four parameters: 1) a character array that contains a new account number, 2) a character array that contains a new customer name, 3) a double variable that contains a new credit limit, and 4) a double variable that contains a new balance. DO NOT GIVE THESE PARAMETERS THE SAME NAMES AS YOUR DATA MEMBERS.. Like all C++ constructors, this constructor does not have a return data type. Use strcpy() to copy the new account number parameter into the account number data member and the new customer name parameter into the customer name data member. The new credit limit and new account balance parameters can be assigned to the corresponding data members. getAccountNumber() - This accessor method takes no parameters. It should return the account number data member. In C++, the usual return data type specified when you are returning the name of a character array is char* or "pointer to a character" (since returning an array's name will convert the name into a pointer to the first element of the array, which in this case is data type char. getName() - This accessor method takes no parameters. It should return the customer name data member. getLimit() - This accessor method takes no parameters. It will have a return data type of double. It should return the credit limit data member. getBalance() - This accessor method takes no parameters. It will have a return data type of double. It should return the account balance data member. processPayment() - This method takes one parameter, a double payment amount. It returns nothing. The payment amount should be subtracted from the current account balance data member. (Note that it is possible to have a negative balance on an account as a result of overpayment.) processCharge() - This method takes one parameter, a double charge amount. It returns a Boolean value. If the charge amount plus the current account balance is greater than the credit limit, the method should return false without altering the balance (because this charge has been declined). Otherwise, the charge amount should be added to the account balance and the method should return true. print() - This method takes no parameters and returns nothing. The method should print the values of the data members for the account in a format similar to the following:
  • 4. If the balance is negative, it should be printed as a positive number but followed by the letters "CR" (for credit). For example, the sample output shown above is for an account with a balance of -127.65. Step 3: Test and debug the CreditAccount class As you write your declaration and implementation of the CreditAccount class, you should begin testing the code you've written. Create a basic main program called assign2.cpp that tests your class. This is not the final version of assign2.cpp that you will eventually submit. In fact, you'll end up deleting most (or all) of it by the time you're done with the assignment. An example test program is given below. You do not have to have written all of the methods for the CreditAccount class before you begin testing it. Simply comment out the parts of your test program that call methods you haven't written yet. Write one method definition, add its prototype to the class declaration, uncomment the corresponding test code in your test program, and then compile and link your program. If you get syntax errors, fix them before you attempt to write additional code. A larger amount of code that does not compile is not useful - it just makes debugging harder! The goal here is to constantly maintain a working program. Once your CreditAccount class has been thoroughly tested and debugged, it's time to write the second class for this assignment. Step 4: Write the AccountDB class declaration The AccountDB class represents a database of CreditAccount objects. Like the CreditAccount class, the code for this class will be placed in two separate files. Place the class declaration in a header file called AccountDB.h. Like the file CreditAccount.h you wrote in Step 1, this file should begin and end with header guards to prevent it from accidentally being #included more than once in the same source code file. After the header guard at the top of the file but before the class definition, make sure to #include "CreditAccount.h". Data Members The AccountDB class should have the following two private data members: An array of 20 CreditAccount objects An integer that specifies the number of CreditAccount objects actually stored in the array Note: Once again, make sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES. Method Prototypes The AccountDB class declaration should (eventually) contain public prototypes for all of the methods in the AccountDB.cpp source code file described in Step 5 below. Step 5: Write the AccountDB class implementation
  • 5. The AccountDB class implementation should (eventually) contain definitions for all of the methods described below. Make sure to #include "AccountDB.h" at the top of this file. AccountDB default constructor - This "default" constructor for the AccountDB class takes no parameters. Like all C++ constructors, it does not have a return data type. This constructor is called to create an empty database, so this method should set the number of accounts data member to 0. (As with the CreditAccount class, if you initialize the number of accounts data member to 0 when you declare it, this method's body can be empty. You still need to code the method with an empty body.) Alternate AccountDB constructor - Write a second constructor for the AccountDB class that takes one parameter: a C++ string that contains the name of an existing database file. Like all C++ constructors, this constructor does not have a return data type. This constructor should do the following: Declare an input file stream variable (the code below assumes it is named inFile). Open the file stream for binary input. Check to make sure the file was opened successfully as usual. Read the database file into your AccountDB object. You can do this with a single statement: Close the file stream. print() - This method takes no parameters and returns nothing. This method should first print a descriptive header line (e.g., "Credit Card Account Listing"). It should then loop through the array of CreditAccount objects and print each of the elements that contains account data, with a blank line between each account. Here we see some of the power of object-oriented programming: since each element of the array is an object, we can call a method for that object. We've already written a print() method for the CreditAccount class, so printing an element of the account array is as easy as calling print() for the array element. The syntax for calling a method using an array element that is an object is pretty straightforward: Step 6: Write the main program Since most of the logic of the program is embedded in the two classes you wrote, the main() routine logic is extremely simple. Create an AccountDB object using the alternate constructor you wrote. Pass the filename string literal "accounts" as an argument to the constructor. Call the print() method for the AccountDB object. here is part 2 and what I have coded for it: Part 2
  • 6. Purpose This part of the assignment introduces the insertion sort and binary search algorithms. It also introduces the use of makefiles for compiling and linking your programs. Set Up In your Assignment 2 directory, make a symbolic link to the data file for this part of the assignment: In this assignment, you will be creating several source code and header files, as described below. You can create each of these files separately using the nano editor, just as you did on Assignment 1. Once you've written a makefile for your program, you can compile and link it by simply typing: Running the executable file is unchanged from Part 1. To remove the executable and object code files for your program (conserving disk space), you can type: Program For this part of the assignment, you'll need to write one new file and then modify two of the files you wrote for Part 1. Step 1: Write a makefile The file named makefile tells the make utility how to build the final executable file from your collection of C++ source code and header files. The makefile for this assignment is given in its entirety below. Makefiles for future assignments will follow this basic pattern. IMPORTANT NOTE: The commands that appear in the makefile below MUST be indented as shown. Furthermore, the indentation MUST be done using a tab character, not spaces. If you don't indent your makefile commands, or indent using spaces, your makefile WILL NOT WORK. Once you've written the file makefile, try using the make utility to compile and link your program. Step 2: Add the following methods to the AccountDB class sortAccounts() - This method takes no parameters and returns nothing. This method should sort the array of CreditAccount objects in ascending order by account number using the insertion sort algorithm. The sort code linked to above sorts an array of integers called numbers of size size. You will need to make a substantial number of changes to that code to make it work in this program: This will be a method, not a function. Change the parameters for the method to those described above. In the method body, change the data type of bucket to CreditAccount. This temporary storage will be used to swap elements of the array of CreditAccount objects.
  • 7. In the method body, change any occurrence of numbers to the name of your array of CreditAccount objects and size to numAccounts (or whatever you called the data member that tracks the number of valid CreditAccount objects stored in the array). The comparison of accountArray[j-1] and bucket will need to use the C string library function strcmp() to perform the comparison. Also, you'll need to use the getAccountNumber() method to access the accountNumber data member within each CreditAccountobject. The final version of the inner for loop should look something like this: It is legal to assign one CreditAccount object to another; you don't need to write code to copy individual data members. Add a call to the sortAccounts() method to the end of the alternate constructor you wrote for the AccountDB class. This will sort the array of CreditAccount objects that were read in from the input file. searchForAccount() - This method should take one parameter: a character array containing the account number code of the CreditAccount to search for (searchNumber). The method should return an integer. The logic for this method is a variation of the binary search of a sorted list strategy. As usual, you'll need to use strcmp() to perform the comparison of account numbers. processTransactions() - This method should take one parameter: a C++ string containing the name of a file of credit card transaction data. The method should return nothing. The method should open the specified transaction file for input (not binary input - this file is a text file). Make sure to test that the file was opened successfully; if it wasn't, print an error message and exit the program. Before reading any transactions, the function should print a report header and column headers. The function should then read transaction data from the file until end of file is reached. A typical transaction is shown below. The first field on the transaction record is the date of the transaction, followed by an account number, then the transaction type ('C' for charge or 'P' for payment), and finally a transaction amount. Once all of the data for a given transaction has been read, call the searchForAccount() method to search the accounts array for the account number given in the transaction. If the account number is present in the array, then the transaction may be processed. For a payment, simply call the processPayment() method for the object that contains a matching account number, passing it the transaction amount. For a charge, call the processCharge() method for the object that contains a matching account number, passing it the transaction amount. For each transaction record processed, print a line in a transaction report with the data from the record and the updated balance for that account. If the balance is negative, it should be printed as a positive number but followed by the letters "CR". If the transaction account number was not
  • 8. found in the account array or if a charge exceeded the account's credit limit (i.e., if the processCharge() method returned false), print an appropriate error message instead of the account balance. After all transactions have been processed, close the transaction file. Step 3: Add two method calls to the main program The main() routine logic will now look like this: Create an AccountDB object using the alternate constructor you wrote. Pass the filename string "accounts" as an argument to the constructor. Call the print() method for the AccountDB object. Call the processTransactions() method for the AccountDB object. Pass the filename string "transactions.txt" as an argument to the method. Call the print() method for the AccountDB object. And what I have for part 2, though it may not be correct: # PROGRAM: assign2 # PROGRAMMER: # LOGON ID: # DATE DUE: # #include #include #include #include #define SIZE 20 #define ACCOUNTS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/accounts #define TRANS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/transactions.txt using namespace std; class CreditAccount { public: CreditAccount(); char* get_accountNumber(); float get_balance(); void process_payment( float );
  • 9. bool process_charge( float ); void print(); private: char acctNum[20]; char custName[21]; int expMonth; int expYear; float creditLimit; float currentBal; }; CreditAccount::CreditAccount() { acctNum[0] = '0'; custName[0] = '0'; expMonth = 0; expYear = 0; creditLimit = 0; currentBal = 0; } char* CreditAccount::get_accountNumber() { return & acctNum[0]; } float CreditAccount::get_balance() { return currentBal; } void CreditAccount::process_payment(float paymentAmt) { currentBal = currentBal - paymentAmt; } bool CreditAccount::process_charge( float chargeAmt ) { if( ( chargeAmt + currentBal ) > creditLimit )
  • 10. { return false; } else { currentBal += chargeAmt; return true; } } void CreditAccount::print() { cout << left << showpoint << fixed << setprecision(2) << setw(22) << acctNum << setw(20) << custName; if( expMonth < 10 ) { cout << "0" << expMonth; } else { cout << expMonth; } cout << "/"<< setw(7) << expYear; cout << right << setw(10) << creditLimit << setw(14); if( currentBal < 0 ) { currentBal = currentBal * (-1); cout << currentBal << " CR" << endl; } else cout << currentBal << endl; } // Function Prototypes: int read_accounts( CreditAccount[] ); void print_accounts( CreditAccount[], int );
  • 11. void process_transactions( CreditAccount[], int ); void sort_accounts( CreditAccount[], int ); int main() { CreditAccount creditArr[SIZE]; int validAccts = 0; validAccts = read_accounts( creditArr ); sort_accounts(creditArr, validAccts); print_accounts( creditArr, validAccts ); process_transactions( creditArr, validAccts ); print_accounts( creditArr, validAccts ); cout << endl; system( "pause" ); return 0; } int read_accounts( CreditAccount Arr[] ) { CreditAccount temp; ifstream inFile; int i = 0; inFile.open( "ACCOUNTS", ios::binary ); if( inFile.fail() ) { cout << "file failed to open"; exit( -1 ); } inFile.read( (char * ) &temp, sizeof( temp ) ); while( inFile ) { Arr[i] = temp; i++; inFile.read( (char * ) &temp, sizeof( temp ) ); } inFile.close(); return i;
  • 12. } void print_accounts( CreditAccount Arr[], int validAccts ) { int i; cout << endl << " " << setw(48) << "Credit Account Listing" << endl << endl << setw(61) << "Credit" << setw(15) << "Account" << endl << "Account Number" << setw(12) << "Name" << setw(24) << "Exp. Date" << setw(10) << "Limit" << setw(16) << "Balance" << endl << "----------------------------------------------------------------------------" << endl << endl; for( i = 0; i < validAccts; i++ ) { Arr[i].print(); } } void process_transactions( CreditAccount Arr[], int validAccts) { bool notExceeded; char* oldNum; char acctNum[SIZE]; string date, type; float amt, oldAmt, newAmt; ifstream inFile; int i = 0; int j = 0; inFile.open( "TRANS" ); if( inFile.fail() ) { cout << "Error: File failed to open"; exit ( -1 ); } cout << endl << " " << setw(48) << "Transaction Report" << endl << endl << "Date" << setw(10) << "Account" << setw(10) << "Type" << setw(10)
  • 13. << "Amount" << setw(15) << "New Balance" << endl << endl; inFile >> date; // set first date while( !inFile.eof() ) { bool noMatch = true; inFile.get(); for( i = 0; i < SIZE; i++ ) { acctNum[i] = inFile.get(); // set 1st acc number } inFile >> type >> amt; inFile.get(); for( i = 0; i < validAccts; i++ ) { bool acctsMatch = true; //set acctsMatch to true oldNum = Arr[i].get_accountNumber(); //get acctNum //oldAmt = Arr[i].get_balance(); //get original balance from class for( j = 0; (j < SIZE-1); j++ ) { if( acctNum[j] != oldNum[j] ) { acctsMatch = false; } } if ( acctsMatch ) { noMatch = false; if( type == "P" ) { Arr[i].process_payment( amt ); newAmt = Arr[i].get_balance(); cout << date << setw(3); for(i = 0; i < SIZE; i++ ) { cout << acctNum[i]; }
  • 14. cout << " " << setw(3) << type << setw(10) << amt << setw(24); if( newAmt < 0 ) //if negative balance, print as positive with CR appended { newAmt = newAmt * (-1); cout << newAmt << " CR" << endl; } else cout << newAmt << endl; } else if( type == "C" ) { bool notExceeded = Arr[i].process_charge( amt ); newAmt = Arr[i].get_balance(); cout << date << setw(3); for(i = 0; i < SIZE; i++ ) { cout << acctNum[i]; } if( notExceeded ) { cout << " " << setw(3) << type << setw(10) << amt << setw(24) << newAmt << endl; } else //if credit limit exceeded print err message { cout << " " << setw(3) << type << setw(10) << amt << setw(35) << "*** Credit Limit Exceeded ***" << endl; } } } } if( noMatch ) { cout << date << setw(3); for(i = 0; i < SIZE; i++)
  • 15. { cout << acctNum[i]; } cout << " " << setw(3) << type << setw(10) << amt << setw(35) << "*** Invalid Account Number ***" << endl; } inFile >> date; // set the next date } inFile.close(); } void sort_accounts( CreditAccount Arr[], int validAccts ) { int i,j; char* temp; CreditAccount cred; // added for(i = 1; i < validAccts; i++) { temp = Arr[i].get_accountNumber(); cred = Arr[i]; // assign here j = i - 1; for( ;(j > 0) && strcmp( temp, Arr[j].get_accountNumber() ) < 0; j-- ) { Arr[j + 1] = Arr[j]; j--; } Arr[j + 1] = cred; // changed } } Help would be appreciated, thank you. Solution #include #include
  • 16. #include #include #define SIZE 20 #define ACCOUNTS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/accounts #define TRANS /home/turing/t90kjm1/CS241/Data/Spring2017/Assign2/transactions.txt using namespace std; class CreditAccount { public: CreditAccount(); char* get_accountNumber(); float get_balance(); void process_payment( float ); bool process_charge( float ); void print(); private: char acctNum[20]; char custName[21]; int expMonth; int expYear; float creditLimit; float currentBal; }; CreditAccount::CreditAccount() { acctNum[0] = '0'; custName[0] = '0'; expMonth = 0; expYear = 0; creditLimit = 0; currentBal = 0; } char* CreditAccount::get_accountNumber() { return & acctNum[0]; }
  • 17. float CreditAccount::get_balance() { return currentBal; } void CreditAccount::process_payment(float paymentAmt) { currentBal = currentBal - paymentAmt; } bool CreditAccount::process_charge( float chargeAmt ) { if( ( chargeAmt + currentBal ) > creditLimit ) { return false; } else { currentBal += chargeAmt; return true; } } void CreditAccount::print() { cout << left << showpoint << fixed << setprecision(2) << setw(22) << acctNum << setw(20) << custName; if( expMonth < 10 ) { cout << "0" << expMonth; } else { cout << expMonth; } cout << "/"<< setw(7) << expYear;
  • 18. cout << right << setw(10) << creditLimit << setw(14); if( currentBal < 0 ) { currentBal = currentBal * (-1); cout << currentBal << " CR" << endl; } else cout << currentBal << endl; } // Function Prototypes: int read_accounts( CreditAccount[] ); void print_accounts( CreditAccount[], int ); void process_transactions( CreditAccount[], int ); void sort_accounts( CreditAccount[], int ); int main() { CreditAccount creditArr[SIZE]; int validAccts = 0; validAccts = read_accounts( creditArr ); sort_accounts(creditArr, validAccts); print_accounts( creditArr, validAccts ); process_transactions( creditArr, validAccts ); print_accounts( creditArr, validAccts ); cout << endl; system( "pause" ); return 0; } int read_accounts( CreditAccount Arr[] ) { CreditAccount temp; ifstream inFile; int i = 0; inFile.open( "ACCOUNTS", ios::binary ); if( inFile.fail() )
  • 19. { cout << "file failed to open"; exit( -1 ); } inFile.read( (char * ) &temp, sizeof( temp ) ); while( inFile ) { Arr[i] = temp; i++; inFile.read( (char * ) &temp, sizeof( temp ) ); } inFile.close(); return i; } void print_accounts( CreditAccount Arr[], int validAccts ) { int i; cout << endl << " " << setw(48) << "Credit Account Listing" << endl << endl << setw(61) << "Credit" << setw(15) << "Account" << endl << "Account Number" << setw(12) << "Name" << setw(24) << "Exp. Date" << setw(10) << "Limit" << setw(16) << "Balance" << endl << "----------------------------------------------------------------------------" << endl << endl; for( i = 0; i < validAccts; i++ ) { Arr[i].print(); } } void process_transactions( CreditAccount Arr[], int validAccts) { bool notExceeded; char* oldNum; char acctNum[SIZE];
  • 20. string date, type; float amt, oldAmt, newAmt; ifstream inFile; int i = 0; int j = 0; inFile.open( "TRANS" ); if( inFile.fail() ) { cout << "Error: File failed to open"; exit ( -1 ); } cout << endl << " " << setw(48) << "Transaction Report" << endl << endl << "Date" << setw(10) << "Account" << setw(10) << "Type" << setw(10) << "Amount" << setw(15) << "New Balance" << endl << endl; inFile >> date; // set first date while( !inFile.eof() ) { bool noMatch = true; inFile.get(); for( i = 0; i < SIZE; i++ ) { acctNum[i] = inFile.get(); // set 1st acc number } inFile >> type >> amt; inFile.get(); for( i = 0; i < validAccts; i++ ) { bool acctsMatch = true; //set acctsMatch to true oldNum = Arr[i].get_accountNumber(); //get acctNum //oldAmt = Arr[i].get_balance(); //get original balance from class for( j = 0; (j < SIZE-1); j++ ) { if( acctNum[j] != oldNum[j] ) { acctsMatch = false; }
  • 21. } if ( acctsMatch ) { noMatch = false; if( type == "P" ) { Arr[i].process_payment( amt ); newAmt = Arr[i].get_balance(); cout << date << setw(3); for(i = 0; i < SIZE; i++ ) { cout << acctNum[i]; } cout << " " << setw(3) << type << setw(10) << amt << setw(24); if( newAmt < 0 ) //if negative balance, print as positive with CR appended { newAmt = newAmt * (-1); cout << newAmt << " CR" << endl; } else cout << newAmt << endl; } else if( type == "C" ) { bool notExceeded = Arr[i].process_charge( amt ); newAmt = Arr[i].get_balance(); cout << date << setw(3); for(i = 0; i < SIZE; i++ ) { cout << acctNum[i]; } if( notExceeded ) { cout << " " << setw(3) << type << setw(10) << amt << setw(24) << newAmt << endl;
  • 22. } else //if credit limit exceeded print err message { cout << " " << setw(3) << type << setw(10) << amt << setw(35) << "*** Credit Limit Exceeded ***" << endl; } } } } if( noMatch ) { cout << date << setw(3); for(i = 0; i < SIZE; i++) { cout << acctNum[i]; } cout << " " << setw(3) << type << setw(10) << amt << setw(35) << "*** Invalid Account Number ***" << endl; } inFile >> date; // set the next date } inFile.close(); } void sort_accounts( CreditAccount Arr[], int validAccts ) { int i,j; char* temp; CreditAccount cred; // added for(i = 1; i < validAccts; i++) { temp = Arr[i].get_accountNumber(); cred = Arr[i]; // assign here j = i - 1; for( ;(j > 0) && strcmp( temp, Arr[j].get_accountNumber() ) < 0; j-- ) {
  • 23. Arr[j + 1] = Arr[j]; j--; } Arr[j + 1] = cred; // changed } }