🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #55

class help

#55
From: Antony Carr
Date: Tue, 01 May 2001 16:57
276 lines
7504 bytes
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: <9cms6r$emm$1@neptunium.btinternet.com>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!btnet-peer1!btnet-feed5!btnet!mendelevium.btinternet.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10d4ba,bcfa6c5c8a6717c0,start
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 114592,bcfa6c5c8a6717c0,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 109fba,bcfa6c5c8a6717c0,start
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 2001-05-01 10:37:16 PST
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!btnet-peer1!btnet-feed5!btnet!mendelevium.btinternet.com!not-for-mail
From: "Antony Carr" <antony.carr@btinternet.com>
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++
Subject: class help
Date: Tue, 1 May 2001 17:57:43 +0100
Organization: BT Internet
Lines: 282
Message-ID: <9cms6r$emm$1@neptunium.btinternet.com>
NNTP-Posting-Host: host213-122-178-49.btinternet.com
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400