Let me try again. I could use some help with this assignment, even
though my teacher does not grade assignments.but because I need to
know this stuff for a test very soon, but haven't been in class for
awhile and don't know what I'm doing.
I have included my (probably wrong) answers for the first few
questions. It would be great if someone could tell me what is missing
or what I need to work on at least just for the first few.
I understand that no one wants to do someone elses homework, so if you
don't want to give any pointers, I would be more than grateful if
anyone could direct me to a URL where I could learn about these topics
since I don't own a textbook.
thanks again for any help.
__________________________________________________ _________________
class Money
{
public:
friend istream& operator >> (istream& IS, Money& anAmount) ;
private:
int mDollars;
int mCents;
};
class ISPAccount
{
public:
friend istream& operator >> (istream& IS, Money& anISPAccount) ;
private:
string mUser ;
Money mBalance ;
int mOnline ;
};
template <class Thing>
class AccountList
{
public:
private:
vector <Thing> mSomeAccts ;
};
1) Write a line of code that declares an AccountList object of
ISPAccounts. Call the object theAccounts.
AccountList <ISPAccounts> theAccounts;
2) Write a public function in the AccountList class that returns the
index of an ISPAccount parameter. If the ISPAccount
is not in the mSomeAccts vector, return -1. Name the function
getIndex. Note that you will need to add some functionality to
the ISPAccount class.
class AccountList
{
public:
int getIndex(ISPAccount
target_parameter);
};
class ISPAccount
{
public:
friend bool operator == (const
ISPAccount & target_parameter, const ISPAccount & parameter);
};
int AccountList::getIndex(ISPAccount target_parameter)
{
while (
3) Write a function in the AccountList class that will return the
total of all the balances in an AccountList. Call the
function getTotalBal. Note that you will need to add some
functionality to the ISPAccount class and/or the Money class.
class AccountList
{
public:
double getTotalBal();
}
double AccountList::getTotalBal()
{
double total_balance = 0, temp_balance;
while (vector mSomeAccounts.mBalance >>
temp_balance)
{
total_balance += temp_balance;
}
return total_balance
{
4) Write a default constructor for the Money Class that initializes
a Money object to $0.
class Money
{
public:
money();
};
money::money()
{
mDollars = 0;
mCents = 0;
}
5) Overload the default constructor so that it takes two arguments,
the first for the number of dollars and the second for
the number of cents.
class BunchOfCards
{
public:
friend vector<Card> operator + (vector<Card> B1,
vector<Card> B2) ;
private:
vector <Card> mTheCards ;
// the “top” of the bunch is the last item on the Card on the
vector.
};
6) Write a member function that ‘splits’ a bunch of card in half. The
top half of the bunch is deleted from the bunch and
then returned. Consider the middle index of the bunch equal to
mTheCards.size() / 2. Here’s a sample function call:
{
BunchOfCards aBunch(“the_deck.txt”);
// creates and initializes a BunchOfCards from a file named
the_deck.txt
// that has 36 cards.
BunchOfCards anotherBunch ; // creates an empty BunchOfCards
anotherBunch = aBunch . topHalf() ;
// post condition: anotherBunch contains 18 cards taken off the
// top of aBunch. aBunch contains the 18 cards left on the bottom of
aBunch.
}
7a) Overload the + operator so that it adds two bunches of cards
together.
friend vector<Card> operator + (vector<Card> B2, vector<Card> B2) ;
7b) Rewrite the header making good style and efficient use of const
and &.
8) Write a member function of the BunchOfCards called cut that takes
the top half of a BunchOfCards object and puts it on
the bottom.
(Question 9 is not related to any of the classes above)
9) Write a nonmember, templated function that will reverse the order
of a vector of anything
vector new_vector;
for (int index_from_back = a_vector.size() - 1,
the_index_from_back >= 0, the_index_from_back--) ;
{
a_vector[the_index]