Article View: alt.comp.lang.learn.c-c++
Article #61Re: class help
From: Regina Momnie
Date: Sun, 06 May 2001 04:19
Date: Sun, 06 May 2001 04:19
299 lines
8419 bytes
8419 bytes
Heres a thought dude, why dont you have BankAccount have a variable which
holdes the name in which the account is held. Even a 13year old could
figure that one out buddy.
Antony Carr <antony.carr@btinternet.com> wrote in message
news:9cms6r$emm$1@neptunium.btinternet.com...
> Right heres a question for you all, i am a little stuck and hope someone
can
> help me...
> The best way of describing my problem is by showing you an example of what
i
> am trying to do, so here it is...
> I have a two files, a .cpp file containing the main() etc, and a header
file
> (bank.hpp).
> inside the header file there are two classes BankAccount and BankDB.
> BankAccount contains the account name, & balance. BankDB amongst other
> things creats for each instance of BankAccount the name in which the
account
> is held. Now heres the problem, i can for a single instance of BankAccount
> set the name & Balance indervidually , however how would you go about
> calling from the class of BankDB an instance of BankAccount ??? Whenever i
> try i get error messagess generated. I have attatched to this message the
> two files concerned. If any one could help i would be eternally greatfull
> :-)
>
> Antony Carr
> antony.carr@btinternet.com
>
>
****************************************************************************
> ************
> FILES
> (bank.cpp)
> #include <iostream.h>
> #include "bank.hpp"
> #include <stdio.h>
> #include <conio.h>
> #include <ctype.h>
> #include <string.h>
> #include <fstream.h>
> #include <io.h>
> #include <process.h>
>
> void main()
>
> BankAccount bankaccount;
> BankDB bankdb;
> char option;
> clrscr();
>
> do{
> clrscr();
> cout <<"Welcome to the automated Banking system";
> cout <<"\n\nPlease select from the menu below the option that you
require:";
> cout <<"\n1) Add Account";
> cout <<"\n2) Credit Account By Name";
> cout <<"\n3) Credit Account By Number";
> cout <<"\n4) Debit Account By Name";
> cout <<"\n5) Debit Account By Account Number";
> cout <<"\n6) Display Accounts";
> cout <<"\n0) Administer Database ";
> cout <<"\n8) TEST";
> cout <<"\n\n7) Quit\nOption: ";
> cin >>option;
>
> if (option=='1'){
> cout <<"\nAdd Account";
> bankdb.add_a_customer();
> getch();
> }
> if (option=='2'){
> cout <<"Credit Account by name";
> getch();
> }
> if (option=='3'){
> cout <<"Credit account by number";
> bankdb.add_to_balance_by_number();
> getch();
> }
> if (
> option=='4'){
> cout <<"Debit account by name";
> getch();
> }
> if (option=='5'){
> cout <<"Debit account by number";
> getch();
> }
> if (option=='6'){
> cout <<"display accounts";
> getch();
> }
> if (option=='8'){
> cout <<"test";
> bankaccount.addtobalance();
> getch();
> }
> if (option=='0'){
> cout <<"DATABASE ADMIN";
> bankdb.read_db();
> getch();
> }
> }while(option!='7');
> cout <<"Thank you for using this program ( :0)";
> }
>
> (bank.hpp)
>
> #include <iostream.h>
> #include <fstream.h>
> #include <process.h>
> #include <string.h>
> #include <stdio.h>
> #include <conio.h>
> #include <stdlib.h>
> #include <io.h>
> char name[20];
> char namestr[20];
> float balance;
> float totalbalances;
>
> class BankAccount {
> public:
>
> void addtobalance();
> void subtractballance();
> void return_account_balance();
> void return_account_name();
> void clear_total_of_balances();
> void add_to_total_of_balances();
> void return_total_of_balancess();
> float input;
> };
> void BankAccount::addtobalance(){
>
> cout <<"Please Enter the amount that you wish to add to the account
> of"<<name<<":\n�";
> cin>>input;
> balance=balance+input;
> totalbalances=totalbalances+input;
> cout <<"Thank you, the total of the account is now: �"<<balance;
> getch();
> }
> void BankAccount::subtractballance(){
> cout <<"Please enter the amount that you wish to subtract from the account
> of"<<name<<";\n�";
> cin>>input;
> balance=balance-input;
> totalbalances=totalbalances-input;
> cout <<"Thank you, The total of the account is now: �"<<balance;
> getch();
> }
> void BankAccount::return_account_balance(){
> cout <<"The account for "<<name<<"has a total balance
of:\n\t\t�"<<balance;
> getch();
> }
> void BankAccount::return_account_name(){
> cout <<"The account is entered in the name of"<<name;
> getch();
> }
> void BankAccount::clear_total_of_balances(){
> cout <<"The total of balances held by this system is now reset to �0";
> totalbalances=0;
> }
> void BankAccount::add_to_total_of_balances(){
> cout <<"To add to the total of the balances held in the bank please enter
> the amount you wish to add: ";
> cout << "�";
> cin >> input;
> totalbalances=totalbalances+input;
> }
> void BankAccount::return_total_of_balancess(){
> cout <<"The total of balancess held in the bank system is
�"<<totalbalances;
> }
>
> class BankDB:BankAccount {
> public:
> void add_a_customer();
> void add_to_balance_by_number();
> void add_to_balance_by_name();
> void subtract_balance_by_number();
> void subtract_balance_by_name();
> void return_balance_by_number();
> void return_balance_by_name();
> void return_account_name_by_number();
> void show_all_accounts();
> void read_db();
> void write_db();
> };
> void BankDB::add_a_customer(){
> }
> void BankDB::add_to_balance_by_number(){
> addtobalance();
> }
> void BankDB::add_to_balance_by_name(){
>
> }
> void BankDB::subtract_balance_by_number(){
>
> }
> void BankDB::subtract_balance_by_name(){
>
> }
> void BankDB::return_balance_by_number(){
>
>
> }
> void BankDB::return_balance_by_name(){
>
> }
> void BankDB::return_account_name_by_number(){
>
> }
> void BankDB::show_all_accounts(){
>
> }
> void BankDB::read_db(){
> char filenm[60], accname[20], accbal[20], inc;
> long int acctot = 0;
> int account_count = 0, char_count = 0;
> FILE* infile;
>
> cout <<"\n\n\t\t\tfilehand.cpp\n\n";
>
> strcpy (filenm, "g:\\filedata.txt");
>
> infile = fopen(filenm, "r");
>
> if(!infile)
> {
> cout<<"input file cannot be opened";
> exit(1);
> }
>
> accname [0] = '\0';
> do
> {
> char_count = 0;
> while (inc = fgetc(infile))
> {
> if (inc == ',') file://A comma signifies end of name
> break;
> accname[char_count++] = inc;
> }
> accname[char_count] = '\0';
> cout<<"\n";
> if (inc != EOF)
> {
> char_count = 0;
> while (inc = fgetc(infile))
> {
> if ((inc == '\n') || (inc == EOF)) file://A newline inicates end of
> account balance
>
> break; file://EOF is end of file
> accbal[char_count++] = inc;
> }
> accbal[char_count++] = '\0';
>
> cout << "\n";
> cout.width(5);
> cout << account_count;
> cout << " ";
> cout.width(30);
> cout.setf(ios::left);
> cout << accname;
> cout.width (8);
> cout.setf(ios::right);
> cout << accbal;
> account_count++;
> acctot += atol(accbal); file://Convert balance to a long and add to
> total
> }
>
> }while (inc != EOF);
>
> cout << "\n\n\nAccounts read = "<< account_count;
> cout << "\nAcounts total = " << acctot;
> getch();
> fclose(infile);
>
>
> }
> void BankDB::write_db(){
>
> }
>
>
>
>
>
>
Technical Details
Message-ID:
<9d2j47$6ad$1@bob.news.rcn.net>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!feed1.news.rcn.net!rcn!not-for-mailReferences:
<9cms6r$emm$1@neptunium.btinternet.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 114592,bcfa6c5c8a6717c0 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,bcfa6c5c8a6717c0 X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,bcfa6c5c8a6717c0 X-Google-Attributes: gid10d4ba,public X-Google-ArrivalTime: 2001-05-05 21:16:01 PST Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!feed1.news.rcn.net!rcn!not-for-mail From: "Regina Momnie" <mom1020@massed.net> Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++ Subject: Re: class help Date: Sun, 6 May 2001 00:19:36 -0400 Lines: 301 Message-ID: <9d2j47$6ad$1@bob.news.rcn.net> References: <9cms6r$emm$1@neptunium.btinternet.com> X-Trace: UmFuZG9tSVamJgxYuToL6AIpIkeeZ4VsYGgznh917DTLzlNO23ci5HkvfAP+k2Nh X-Complaints-To: abuse@rcn.com NNTP-Posting-Date: 6 May 2001 04:15:03 GMT X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 X-Priority: 3 X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MSMail-Priority: Normal