I am thinking that I should preform this in the for loop before I write each check. Or should I do it inside the write() function?
/*
CST 280 Program Assignment 3
Purpose---
INPUT: The input will come from file checkdata.txt that contains the starting check number, the employees name, the date, and the amount. There is no user interaction.
PROCESS: This program will read and process the data from the file, generate a english version of the check amount, and write the result to the console.
OUTPUT: A list of simulated checks will be output to the console.
On: 02/12/2010
*/
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
#include "check.h"
// Global Variable
const int MAX_EMPLOYEES = 500;
int main()
{
Check ckList[MAX_EMPLOYEES]; // Array of objects
int checkNum;
double amount;
string firstName, lastName, date;
int ptr, size;
// read check info from file and build array values
ifstream check_File("checkdata.txt");
ptr = 0;
check_File >> checkNum >> firstName >> lastName >> date >> amount;
//ckList[ptr].setCheckNumber(checkNum);// capture check number only one time
while(!check_File.eof())
{
// Store information from file in current array object
ckList[ptr].setCheckNumber(checkNum);
ckList[ptr].setCheckFName(firstName);
ckList[ptr].setCheckLName(lastName);
ckList[ptr].setCheckDate(date);
ckList[ptr].setCheckAmount(amount);
check_File >> firstName >> lastName >> date >> amount;
ptr++;
checkNum++; // add 1 to the check number to be stored in each object
}
size = ptr;
// Check writing loop
for (int i=0; i < size; i++)
{
// Get long format of number
ckList[i].write();
}
return 0;
}
// This file implements functions for the check class
#include <iostream>
#include<iomanip>
#include <string>
using namespace std;
#include "check.h"
const string CHECK_SIGNER = "DELTA COLLEGE";
// Defualt constructor - initialize to "dummy" values
Check::Check()
{
checkNum = 0000;
firstName = "XXX";
lastName = "ZZZ";
date = "00/00/00";
amount = 0.00;
}
// Method to set check number
void Check::setCheckNumber(int ckNum)
{
checkNum = ckNum;
}
// Method to set first name
void Check::setCheckFName(string ckFName)
{
firstName = ckFName;
}
// Method to set last name
void Check::setCheckLName(string ckLName)
{
lastName = ckLName;
}
// Method to set date
void Check::setCheckDate(string ckDate)
{
date = ckDate;
}
// Method to set check amount
void Check::setCheckAmount(double ckAmt)
{
amount = ckAmt;
}
// Method to wrtie checks to console output
//
void Check::write()
{
cout << "--------------------------------------------------------" << endl;
cout << checkNum ;
cout << setw(44) << "DATE: " << date << endl;
cout << "PAY TO THE ORDER OF: " << firstName << " " << lastName;
cout << setw(4) << "$ " << amount << endl;
cout << setw(56) << CHECK_SIGNER << endl;
}
I am having trouble uploading the file, but here is the content:
1678
Jane Doe 04/28/09 567.12
George Obama 05/01/09 811.47
Barrak Bush 10/19/10 98.14
Condi Clinton 12/31/09 1.84
Hillary Rice 07/03/10 0.56
Jen Fuller 08/25/09 112.13
Abe Washington 03/02/11 117.00
George Lincoln 09/09/09 345.99
Nick Lidstrom 11/23/09 10.00
Steve Yyzerman 11/23/09 8.87
This post has been edited by jessicalegner: 14 February 2010 - 09:06 AM

New Topic/Question
Reply




MultiQuote





|