RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 3942 | Replies: 11
Reply
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

bank account

  #1  
Jul 21st, 2005
Hi, I have a big project (#1). this is its direction:
Project I

Software for a Bank

Write a C++ program for the following task:
a) Should allow 5 users with user name & password [ (Ohlone1, Ohlone1pw), (Ohlone2, Ohlone2pw),( Ohlone3, Ohlone3pw), (Ohlone4, Ohlone4pw), (Ohlone5, Ohlone5pw)]

b) Display a welcome / greeting .

c) Menu driven program to allow ‘View Balance’, ‘Deposit’, ‘Withdraw’, ‘Transfer’ and ‘Exit’. Start with a beginning balance of 1000.00 in checking and 1500.00 in savings.

These are the general specifications, use your creativity to make program user friendly.


So far I've laid out the general scheme in the following code. But I have no idea how to do the depositing, withdrawing, or the transfering...worse yet...How can you show these amounts on the "view Balance"?
Do I have to repeat this for each and every user? Is there a simpler way to simplify this process?

//Term Project #1 - 100 points
//SOFTWARE FOR A BANK 
//Write a C++ program for the following task using modular approach.
//a)    Should allow  5 users with user name & password :
//[ (Ohlone1, Ohlone1pw), (Ohlone2, Ohlone2pw),( Ohlone3, Ohlone3pw), (Ohlone4, Ohlone4pw), (Ohlone5, Ohlone5pw)]
//b)    Display a welcome / greeting .
//c)    Menu driven program to allow: 
//‘View Balance’, 
//‘Deposit’, 
//‘Withdraw’, 
//‘Transfer’ 
//and ‘Exit’. 
//Start with a beginning balance of 1000.00 in checking and 1500.00 in savings.

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

//PROTOTYPE;
void Signin();
void Menu1();
void ViewBalance1();
void Ohlone1_balance();
void Ohlone1_Deposit();
void Ohlone1_Withdraw();
void Ohlone1_Transfer();
void Ohlone1_Checking();
void Ohlone1_Saving();


void main (void)
{

	cout << "WELCOME TO PROGRAMMING BANK!\n\n";
	cout << "~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~\n\n";
	Signin ();
	Menu1 ();
}

void Signin ()
{
	char username[31], PW[20];

	cout << "Please enter your username: \n";
	cin.width(32);
	cin >> username;
	do 
	{
		//User 1
		if (strcmp(username, "Ohlone1") ==0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			for (int i = 0; i < PW; i++)
			{
				cout << "*";  //How come this technique deosn't work?
			}
			if (strcmp(PW, "Ohlone1pw") == 0)
				cout << "\n\n\tYou are logged in!\n\t";
			else 
			{
				cout << "Your password was entered incorrectly.\n";
				cout << "Please enter your password again.\n";
				cin >> PW;
				if (strcmp(PW, "Ohlone1pw") == 0)
					cout << "\n\n\tYou are logged in!\n\n";
				else 
				{
					cout << "I'm sorry you're having trouble.\n";
					break;
				}
			}
			return;
		}
		//User 2
		else if (strcmp(username, "Ohlone2") ==0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			if (strcmp(PW, "Ohlone2pw") == 0)
				cout << "\n\n\tYou are logged in!\n\n";
			else 
			{
				cout << "Your password was entered incorrectly.\n";
				cout << "Please enter your password again.\n";
				cin >> PW;
				if (strcmp(PW, "Ohlone2pw") == 0)
					cout << "\n\n\tYou are logged in!\n\n";
				else
				{
					cout << "I'm sorry you're having trouble.\n";
					break;
				}
			}
			return;
		}
		//User 3
		else if (strcmp(username, "Ohlone3") == 0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			if (strcmp(PW, "Ohlone3pw") == 0)
				cout << "\n\n\tYou are logged in!\n\n";
			else 
			{
				cout << "Your password was entered incorrectly.\n";
				cout << "Please enter your password again.\n";
				cin >> PW;
				if (strcmp(PW, "Ohlone3pw") == 0)
					cout << "\n\n\tYou are logged in!\n\n";
				else
				{
					cout << "I'm sorry you're having trouble.\n";
					break;
				}
			}
			return;
		}
		//User 4
		else if (strcmp(username, "Ohlone4") == 0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			if (strcmp(PW, "Ohlone4pw") == 0)
				cout << "\n\n\tYou are logged in!\n\n";
			else 
			{
				cout << "Your password was entered incorrectly.\n";
				cout << "Please enter your password again.\n";
				cin >> PW;
				if (strcmp(PW, "Ohlone4pw") == 0)
					cout << "\n\n\tYou are logged in!\n";
				else 
				{
					cout << "I'm sorry you're having trouble.\n";
					break;
				}
			}
			return;
		}
		//User 5
		else if (strcmp(username, "Ohlone5") == 0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			if (strcmp(PW, "Ohlone5pw") == 0)
				cout << "\n\n\tYou are logged in!\n\n";
			else 
			{
				cout << "Your password was entered incorrectly.\n";
				cout << "Please enter your password again.\n";
				cin >> PW;
				if (strcmp(PW, "Ohlone5pw") == 0)
					cout << "\n\n\tYou are logged in!\n\n";
				else
				{
					cout << "I'm sorry you're having trouble.\n";
					break;
				}
			}
			return;
		} 
	}while (strcmp(username, "Ohlone1") == 0 || (username, "Ohlone2") == 0 || 
		(username, "Ohlone3") == 0 || (username, "Ohlone4") ==0 || (username, "Ohlone5") == 0);
     
	if (strcmp(username, "Ohlone1") != 0 || (username, "Ohlone2") != 0 || 
		(username, "Ohlone3") != 0 || (username, "Ohlone4") !=0 || (username, "Ohlone5") != 0)
	{
		cout << "your enter your username incorrectly.\n";
		cout << "Please try again.\n";
	}
	return;
	}
void Menu1 ()
{
	int choice;

	cout << "\nWHAT WOULD YOU LIKE TO DO?\n";
	cout << "\n*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n\n";
	cout << "\t1. View Your Balance.\n";
	cout << "\t2. Deposit.\n";
	cout << "\t3. Withdraw.\n";
	cout << "\t4. Transfer.\n";
	cout << "\t5. Exit.\n\n";
	cout << "Please enter your choice: \n";
	cin >> choice; 
	if (choice ==1)
	{
		Ohlone1_balance();
	}
	else if (choice ==2)
	{
		Ohlone1_Deposit();
	}
	else if (choice ==3)
	{
		Ohlone1_Withdraw();
	}
	else if (choice ==4)
	{
		Ohlone1_Transfer();
	}
	else if (choice ==5)
	{
		cout << "You have chosen to exit the menu.\n";
		cout << "Thank you for visiting Programming Bank.\n";
		return;
	}
}

void Ohlone1_balance ()
{
	//cout << "Your checking account has : " << << endl;
	//cout << "Your saving account has : " <<  << endl;
}

void Ohlone1_Checking (float *amount)
{
	//amount = 1000;

}

void Ohlone1_Saving (float *amount)
{
	//amount = 1500;
}

void Ohlone1_Deposit ()
{
	int input;
	float deposit; 

	cout << "Which account would you like to deposit to?\n";
	cout << "1. Checking Account\n";
	cout << "2. Saving Account\n";
	cin  >> input;
	if (input = 1)
	{
		cout << "How much do you want to deposit to the Checking Account?\n";
		cin >> deposit;
	}
	if (input =2)
	{
		cout << "How much do you want to deposit to the Saving Account?\n";
		cin >> deposit;
	}
}

void Ohlone1_Transfer ()
{
	int input;

	cout << "Would you like to transfer..\n\n";
	cout << "1. From CHECKING to SAVING\n";
	cout << "\nOR\n\n";
	cout << "2. From SAVING to CHECKING\n";
	cin >> input;
	if (input = 1)
	{
		// C_to_S ();
	}
	if (input = 2)
	{
		// S_to_C ();
	}
}

void Ohlone1_Withdraw ()
{
	int input;
	float withdraw;

	cout << "From which account would you like to withdraw?\n";
	cout << "1. Checking\n";
	cout << "2. Saving\n";
	cin >> input;
	if (input = 1)
	{
		cout << "How much would you like to withdraw from the Checking account?\n";
		cin >> withdraw;
		//what to do here? 
	}
	if (input = 2)
	{
		cout << "How much would you like to withdraw from the Saving account?\n";
		cin >> withdraw;
		//what to do here?
	}
}

I know it's really long. But can you guys help please?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: bank account

  #2  
Jul 21st, 2005
Did you learn about structs or classes recently?
Reply With Quote  
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

Re: bank account

  #3  
Jul 21st, 2005
umm...no...I'm a level-1 beginner.
You can tell from my coding that I'm pretty much clueless in C++.
Reply With Quote  
Join Date: Apr 2004
Posts: 3,765
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: bank account

  #4  
Jul 21st, 2005
This is assignment. (The subsequent comparison is always true.)
if (input = 1)
This is comparison.
if (input == 1)
Ever here the phrase, "What happens in Vegas stays in Vegas" (or something similar)? Well, function are like that too. Whatever happens to a local variable inside a function is lost on the outside of that function. So if you want to keep track of something, you would want to be passing parameters to a function and returning values from them to "communicate" with one another.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: bank account

  #5  
Jul 21st, 2005
Just outta curiosity, are you learning this stuff in a class, or from a book?

And everyone starts at level 1.

I'm just asking so that you go down the right path for the class, but if it's from a book and this is just for your own betterment, I'll show you how to do these things with structs and classes.

Aaaanyway: For your concerns about deposits, withdrawals, and transfers:
You should have two variables for monetary values. Savings and checking, let's call 'em.
What you do is you declare and initialize them like so:

float checking = 1000.;
float savings = 1500.;

and that gives you the initial values.

When you want to make a deposit, you need to specify checking or savings, and then add the appropriate amount (from user input) to the appropriate account.

Making a withdrawal is a little tougher. Once you've specified savings or checking, you need to make sure that the user doesn't overdraw their account. That means you have to use an 'if' statement to check that the amount of money to be withdrawn is less than or equal to the current value held in the account.


What you'd want is something like this:
float deposit(int account_type);
//Asks for amount to add, and returns the new value of the appropriate account.

float withdraw(int account_type); 
//Asks, Error checks the balance, returns the value of the balance if transaction is good. Otherwise, returns a -1.0

The transfers, though... That's a little odd.
You can't return two values from a function, you have to use pointers...
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: bank account

  #6  
Jul 21st, 2005
As I didn't see any rules against double posting in this fashion, I thought it best to split this off to help seperate the topic, as my last one was far too heavily edited and almost unusable.

Yes, your current code is far too redundant. If you ever have code that is repeated with only minor changes like the name entered, there's a better, faster way to do it.

Let me introduce you to your friend and mine, 'Switch'.
Switch is, for an integer input (like a menu choice), a very handy tool.

int menu_sel;

//Get your menu selection somehow.

switch(menu_sel){
       case 0:  //menu selection for, I dunno... Deposits.
            Your deposit function;
       case 1: //Let's say, withdrawals.
            your withdraw function;
       case 2: //for whatever else you want. Just keep adding cases.
       default: //This  must always be at the end of the  cases. It catches anything that wasn't supposed to come through. So, if someone enters G, it'll be caught here.
        break; //It's always a good idea to use 'break' in the default. Just do it, it's good, safe coding.
} //end of the switch statement.

That'll help a little. More importantly, you'll need to make it so that you have one generic login, not five. You can do this a number of ways, but the lowest-level one would be to have two arrays of strings, . One for the names, one for the associated passwords.
Also, two arrays (or one 2-D array) of floats for the balances.

You do the log in by asking for a string, and iterate through the name array to find a match with strcmp. If there's a match, you prompt the user for a password and do the same thing with the password array, looping until they get it right.

Then, you just keep the increment counter in memory, and refer to the array for the name of the person and their bank balances. This way, you don't have to write up a huge amount of redundant code, and you just manipulate the balances by referring to their locations in the arrays...

Make sense?
Reply With Quote  
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

Re: bank account

  #7  
Jul 21st, 2005
Originally Posted by Drowzee
As I didn't see any rules against double posting in this fashion, I thought it best to split this off to help seperate the topic, as my last one was far too heavily edited and almost unusable.

Yes, your current code is far too redundant. If you ever have code that is repeated with only minor changes like the name entered, there's a better, faster way to do it.

Let me introduce you to your friend and mine, 'Switch'.
Switch is, for an integer input (like a menu choice), a very handy tool.

int menu_sel;

//Get your menu selection somehow.

switch(menu_sel){
       case 0:  //menu selection for, I dunno... Deposits.
            Your deposit function;
       case 1: //Let's say, withdrawals.
            your withdraw function;
       case 2: //for whatever else you want. Just keep adding cases.
       default: //This  must always be at the end of the  cases. It catches anything that wasn't supposed to come through. So, if someone enters G, it'll be caught here.
        break; //It's always a good idea to use 'break' in the default. Just do it, it's good, safe coding.
} //end of the switch statement.

That'll help a little. More importantly, you'll need to make it so that you have one generic login, not five. You can do this a number of ways, but the lowest-level one would be to have two arrays of strings, . One for the names, one for the associated passwords.
Also, two arrays (or one 2-D array) of floats for the balances.

You do the log in by asking for a string, and iterate through the name array to find a match with strcmp. If there's a match, you prompt the user for a password and do the same thing with the password array, looping until they get it right.

Then, you just keep the increment counter in memory, and refer to the array for the name of the person and their bank balances. This way, you don't have to write up a huge amount of redundant code, and you just manipulate the balances by referring to their locations in the arrays...

Make sense?
Hi, i've tried the login part of your suggestion. But I don't know why I can't get get it to compile. this is my code. do you know what I did wrong?

#include <iostream>
#include <iomanip>
#include <string>
#include <stdlib.h>

using namespace std;

//Function Prototypes
string Signin (string, string);
void Menu ();
void ViewBalance ();
void Deposit ();
void Withdrawal ();
void Transfer ();


void main (void)
{
	string Username[] = {"Ohlone1","Ohlone2","Ohlone3","Ohlone4","Ohlone5"};
	string PWmain[] = {"Ohlone1pw", "Ohlone2pw", "Ohlone3pw", "Ohlone4pw", "Ohlone5pw"};
	
	cout << "WELCOME TO PROGRAMMING BANK!\n\n";
	cout << "~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~\n\n";

	Signin (*Username, *PWmain);
	Menu ();
}

string Signin (string &userID, string &PWuser)
{
	string ID, PW;
	cout << "Please enter your username: \n";
	cin.width(32);
	cin >> ID;
	
	for (int i =0; i < 5; i++)
	{ 
		if (strcmp(ID, userID[i]) == 0)
		{
			cout << "Please enter your password: \n";
			cin >> PW;
			for (int j =0; i < 5; i++)
			{
				if (strcmp(ID, PWuser[i])  ==0)
				{
					cout << "YOU'RE LOGGED IN!\n";
				}
			}
		}
	}
}

void Menu ()
{
	int choice; 

	cout << "\t1. View Your Balance.\n";
	cout << "\t2. Deposit.\n";
	cout << "\t3. Withdraw.\n";
	cout << "\t4. Transfer.\n";
	cout << "\t5. Exit.\n\n";
	cout << "Please enter your choice: \n";
	cin >> choice; 
	switch (choice)
	{
	case 1: 
		{
			//cout << "Your checking account has : " << << endl;
			//cout << "Your saving account has : " <<  << endl;
		}
	case 2:
		{
			//deposit
		}

	case 3:
		{
			//withdrawal
		}

	case 4:
		{
			//transfer
		}

	default:
		{
			cout << "Thank you for using this program.\n";
			break;
		}
	}
}

void ViewBalance ()
{
	//cout << "Your checking account has : " << << endl;
	//cout << "Your saving account has : " <<  << endl;
}

void Deposit ()
{
	int input;
	float deposit; 

	cout << "Which account would you like to deposit to?\n\n";
	cout << "1. Checking Account\n";
	cout << "2. Saving Account\n";
	cin  >> input;
	if (input = 1)
	{
		cout << "How much do you want to deposit to the Checking Account?\n\n";
		cin >> deposit;
		//What to do here?
	}
	if (input =2)
	{
		cout << "How much do you want to deposit to the Saving Account?\n";
		cin >> deposit;
		//What to do here?
	}
}

void Transfer ()
{
	int input;

	cout << "Would you like to transfer..\n\n";
	cout << "1. From CHECKING to SAVING\n";
	cout << "\nOR\n\n";
	cout << "2. From SAVING to CHECKING\n";
	cin >> input;
	if (input = 1)
	{
		// C_to_S ();
	}
	if (input = 2)
	{
		// S_to_C ();
	}
}

void Withdrawal ()
{
	int input;
	float withdraw;

	cout << "From which account would you like to withdraw?\n\n";
	cout << "1. Checking\n";
	cout << "2. Saving\n";
	cin >> input;
	if (input = 1)
	{
		cout << "How much would you like to withdraw from the Checking account?\n\n";
		cin >> withdraw;
		//what to do here? 
	}
	if (input = 2)
	{
		cout << "How much would you like to withdraw from the Saving account?\n";
		cin >> withdraw;
		//what to do here?
	}
}


did I do the switch thing right?
Reply With Quote  
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

Re: bank account

  #8  
Jul 21st, 2005
uh...to answer your question, Drowzee, I'm taking this introduction to C++ class in a college (ohlone, if you know the name) right now and it's in the summer. the class is normall 3 months long but since it's in the summer, it's only 6 weeks! WAHHH!! But the same materials have to be covered, so it's like 3 chapters a week! So even though, I'm taking the class, I'm basically on my own 'cause the teacher barely has time for lectures, let alone helping individual students (although all of my classmates seem to know what they're doing, I'm always the last one to turn in something, even tests).That's why I'm constantly asking for help. It took forever to figure out what I did wrong, or just to figure out what to do!
Reply With Quote  
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

Re: bank account

  #9  
Jul 21st, 2005
thanks, Drowzee
it makes sense all right. I'm trying to do it right now.
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: bank account

  #10  
Jul 21st, 2005
Cool.

Just to make sure I'm not confusing you:
Once you've got a valid userID, you only need to check the associated password, and loop the password prompt until it's entered correctly.

Also: Trying to get asterisks (*) entered instead of characters requires a lot more effort than it's worth to you right now.
It'd be better to just leave that kind of functionality alone.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:15 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC