GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Apr-2005, 19:13
brookeville brookeville is offline
Junior Member
 
Join Date: Oct 2004
Posts: 56
brookeville is on a distinguished road

Help with Classes and database arrays


Hello all,

I am in the process of designing a program (a savings account database program) and I have run into a few subtle errors I need to resolve. The whole program consists of 2 header files, 2 source code files (each with member function definitions) and 1 driver file. I have only listed one header file and a simple member function. I am having specific trouble completing this one member function.

Here is the class header file:

CPP / C++ / C Code:
// SavingsDB.h

#ifndef SAVINGS_DB_H
#define SAVINGS_DB_H

#include "SavingsAccount.h"

class SavingsDB {
public:
	SavingsDB(); // default ctor
	enum { MAX_DB = 10 }; // enumerated constant
	void addAccount();
	void deleteAccount();
	void displayAccount();
	void updateAccountBalances();
	void printDb();
	void dBmenu();
	void openDbFile();
	void saveDbFile();

private:
	SavingsAccount db[MAX_DB]; // database array
	int size;
};
#endif

First off, in the private section, I do not understand the declaration of the database array, SavingsAccount db[MAX_DB]. I presume it is an object of class SavingsAccount?

Here is my member function definition:
CPP / C++ / C Code:
///////////////////////////////////////////////////////////////////////////////////////////////
// The function prompts the user to enter account data and then stores the data in a record in 
// the database array. If the database is full an appropriate message is displayed. 
///////////////////////////////////////////////////////////////////////////////////////////////
void SavingsDB::addAccount()
{

	unsigned acctNo;
	float balance;
	static int i;
	i = 0;

	if (size == 10)
	{
		cout << "Database is full. Cannot add a new savings account." << endl;
		dBmenu(); //return to menu
	}
	
	cout << "Enter a New Savings Account\n";
	
	cout << "Enter Account #: ";
	cin >> acctNo;

	cout << "Enter Balance: ";
	cin >> balance;

	db[i] = acctNo;
	db[i + 1] = balance;

	i += 2; // add two to static variable i for next use of this function

	dBmenu();
	

}

What I need to do is store each account number and balance entered in a record in the database array. (Later, the array will be output to a text file). I am having trouble doing this... the array was not assigned a specific type in the header file I believe. Any help is most appreciated.
  #2  
Old 13-Apr-2005, 00:26
brookeville brookeville is offline
Junior Member
 
Join Date: Oct 2004
Posts: 56
brookeville is on a distinguished road
Let me also post the SavingsAccount header file, if it helps solve some of my other problems w/ this assignment:


CPP / C++ / C Code:
// SavingsAccount.h

#ifndef SAVINGS_ACCOUNT_H
#define SAVINGS_ACCOUNT_H

#include <iostream>

using namespace std; //instead of using std::ostream

class SavingsAccount 
{

friend ostream& operator <<(ostream & os, SavingsAccount& sa); // use with cout

public:
	
	SavingsAccount() //constructor
		: accountNumber(0), savingsBalance(0.0f) //member initializers
	{

	//empty body
	
	} 
	
	void setAccountNumber( unsigned acctNo );
	void setBalance( float balance );
	void updateAccountBalance();
	unsigned getAccountNumber() const;
	float getBalance() const;
	bool operator==( SavingsAccount & rhs );
	static void setInterestRate( float );
	static float getInterestRate();	

private:
	
	unsigned accountNumber;
	float savingsBalance;
	static float annualInterestRate;
};

#endif


So, basically, I need to be able to enter an (unsigned int) account number and a (float) balance amount; then I need to store this data in a record in the database array. I am getting errors in my previous post, above this one and I don't know how to work them out. Any guidance would be cherished! :-P
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.