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 29-May-2006, 12:15
febrarierose febrarierose is offline
New Member
 
Join Date: May 2006
Location: USA
Posts: 25
febrarierose is on a distinguished road

help in retrieveItem using a list... I'm lost


Hello... I need help I don't understand how list works...
I have enclosed the part of the retrieveItem definition I have and my .h file including the error I got.

blist.cpp
CPP / C++ / C Code:

#include <new>
#include <cassert>


using namespace std;

#include "blist.h"


//definition of retreiveItem
void bankList::retrieveItem(bankAccount &key, bool &found)
{
	int midPoint, first = 0, last = accountSize - 1;

	bool moreToSearch = (first <= last);
	found = false;
	
	while (moreToSearch && !found)
	{
		midPoint = (first + last) / 2;
		if (key < accountSize[midPoint])
		{
			last = midPoint -1;
			moreToSearch = (first <= last);
		}
		else
		{
			if (key > accountSize[midPoint])
			{
				first = midPoint + 1;
				moreToSearch = (first <= last);
			}
			else
			{
				found = true;
				key = accountSize[midPoint];
			}
		}
	}
}




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

#include <iostream>


#ifndef BANK
#define BANK


typedef bAccnt bAccnt;

class blist
{
public:

	//retrieve item
	void retrieveItem (bankAccount &key, bool &found); // find a "key"
private:
	int accountSize;
	int accountCapacity;
	bAccnt *myArrayPtr;
};


error Message:

c:\Documents and Settings\bankList.cpp(12: error C2511: 'int bankList::getCapacity(void)' : overloaded member function not found in 'bankList'
c:\Documents and Settings\bankList.cpp(99): error C2109: subscript requires array or pointer type
c:\Documents and Settings\bankList.cpp(91): error C2109: subscript requires array or pointer type
c:\Documents and Settings\bankList.cpp(84): error C2109: subscript requires array or pointer type
  #2  
Old 29-May-2006, 13:37
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: help in retrieveItem using a list... I'm lost


Did you try to use a function getCapacity? Where is it? It's not in the bankList class, and the compiler complains about it.
Please show us how you have tried to use this class (the code making an instance and so on).

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 29-May-2006, 14:12
febrarierose febrarierose is offline
New Member
 
Join Date: May 2006
Location: USA
Posts: 25
febrarierose is on a distinguished road

Re: help in retrieveItem using a list... I'm lost


Here is the whole code. I made some changes but most of the error I got were pointing to retrieveItem section. Please help I really don't know what those means. I just started working on c++ for few months.

Please explain what I need to do.

Thank you very much.



bankAccount.cpp
CPP / C++ / C Code:
//bankAccount.cpp - Bank Account class implementation file

#include <iostream>
#include <string>
#include "bankAccount.h"

//Constructors
bankAccount::bankAccount()  //initialize to 0 or just a place holder
: accountNumber(00000), accountName("John and Anna Doe"), accountType("Checking&Saving"), amountDeposit(0),  amountWithdraw(0), interestRate(0), overdraft(0)
{
}


bankAccount::bankAccount(string acctName, string acctType, int acctNum, double amtDeposit, double amtWithdraw, double intRate, double overDraft)
{	
	//initialize to any size
	accountName = acctName;
	accountType = acctType;
	accountNumber = acctNum;
	amountDeposit = amtDeposit;
	amountWithdraw = amtWithdraw;
	interestRate = intRate;
	overdraft = overDraft;


}

//Accessors
string bankAccount::getAcctName() const		//returns the account name
{
	return accountName;
}

string bankAccount::getTypeAcct() const		//returns the account type
{
	return accountType;
}
int bankAccount::getAcctNumber() const		//returns the account number	
{
	return accountNumber;
}
double bankAccount::getAmtDeposit() const	//returns the amount deposit
{
	return amountDeposit;
}
double bankAccount::getAmtWithdraw() const	//returns the amount withdraw
{
	return amountWithdraw;
}
double bankAccount::getIntRate() const		//returns the interest rate
{
	return interestRate;
}
double bankAccount::getOvrdraft() const		//returns the overdraft
{
	return overdraft;
}
//Mutators
void bankAccount::setAcctName(string acctName)	//change the account name	
{
	accountName = acctName;
}
void bankAccount::setAcctType(string acctType)	//change the account type
{
	accountType = acctType;
}	
void bankAccount::setAcctNum(int acctNum)	//change the account number
{
	accountNumber = acctNum;
}
void bankAccount::setAmtDeposit(double amtDeposit)	//change the account deposit
{
	amountDeposit = amtDeposit;
}

void bankAccount::setAmtWithdraw(double amtWithdraw)	//change the account withdraw
{
	amountWithdraw = amtWithdraw;
}
void bankAccount::setNewAcctName(string acctName)	//set the account name
{
	accountName = acctName;
}

void bankAccount::setInterestRate(double intRate)	//set the interest rate
{
	interestRate = intRate;
}
void bankAccount::setOverdraft(double overDraft)	//set the overdraft charges
{
	overdraft = overDraft;
}

//Utilities
void bankAccount::displayCheckBal(ostream & out) const	//display balance
{
	out << "\nAccount Name: "<< accountName << endl;
	out << "Account Number: " << accountNumber << endl;
	out << "Balance: $" << amountDeposit << endl;
}
void bankAccount::displayAcctStatus(ostream & out) const //display account status 
{
	out << "\nAccount Name: " << accountName << endl;
	out << "Account Number: " << accountNumber << endl;
	out << "Account Type: " << accountType << endl;
	out << "Amount Remaining: $" << amountDeposit << endl;
	out << "Current Interest Rate: " << interestRate << endl;;
	out << "Current Overdraft Charges: $" << overdraft << endl;
}

double bankAccount::calcInterest()		//calculate and return amount deposit with interest rate
{
	
	amountDeposit = amountDeposit + (interestRate * amountDeposit);
    return amountDeposit;
}

double bankAccount::calcBalanceAmt()	//calculate and return amount deposit after withrawal
{
	
	amountDeposit = amountDeposit - amountWithdraw;
	if (amountDeposit > 0)
	{
        return  amountDeposit;
	}
	else
	{
		amountDeposit = amountDeposit - overdraft;
		return amountDeposit;
	}
}


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

//bankAccount.h - Bank Account class header file

#include <iostream>
#include <string>
using namespace std;

#pragma once

class bankAccount
{
	friend class bankList;

	public:
		//Constructors
		bankAccount();
		bankAccount(string acctName, string acctType, int acctNum, double amtDeposit, double amtWithdraw, double intRate, double overDraft);

		//Accessors
		string getAcctName() const;
		string getTypeAcct() const;
		int getAcctNumber() const;
		double getAmtDeposit() const;
		double getAmtWithdraw() const;
		double getIntRate() const;
		double getOvrdraft() const;

		//Mutators
		void setAcctName(string acctName);
		void setAcctType(string acctType);
		void setAcctNum(int acctNum);
		void setAmtDeposit(double amtDeposit);
		void setAmtWithdraw(double amtWithdraw);
		void setNewAcctName(string acctName);
		void setInterestRate(double intRate);
		void setOverdraft(double overDraft);
		 

		//Utilities
		void displayCheckBal(ostream & out) const;
		void displayAcctStatus(ostream & out) const;
		double calcInterest();
		double calcBalanceAmt();
		 
	private:
		int accountNumber;
		string accountName, accountType; 
		double amountDeposit, amountWithdraw, interestRate, overdraft;
        

};


bankList.cpp
CPP / C++ / C Code:
#include <new>
#include <cassert>


using namespace std;

#include "bankList.h"


bankList::bankList(int maxAccount)
: accountSize(), accountCapacity(maxAccount)
{
	myArrayPtr = new(nothrow) bankAccount[maxAccount];
	assert(myArrayPtr !=0);
}

//class destructor
bankList::~bankList()
{
	delete [] myArrayPtr;
}

//copy constructor
bankList::bankList(const bankList & origList)
: accountSize(origList.accountSize), accountCapacity(origList.accountCapacity)
{
	myArrayPtr = new(nothrow) bankAccount[accountCapacity];

	if(myArrayPtr != 0)	//check if memory available
	{
		//copy origList's array into this new array
		for (int i = 0; i < accountCapacity; i++)
		{
			myArrayPtr[i] = origList.myArrayPtr[i];
		}
	}
	else
	{
		cerr << "*** Inadequate memory to allocate stack ***\n";
		exit(1);
	}
}
//asignment operator
bankList & bankList::operator=(const bankList & origList)
{
	if (this != &origList) // check for bankList = bankList
	{
		accountSize = origList.accountSize;
		accountCapacity = origList.accountCapacity;

		//allocate a new array if necessary
		if (accountCapacity != origList.accountCapacity)
		{
			delete [] myArrayPtr;
			myArrayPtr = new(nothrow) bankAccount[accountCapacity];

			if (myArrayPtr == 0) //check if memory available
			{
				cerr << "*** Inadequate memory to allocate stack ***\n";
				exit(1);
			}
		}

		//copy origList's array into this new array
		for(int i = 0; i<accountCapacity; i++)
		{
			myArrayPtr[i] = origList.myArrayPtr[i];
		}
	}
	return *this;
}

//definition of retreiveItem
void bankList::retrieveItem(bankAccount &key, bool &found)
{
	int midPoint, first = 0, last = accountSize - 1;

	bool moreToSearch = (first <= last);
	found = false;
	
	while (moreToSearch && !found)
	{
		midPoint = (first + last) / 2;
		if (key.accountNumber < myArrayPtr[midPoint])
		{
			last = midPoint -1;
			moreToSearch = (first <= last);
		}
		else
		{
			if (key.accountNumber > myArrayPtr[midPoint])
			{
				first = midPoint + 1;
				moreToSearch = (first <= last);
			}
			else
			{
				found = true;
				key.accountNumber = myArrayPtr[midPoint];
			}
		}
	}
}
		

//definition of isFull
bool bankList::isFull() const
//full if list is at capacity
{
	return (accountSize == accountCapacity);
}

//definition of empty()
bool bankList::empty() const
{
	return accountSize == 0;
}

//definition of sizeIs()
int bankList::sizeIs() const
{
	return accountSize;
}

//maximum Capacity;
int bankList::getCapacity()

{
	return accountCapacity;
}


//Definition of insert()
void bankList::insert(bankAccount newEntry, int pos)
{
	if (accountSize == accountCapacity)
	{
		cerr << "*** No Space for list element -- terminating execution ***\n";
		exit(1);
	}

	if (pos < 0 || pos > accountSize)
	{
		cerr << "*** Illegal location to insert -- " << pos << ".  List unchanged. ***\n";
		return;
	}

	for (int i = accountSize; i > pos; i--)
	{
		myArrayPtr[i] = myArrayPtr[i-1];
	}
	myArrayPtr[pos] = newEntry;
	accountSize;
}

//deleteItem
void bankList::deleteItem(int pos)
{
	if (accountSize == 0)
	{
		cerr << "*** List is empty ***\n";
		return;
	}
	
	if (pos < 0 || pos >= accountSize)
	{
		cerr << "Illegal location to delete -- " << pos << ". List unchanged. ***\n";
		return;
	}

	for (int i = pos; i < accountSize; i++)
	{
		myArrayPtr[i] = myArrayPtr[i+1];
	}
	accountSize;

	/*
	int location = 0;
	while (myArrayPtr[location] != key)
	{	
		location ++;
	}
	for (int i = location +1; i < accountSize; i++)
	{
		myArrayPtr[i-1] = myArrayPtr[i];
	}
	accountSize--;*/
}

//definition of out operator
ostream & operator<< (ostream & out, const bankList & accNum)
{
	accNum.display(out);
	return out;
}



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

#include <iostream>
#include "bankAccount.h"

#ifndef BANK
#define BANK


typedef bankAccount bankAccount;

class bankList
{
public:
	//class constructor
	bankList(int maxAccount = 5);

	//class destructor
	~bankList();

	//copy constructor
	bankList(const bankList & origList);
    
	//assignment
	bankList & operator = (const bankList & origList);

	// isFull operation
	bool isFull () const;

	//empty operation
	bool empty() const;

	//sizeIs operation
	int sizeIs() const;
	 
	//getCapacity here
	int getCapacity() const;


	//retrieve item
	void retrieveItem (bankAccount &key, bool &found); // find a "key"


	//insertItem
	void insert(bankAccount newEntry, int pos);

	//delete item
	void deleteItem(int pos);

	//dislay
	void display(ostream & out) const;

private:
	int accountSize;
	int accountCapacity;
	bankAccount *myArrayPtr;
};

//prototype of output operator
ostream & operator<< (ostream &out, const bankList &accNum);

#endif



new errors after I made some changes:

c:\bankList.cpp(84): error C2677: binary '<' : no global operator found which takes type 'bankAccount' (or there is no acceptable conversion)

c:\bankList.cpp(84): error C2784: 'bool std:perator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const T1 *' from 'int'

c:\bankList.cpp(84): error C2784: 'bool std:perator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'int'

c:\bankList.cpp(84): error C2784: 'bool std:perator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'int'

c:\bankList.cpp(84): error C2784: 'bool std:perator <(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'int'

c:\bankList.cpp(84): error C2784: 'bool std:perator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'int'

c:\bankList.cpp(91): error C2677: binary '>' : no global operator found which takes type 'bankAccount' (or there is no acceptable conversion)

c:\bankList.cpp(91): error C2784: 'bool std:perator >(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const T1 *' from 'int'

c:\bankList.cpp(91): error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'int'

c:\bankList.cpp(91): error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'int'

c:\bankList.cpp(91): error C2784: 'bool std:perator >(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'int'

c:\bankList.cpp(91): error C2784: 'bool std:perator >(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'int'

c:\bankList.cpp(99): error C2440: '=' : cannot convert from 'bankAccount' to 'int'

c:\bankList.cpp(12: error C2511: 'int bankList::getCapacity(void)' : overloaded member function not found in 'bankList'
  #4  
Old 29-May-2006, 15:03
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: help in retrieveItem using a list... I'm lost


Quote:
Originally Posted by febrarierose
most of the error I got were pointing to retrieveItem section.
.
.
.
c:\bankList.cpp(84): error C2677: binary '<' : no global operator found which takes type 'bankAccount' (or there is no acceptable conversion)

Instead of worrying about "most of them", why not just take them one at a time as they appear? Lots of time fixing one thing makes many other errors go away. In any case, you are going to have to address this one sooner or later. Why not sooner?

I know that sometimes error messages are very obscure, but this one seems plain enough.

The line that it flagged is
CPP / C++ / C Code:
	        if (key.accountNumber < myArrayPtr[midPoint]) {


myArrayPtr is a pointer to a bankAccount object (so myArrayPtr[midPoint] is a bankAccount object), and there is no overloaded "<" operator that is applicable to bankAccount objects. What are you really trying to compare here?

Regards,

Dave
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Help in C Print is not working with LinkList batman3280 C Programming Language 3 09-Mar-2006 19:03
linked list error message Krandygrl00 C++ Forum 4 22-Jun-2005 14:13
search linked list itsmecathys C++ Forum 20 18-Apr-2005 01:34

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

All times are GMT -6. The time now is 18:20.


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