jeymine 0 Newbie Poster

Hi Guys,
Kindly help me Solve this. I have already worked on the classes that were inherited and attached after the question is the main part of my program. I have bolded the part in the question below where I need help. Thank you so much.
The question is:
Make an array of BankAcct pointers and assign each of the three object addresses into this array. Set up a loop that asks the user what type of banking transaction he or she wants. For whatever type of transaction, run a for loop and call the appropriate function. After each transaction, call the ShowAll functions, which report all data associated with each object. For example, if the user wishes to deposit $100, then $100 is deposited into each account. (Try to conserve space so that all the data may be written on the screen for each transaction). Be sure to place error messages if the user attempts to perform an illegal transaction (i.e. not enough money in the account to make the requested withdrawal). Your program should ask if he or she wishes to perform another transaction. Quit the program when the user is finished.

#include <iostream>
# include "BankAcct.h"
# include "AtmBankAcct.h"
# include "Gold_BankAcct.h"
using namespace std;
using namsepace Judith;

int main()
{

//(Objects for the classes)
BankAcct ExpressInc("Dimer", "0123672580", "500.00");

//Alternative way
	//cout<<" Enter the Name of the Account Holder"<<endl;
	//cin>> ExpressInc.setName;
             //cout<<" Enter Your Account Number (10 digits):"<<end;
	//cin>> ExpressInc.setaccount_Number;
	//cout<<" The savings …
jeymine 0 Newbie Poster
Mat Mat::operator+(Mat d)
{
     myVar += d.myVar;
     //...
}

Thanks . This is quite helpful. Just wondering though, how do you use the setmat to initialize the matrix objects?
Thanks again.
The setmat is a public function in the class of Mat.

jeymine 0 Newbie Poster

And where are you learning C++ from? School? Book?

I use my head, well it has brains:) and heresay combined. Seems there is a gap in both, otherwise thanks:
I just realised I didnt formulate the question in a right way.

How do I access the private variable of an array in the function defination?
Thanks

jeymine 0 Newbie Poster

Very simple way to pass them:

void myFunction(arg1 *[], arg2 *[], arg3 *[]);//prototype - doesn't have
                          //to be pointer array, but I prefer this notation

int myArray[3][3], myArray2[3][3], myArray[3][3];//create my variables

myFunction(myArray, myArray2, myArray3);//function call

Does that show you how to call the function using the three arrays?

Got it,
Thanks.
My next question is:
I want to overload the operations *+and_ using the class Mat and two class objects of mat to perform the above operations to a matrix of 3 by 3.
How do I pass the function to the defination part
i.e

class Mat
{
public:
Mat;
void setmat();
void display();
operator*(Mat M);
operator+(Mat A);
operator -(Mat S);
private:
int arrayz[3][3];
};
int main()
// Is this output right?
Mat M, N;

Mat K=M+N;
K.display()

K=M*N;
K.display

K=M-N
K.display

Mat Mat::operator +(Mat A)
{
//how do you pass this to main for all the overloaded operators?
}

I will high;y appreciate your help.
Thanks

jeymine 0 Newbie Poster

My Major problem is how I can call the fuction with the two arrays: I couldn't figure out a syntax for it. Let me have an example of how to call this function.
Thank you

jeymine 0 Newbie Poster

HI Guys, I have a question on Multidemensional arrays in matrices:

The question needs one to write a program that of a two 3by3 matrice that adds and also multiplies the two matrices together to display a reulting matrix
Below is my program:

/* Write a C++ program that reads two 3x3 matrices, 
multiply these two matrices together and  displays 
the resulting matrix.*/

#include <iostream>
using namespace std;


void Times(int A[][3], int B[][3],int C[][3]);//prototype int first, int last);
			   
			 


int main()
{
	int N[3][3];
	int M[3][3];
	int K[3][3];
	int i, j;

	{
	
	cout<<"Enter a three by three matrix for first array"<<endl;
	
		
	for(i=0; i<3;i++)//for rows
		{
			for(j=0;j<3;j++)//for columns
		
			cin>>N[i][j];//"\t";
		}
		cout<<" Martix for array N is:\n\n";

		for(i=0; i<3;i++)
			{
				for(j=0;j<3;j++)
			
		
				cout<<N[i][j]<<"\t";
				cout<<endl;
			}
	}

		
//cout<<"Matrix N is:"<<"\n";
	

 cout<<"Enter a three by three matrix for second array"<<endl;

		for(i=0; i<3;i++)
		
		{
			for(j=0;j<3;j++)
		
				cin>>M[i][j];
		}

		cout<<" Martix for array M is:\n\n";

		for(i=0; i<3;i++)
			{	
			for(j=0;j<3;j++)
		
				cout<<M[i][j]<<"\t";
			cout<<endl;
		
		}
		for(i=0;i<3;i++);
		{
				for(j=0;j<3;j++);
		}
				cout<<"The product is:"<<Times(K,3,3)<<endl;
		

	//	cout<<endl;
	

	return 0;
}

void Times(int A[][3], int B[][3],int C[][3])
		{
	int i,j, product;
	
		for(i=0;i<3;i++);
		{
				for(j=0;j<3;j++);
			
				

				product=(A[i][0]*B[0][j]+A[i][1]*B[1][j]+A[i][0]*B[0][j]);
				
				C[i][j]=product;
				
				cout<<C[i][j];
				cout<<endl;
		

		}

	return ;
	
}

Kindly help me with a way to call the function for this multiplication.
Why is it that when you make the array range a global constant, the program does to work out i.r
const int SIZE=3, SIZE=3;
for both i and j?
Thanks in advance

jeymine 0 Newbie Poster

The seed cout part is in the main program after the first [do] statement

if  ((seed>0)||(seed<4000))
					{
				cout<<"\n\n  Enter the lucky number to pick a card...\n\n";
				cin>>seed;
				cout<<"\n";
					}
					else
					{
						cout<<" The number"<<seed<<" is out of range!!\n";
								cin>>start;
								abort();
					}

The == operator is at the end of the main fuction with the > operator.

jeymine 0 Newbie Poster

Below is the complete program for playing the cards: It compiles but as usual picks same cards over again: Problem 1. I need to cout a seed to avoid this problem, where can I locate that. I have tried out( seen in the program) to use if-else statements but they don't work:
2. Only the equals execution is displayed each time, is there a problem with the drwaing of cards?!

#include <iostream>
#include <cstdlib> // for rand(), srand()

using namespace std;

enum Suit
{
   club=1, diamond, heart, spade
};
enum Rank
{
   two = 2, three, four, five, six, seven, eight, nine, ten, 
   jack, queen, king, ace
};


class Card 
{
private:
   Suit color;
   Rank number;
public: 
   Card()
   {
   };
   friend void printcard(Card X);
  
   
   void SetSuit(Suit s )
   {
      color = s;
   }
   void getSuit(); //not used
 
   void SetRank(Rank r )
   {
      number = r;
   } 
   void getRank(); //not used
   void ShowCard(); 
   bool operator > (Card X);
   bool operator==(Card X);
};

int main()
{

		char start;
		int seed=4000;
		int color,number;
	
	Card luckycarda,luckycardb;
	//Luckycarda is the dealer
	//luckycardb is the player
 
   cout<<"\n\n Thank you for choosing to play cards. It is a pleasure to have you in my game.";
   
			do
				{
				
      
					cout<<"\n\n Do you want to draw a card"<<"\n Press Y for yes and n for no"<<endl;
					cin>>start;
					
					if  ((seed>0)||(seed<4000))
					{
				cout<<"\n\n  Enter the lucky number to pick a card...\n\n";
				cin>>seed;
				cout<<"\n";
					}
					else
					{
						cout<<" The number"<<seed<<" is out of range!!\n";
								cin>>start;
								abort();
					}

		if ( start=='Y'||start=='y')
				
	

				{ …
jeymine 0 Newbie Poster

The first part shows a full deck. The second part draws random cards; this was meant to be a hint.

How about putting the switch and its output into printcard? Then you can access the data that is intended to be private and produce just such an error when you try to access it directly.

Hi,
This doen't work either:
Can you kindly compile this:You will see the error am talking about. Thank you. Try to see if it plays the cards: Hope you have the program question. Well, I am a bother but I love learning new things:)

#include <iostream>
#include <cstdlib> // for rand(), srand()
//#include <cmath>
using namespace std;

enum Suit
{
   club=1, diamond, heart, spade
};
enum Rank
{
   two = 2, three, four, five, six, seven, eight, nine, ten, 
   jack, queen, king, ace
};


class Card 
{
private:
   Suit color;
   Rank number;
public: 
   Card()
   {
   };
   void printcard(Card X);
   
   void SetSuit(Suit s )
   {
      color = s;
   }
   void getSuit(); //not used
 
   void SetRank(Rank r )
   {
      number = r;
   } 
   void getRank(); //not used
   void ShowCard(); 
   bool operator > (Card X);
   
};

int main()
{

    char start;
	int seed=4000;
	int color,number;
	
 Card luckycarda,lackycardb;
 
   
   do
   {
      
      cout<<"\n\n Do you want to draw a card"<<"\n Press Y for yes and n for no"<<endl;
      cin>>start;
	  
      if ( start=='Y'||start=='y')

	 
		int seed=4000;
			srand(seed);
			color=rand()%4+1;

	switch(color)
	{

	case 1:luckycarda.SetSuit(club);break;
	case 2:luckycarda.SetSuit(diamond);break;
	case 3:luckycarda.SetSuit(heart);break;
	case 4:luckycarda.SetSuit(spade);break;
	
		
	}
int seed=4000;
srand(seed);
number=rand()%13+1;
	switch(number)
	{
case 1:luckycarda.SetRank(2)break;
case 2:luckycarda.SetRank(3);break;
case …
jeymine 0 Newbie Poster

Uh! That is great. Thanks for the new way I can view it. But your output displays all cards but all the program needs is just to draw one card and make comparison with the other. Well, how does that come in?
I have used the above for the main fuction of the program but still it issues an error on direct reference to private variables on the switch statement.....well this seems weard .
Check this out: at x.color and x.number.
Kindly elucidate on this. Thanks again

void printcard(Card X)
{

    switch(X.color)
    {
    case club:  cout<<"Club ";
                break;
    case diamond:   cout<<"diamond "; 
                    break;
            case heart: cout<<"heart ";
                break;
            case spade: cout<<"space ";

    }
    switch(X.number)
    {
    case two:   cout<<"2"; break;
    case three: cout<<"3"; break;
    case four:  cout<<"4"; break;
    case five:  cout<<"5"; break;
    case six:   cout<<"6"; break;
    case seven: cout<<"7"; break;
    case eight: cout<<"8"; break;
    case nine:  cout<<"9"; break;
    case ten:   cout<<"10"; break;
    case jack:  cout<<"Jack"; break;
    case queen: cout<<"Queen"; break;
    case king:  cout<<"King"; break;
    case ace:   cout<<"Ace"; break;
    }
    cout<<endl;
}
jeymine 0 Newbie Poster

I don't think so. You seed the generator once, and once only per program execution (generally); you call the rand() function for each draw.
You already posted it.

Hi,
here is how the seed is called twice: basically we have to draw two cards, one for the dealer and the other for the player hence have two calls. I will attach the program.

But I need some more clarification on how to use the static_cast in my main function : is there a way I can declare it globally so that I don't have to redefine every function? That is in the main body with switch (color) and switch(number). This is because on compiling the program, the static cast ommition erroris generated.
I really do appreciate your help.
Thanks

#include <iostream>
#include <cstdlib> 

using namespace std;

enum Suit
{
   club=1, diamond, heart, spade
};
enum Rank
{
   two = 2, three, four, five, six, seven, eight, nine, ten, 
   jack, queen, king, ace
};


class Card 
{
private:
   Suit color;
   Rank number;
public: 
   Card()
   {
   };
   void printcard(Card X);
   
   void SetSuit(Suit s )
   {
      color = s;
   }
   void getSuit(); //not used
 
   void SetRank(Rank r )
   {
      number = r;
   } 
   void getRank(); //not used
   void ShowCard(); 
   bool operator > (Card X);
   
};

int main()
{

    char start;
	int seed=4000;
	int color,number;
	
 Card luckycarda,lackycardb;
 
   
   do
   {
      
      cout<<"\n\n Do you want to draw a card"<<"\n Press Y for yes and n for no"<<endl;
      cin>>start;
	  
      if ( …
jeymine 0 Newbie Poster

I meant one has to compare both the rank and suit in each draw between the players and the seed has to be called twice since each player has to draw a card. Can I kindly have the syntax for this?
Thanks

jeymine 0 Newbie Poster

THanks alot.
But I still have a problem with calling the seed when drawing the cards since one has to draw the cards twice, and check for both its rank and seed. How can I do that within the main body function.
Hope to hear from you soon.
Thanks again.

Some touch-ups:

#include <iostream>
#include <cstdlib> // for rand(), srand()
using namespace std;

const int declared_size=64;

enum Suit
{
   club, diamond, heart, spade
};
enum Rank
{
   two = 2, three, four, five, six, seven, eight, nine, ten, 
   jack, queen, king, ace
};

class Card 
{
private:
   Suit color;
   Rank number;
public: 
   Card()
   {
   };
   void printcard(Card X);
   void SetSuit(Suit s )
   {
      color = s;
   }
   void SetRank(Rank r )
   {
      number = r;
   }
   void ShowCard(); 
   bool operator > (Card X);
};

int main()
{

   char start;
   int seed=218;
   srand(seed);
   do
   {
      Card firstCard;
      Card secondCard;
      cout<<"\n\n Do you want to draw a card"<<"\n Press Y for yes and n for no"<<endl;
      cin>>start;
      if ( start=='Y'||start=='y' )
      { //start of if



      } //end of if

      else
      {
         cout<<"\n Thank you for playing"<<"\n Goodbye!!!"<<endl;
      } //end of else

   } while ( start=='y'||start=='Y' );
   return 0;
}

bool Card::operator > (Card X)
{
   if ( number>X.number )return 1;
   else if ( number<X.number )return 0;
   if ( color>X.color ) return 1;
   else return 0;
}
jeymine 0 Newbie Poster

QUOTE=Dave Sinkula: If you ask a question here and want an answer from here, expect it here (it is considered http://www.catb.org/~esr/faqs/smart-questions.html#noprivate]rude to ask someone to privately provide an answer). This also allows potential respondents to gauge a response best suited to your question.

Please post the code of your initial attempt (and remember to post the code within http://www.daniweb.com/techtalkforums/misc.php?do=bbcode#code code tags!

Hi,
Glad to know that. I was in a hurry and never got to read all rules at a go.
Here is what I already have. Trying to fix in parts
Thanks

#include <iostream>
const int declared_size=64;
using namespace std;
enum Suit { club, diamond, heart, spade};
enum Rank { two = 2, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace};
class Card 
{
private:
  Suit color;
  Rank number;
public: 
  Card(){};
  void printcard(Card X);
  void SetSuit(Suit s ){ color = s; }
  void SetRank(Rank r ){ number = r; }
  void ShowCard(); 
  bool operator > (Card X);
};

int main()
{

  do {
    Card firstCard;
    Card secondCard;
    int seed=218;
    char start;
    cout<<"\n\n Do you want to draw a card"<<"\n Press Y for yes and n for no"<<end;
    cin>>start;
    if (start=='Y'||start=='y')
    { \\start of if



    } \\end of if

    else
    {
      cout<<"\n Thank you for playing"<<"\n Goodbye!!!"<<endl;
    } \\end of else

  } while (start=='y'||start=='Y');
  return 0;
}

int Card::operator > (Card X)
{
  if (number>X.number)return 1;
  else if (number<X.number)return 0;
  if (color>X.color) return 1;
  else return …
jeymine 0 Newbie Poster

Hi guys,
I am working on a project on playing cards using enum and class. I really need help with the function defination in this project,
Here i will attach the question, your help will be highly appreciated. You can get bac to me trough jeymineb at yahoo.co.uk.
Thanks.
If you can help, I can give you what Ii have and we can work it out. Thanks again.
Use enum and class to define a Card class. The Card class has two private variables: color and number and all necessary methods including overloaded operator >.

This is how the game is played: Your program asks if the player wants a card, if yes, your program will randomly draw a card (you need to use the random number generator function twice, once for the color and once for the number of card) and displays the player's card on screen. then your program draws a card for dealer and displays the dealer's card as well as the comparison result, such as you win or dealer wins. Use a loop so that the player can play another game if he chooses.

Note on random number generator function.

C++'s library has a rand( ) function you can call to generate a random number between 0 and maximum integer the system allows. It should be seeded with an integer value that is sent to srand(), i.e, you first call srand(seed); before calling the rand( ) function. seed …