PART 1 http://faculty.cs.niu.edu/~mcmahon/CS241/Assign/as02_part1_cs241_sp14.htm
ID: 3550518 • Letter: P
Question
PART 1
http://faculty.cs.niu.edu/~mcmahon/CS241/Assign/as02_part1_cs241_sp14.html
PART 1 output
http://faculty.cs.niu.edu/~mcmahon/CS241/Assign/output2_part1.txt
PART 2
http://faculty.cs.niu.edu/~mcmahon/CS241/Assign/as02_part2_cs241_sp14.html
PART 2 output
http://faculty.cs.niu.edu/~mcmahon/CS241/Assign/output2_part2.txt
Link to all the files required is provided below in the link....
https://www.dropbox.com/sh/c4hpwr3b1tg0xrp/02uZ7bHy4J
Please read everything and complete the total program..... Need little documentation....
Need it as soon as possible.... Deadline is on 2/17/2014 by 5:00 PM CST
Explanation / Answer
CreditAccount.h
#ifndef CREDIT_ACCOUNT_H
#define CREDIT_ACCOUNT_H
//*****************************************************************
// FILE: CreditAccount.h
// AUTHOR: your name
// LOGON ID: your z-ID
// DUE DATE: due date of assignment
//
// PURPOSE: Contains the declaration for the CreditAccount class.
//*****************************************************************
class CreditAccount
{
private:
char AccNum[20];
char Customer_Name[21];
double limit;
double bal;
public:
char* getAccountNumber();
char* getName();
double getLimit();
double getBalance();
void processPayment(double amount);
bool processCharge(double charge);
void print();
};
#endif
CreditAccount.CPP
#include "CreditAccount.h"
class CreditAccount
{
CreditAccount ()
{
AccNum="";
Customer_Name="";
limit=0;
bal=0;
}
CreditAccount(char number, char name, double CreditLimit, double balance)
{
strcpy (AccNum,number);
strcpy(Customer_Name,name);
limit=CreditLimit;
bal=balance;
}
char* getAccountNumber()
{
return AccNum;
}
char* getName()
{
return Customer_Name;
}
double getLimit()
{
return limit;
}
double getBalance()
{
return bal;
}
void processPayment(double amount)
{
bal=bal-amount;
}
bool processCharge(double charge)
{
if(charge+bal>limit)
return false;
else
{
bal=bal+charge;
return true;
}
}
void print()
{
cout<<"Account Number: "<<getAccountNumber();
cout<<"Name: "<<getName();
cout<<"Credit Limit: "<<getLimit();
if(bal<0)
cout<<"Current Balance: "<<getBalance()<<"CR";
else
cout<<"Current Balance: "<<getBalance();
}
};
AccountDB.h
#ifndef ACCOUNT_DB_H
#define ACCOUNT_DB_H
//*****************************************************************
// FILE: AccountDB.h
// AUTHOR: your name
// LOGON ID: your z-ID
// DUE DATE: due date of assignment
//
// PURPOSE: Contains the declaration for the AccountDB class.
//*****************************************************************
class AccountDB
{
private:
CreditAccount creditAccount[20];
int number;
public:
void print();
void sortAccounts();
void insertion_sort(CreditAccount ca[], int numAccounts);
int searchForAccount(const char* searchNumber);
void processTransactions(const char* name);
};
#endif
AccountDB.CPP
#include "AccountDB.h"
class AccountDB
{
AccountDB()
{
number=0;
}
AccountDB(const char* db_name)
{
ifstream inFile;
inFile.open (db_name, ios::out | ios::binary);
if (!inFile) {
cout<<"unable to open file";
}
inFile.read((char*) this, sizeof(AccountDB));
}
void print()
{
cout<<"Credit Card Account Listing"<<" ";
for(int i=0; i<creditAccount.Size();i++)
{
creditAccount[i].print();
cout<<" ";
}
}
void sortAccounts()
{
insertion_sort(creditAccount,creditAccount.size());
}
void insertion_sort(CreditAccount ca[], int numAccounts)
{
int i, j;
CreditAccount bucket;
for (i = 1; i < numAccounts; i++)
{
bucket = ca[i];
for (j = i; (j > 0) && ((strcmp(ca[j-1].getAccountNumber(), bucket.getAccountNumber()) > 0);); j--)
ca[j] = ca[j-1];
ca[j] = bucket;
}
}
int searchForAccount(const char* searchNumber)
{
int low = 0;
int high = creditAccount.Size() - 1;
int mid;
while (low <= high)
{
mid = (low + high) / 2;
if (searchNumber = creditAccount[mid]. getAccountNumber())
return mid;
if (searchNumber < creditAccount[mid]. getAccountNumber())
high = mid - 1;
else
low = mid + 1;
}
return -1;
}
void processTransactions(const char* name)
{
ifstream inFile;
inFile.open (name, ios::out | ios::binary);
if (!inFile) {
cout<<"unable to open file";
exit(1);
}
inFile.read((char*) this, sizeof(AccountDB));
}
};
MAIN METHOD
void main()
{
AccountDB ad=new AccountDB("accounts");
ad.print();
ad.processTransactions("transactions.txt");
ad.print();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.