« April 2024 »
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Lab 2
Thursday, 13 March 2008
Lab 2

#include <string>

#include <fstream>

#include <iostream>

#include <vector>

#include <iomanip>

using namespace std;

class Account

{

private:

string name,

address,

cityStateZip,

telephone_Number,

date_Last_Payment,

Getline;

double account_Balance;

fstream File;

public:

Account(){string N = NULL;string A= NULL ;string C= NULL;string T= NULL;string D= NULL; double Ab = 0.0;} //default constructor *** initialize all data member to null or zero 20%

Account(string N,string A,string C,string T,string D, double Ab)//overloaded constructor

{ name=N;

address=A;

cityStateZip=C;

telephone_Number=T;

date_Last_Payment=D;

account_Balance=Ab;

}

bool Write(); // write Account object to file

bool Read(fstream &); // read account object from file

void Copy(Account & A) // copy account object

{ this ->name=A.name;

this ->address=A.address;

this ->cityStateZip=A.cityStateZip;

this ->telephone_Number=A.telephone_Number;

this ->date_Last_Payment=A.date_Last_Payment;

this ->account_Balance=A.account_Balance;}

void Cin();

void Cout(fstream &);

 

};

void PrintHeaders(fstream &);

int main()

{

fstream File;

string name,

address,

cityStateZip,

telephone_Number,

date_Last_Payment;

double account_Balance = 0;

char ans;

PrintHeaders(File);

// create object

do{

Account A(name,address,cityStateZip,telephone_Number,date_Last_Payment,account_Balance);

A.Cin(); // initialize it

A.Write();

 

fflush(stdin);

cout << "Do you have another account? (Y|N)" << endl;

cin >> ans; //want to continue??

fflush(stdin);

}

while (ans == 'y' || ans == 'Y');

Account A(name,address,cityStateZip,telephone_Number,date_Last_Payment,account_Balance);

A.Read(File); // write it to end of file

A.Cout(File);

 

system("pause");

 

return 0;

}

// write to file

bool Account::Write ()

{

File.open ("Account.txt",ios::app);

char Tab='\t';

if(!File)

{ cout << " can't open output file"<<endl; return false;}

else File << left << setw(15) << name <<

left << setw(10)<<address<<

left << setw(20)<<cityStateZip<<

left << setw(14)<<telephone_Number<<

left << setw(15)<<date_Last_Payment<<

left << setbase(13)<< account_Balance <<endl;

File.close();

return true;

}

//Open file for output

bool Account::Read(fstream &file)

{

cout << "Opening Account.txt" << endl;

File.open("Account.txt", ios::in);

if(File.eof())

{

cout << "Closing file..." << endl;

File.close();

return false;

}

return true;

}

//write file to screen

void Account::Cout(fstream &file)

{

string line;

cout << "The accounts are: " << endl;

while (!File.eof())

{

getline(File, line);

cout << line << endl;

}

}

//input data from user

void Account::Cin()

{

Account Local(name,address,cityStateZip,telephone_Number,date_Last_Payment,account_Balance);

this->Copy(Local);

cout << "Enter Name: " << endl;

getline(cin,name);

fflush(stdin);

cout << "Enter adress: " << endl;

getline(cin,address);

fflush(stdin);

cout << "Enter City/State/zip: " << endl;

getline(cin,cityStateZip);

fflush(stdin);

cout << "Enter telephone number: " << endl;

getline(cin,telephone_Number);

fflush(stdin);

cout << "Enter date of last payment: " << endl;

getline(cin,date_Last_Payment);

fflush(stdin);

cout << "Enter account balance: " << endl;

cin >> account_Balance;

fflush(stdin);

return ;

}

void PrintHeaders(fstream &File)

{

File.open("Account.txt", ios::out);

File << left << setw(15) << "Name" <<

left << setw(10) << "Address" <<

left << setw(25) << "City/State/zip" <<

left << setw(14) << "Phone-Number" <<

left << setw(19) << "Last-Payment-Date" <<

left << setbase(13) << "Acct-Balance" << endl <<

left << setfill('-') << setw(95) << "-" << endl;

File.close();

}


Posted by veronicak5678 at 11:33 PM EDT

Newer | Latest | Older