hi every please i need your expriment to help to complete this code my problem is with three functions i think so there is no errors
the funcions are
display account...>does not work just display name
transection...>it count jyst one time
standing order...>i do not know how to compare the date the customer enter with the local time

here is the code

#include <vector>
#include <string>
#include <iostream>
#include  <conio.h>
#include<ctime>
#include<math.h>				//Cos,Sin
#include<stdlib.h>				//itoa
#include<string.h>				//strcpy,strcat,strlen

using std::fixed;

using namespace::std;

/////////ACCOUNT///////////////////////////////
class Account
{
 
 string name;
 string AccNum;
 double balance;
 string AccType;
double transfer;

 public:

 Account();//defalt constructor
 
 void setName(string n);//enter customer's name
 string getName();//return customer's name

 void setNum(string n);//enter account's number
 string getNum();//return account's number

 void setbalance(double bal);//enter customer's balance
 double getbalance();//return account's balance

 void settype(string T);
 string gettype();

 void withdraw(double amount);
 void deposit (double amount);
 double zakat();//calculate customer's zakat

 void disolayaccount();//display account info
 friend int	gettime (){
		struct tm *ptr;
		time_t lt;
		lt=time('\0');
		ptr=localtime(&lt);
		cout<<asctime(ptr);
return 0;

}
 

};

///////////////////////BANK//////////////////////////////

class Bank
{
	
 
 vector<Account *> Accs; //A vector of account pointers
double Newbalance;

 string accnum;
 string name;
 string acctype;
 double OpeningBalance;
 double transfer;
public:

 void DisplayAllAccounts();//display all accounts info
 
 void OpenAccount();//open new acount
 
 void CloseAccount(); //close an account

 int FindAccountbyNumber(string accnum);
 //search for an aaccount by account's number
 //Returns the index for the account having this number
 
 void Standing_Order();
int transactions(); 
 void Withdraw();
void Deposit();
 void ShowAccount();
 
};// end of bank


//////////////////TRANSACTIONS/////////////////////////////
int Bank::transactions()
{
int acount_d=0;int acount=0;int count=0;

	Deposit();
	Withdraw();
	acount_d=acount_d+1;
	cout << "\nTotal Deposits: " << acount_d<<endl;
	acount=acount+1;
cout << "\nTotal Withdraw: " << acount<<endl;
count=acount_d+acount;
cout<<"count="<<count;
	return 0;
}

//////////////////STANDING ORDER/////////////////////////////
void Bank::Standing_Order()
{


int sec, min, hr;				//Store time

	gettime ();				//Get time
		//Get Date
char strhr[5] = "",strmin[5] = "",strsec[5] = "";//Store date.

char strdate[30];
//Select day of Month
char strday[][3]={"01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
	       "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
	       "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
//Select month of Year
char strmonth[][10]={"January", "February", "March", "April", "May", "June",
		    "July", "August", "September", "October", "November", "December"};
char stryr[5] = "";//Store year
//Select day of Week
char strwday[][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

	

	while( ! kbhit() ){
	


	
	itoa             (hr, strhr, 10); //Get hours in a string
	if( strlen (strhr) == 1)          //Make it a string having len = 2
	{
		strhr[2]   = '\0';
		strhr[1]   = strhr[0];
		strhr[0]   = '0';
	}
	itoa             (min, strmin, 10);//Get minutes in a string
	if( strlen (strmin) == 1)          //Make it a string having len = 2
	{
		strmin[2]   = '\0';
		strmin[1]   = strmin[0];
		strmin[0]   = '0';
	}
	itoa             (sec, strsec, 10);//Get seconds in a string
	if( strlen (strsec) == 1)          //Make it a string heving len = 2
	{
		strsec[2]   = '\0';
		strsec[1]   = strsec[0];
		strsec[0]   = '0';
	}


}
	/*cout<<"enter the date"<<endl;
	cin>>day>>month>>yr;*/
}

/////////////////DEFAULT CONSTRUCTOR////////////////////////

Account::Account()
{
name="\0";
AccNum="\0";
AccType="\0";
balance=0.0;
transfer=0;
};

///////////////////SET NAME///////////////////

void Account::setName(string n)
{
 name=n;
}

//////////////////SET ACCOUNT NUMBER///////////

void Account::setNum(string n)
{
 AccNum=n;
}

//////////////////SET BALANCE////////////////

void Account::setbalance(double bal)
{
balance=bal;
}

///////////////////SET TYPE////////////////

void Account::settype(string T)
{
AccType=T;
}

//////////////////GET TYPE//////////////////

string Account::gettype()
{
 return AccType;
}

///////////////////GET NAME////////////////

string Account::getName()
{
 return name;
}

/////////////GET ACCOUNT NUMBER////////////

string Account::getNum()
{
 return AccNum;
}

///////////////GET BALANCE////////////////

double Account::getbalance()
{
return balance;
}

////////////////WITHDRAW//////////////////

void Account::withdraw(double amount)
{
int acount=0;
	if (AccType=="PERSONAL")
	{
      balance=balance-amount;
      setbalance(balance);
	}


	if (AccType=="COMPANY")
	{
		balance=balance-amount-0.05;
		setbalance(balance);
}

acount=acount+1;
cout << "\nTotal Withdraw: " << acount;
}


//////////////DEPOSTE///////////////////

void Account::deposit(double amount)
{
	int acount_d=0;
	if (AccType=="personal")
	{
		balance=balance+amount;
		setbalance(balance);
	}

	if (AccType=="company")
	{
		balance=balance+amount-0.05;
		setbalance(balance);
	}
	
	acount_d=acount_d+1;
	cout << "\nTotal Deposits: " << acount_d;
}




/////////////FIND ACCOUNT//////////////

int Bank::FindAccountbyNumber(string accnum)
{

for (int j=0;j<Accs.size();j++)
{
 if (Accs[j]->getNum() == accnum)

  return j;
}
return -1;
}


////////////DisplayAllAccounts//////////////

void Bank::DisplayAllAccounts() 
{
int i;

 cout<<"ENTER THE  NUMBER OF ACCOUNT YOU WANT TO DISPLAY: ";
 cin>>accnum;
cout<<"\nname:"<<name<<endl;
if (i != -1)
  Newbalance = Accs[i]->getbalance();

  cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
 }
/************(BANK)*************************/
/////////////OPEN NEW ACCOUNT////////////////
void Bank::OpenAccount()
{

 int i=0;
 
 cout<<"ENTER CUSTOMER NAME: ";
 cin>>name;
 //Accs[i]->setName(name);

 cout<<"ENTER CUSTOMER BALANCE: ";
 cin>>OpeningBalance;
 //Accs[i]->setbalance(OpeningBalance);

 cout<<"ENTER ACCOUNT'S NUMBER: ";
 cin>>accnum;
 //Accs[i]->setNum(accnum);

 cout<<"ENTER ACCOUNT TYPE (PERSONAL OR COMPANY): ";
 cin>>acctype;
 //Accs[i]->settype(acctype);
 
 Accs.push_back(new Account);
}

////////////CLOSE ACCOUNT///////////////////////

void Bank::CloseAccount()
{
 int i; 
 
 string accnum;
 cout<<"ENTER THE NUMER OF ACCOUNT's YOU WANT TO CLOSE: ";
 cin>>accnum;
 
 i = FindAccountbyNumber(accnum);
 
 if (i != -1)
 {
  vector<Account *>::iterator p = Accs.begin();
  p +=i;//gives the indix of this account
  delete Accs[i];//closing account
  Accs.erase(p,p+1);
 }
}

/////////////////WITHDRAW//////////////////////

void Bank::Withdraw()
{
 int i;
 int acount=0;
 
 string accnum;
 double amount, Newbalance; 
 cout<<"ENTER THE  NUMBER OF ACCOUNT YOU WANT TO WITHDRAW FROM: ";
 cin>>accnum;//the account number from the user

 cout<<"HOW MANY HE SHE WANT TO WITHDRAW? ";
 cin>>amount;//the amount to be withdrawn
 
       //check amounts
 if (amount > OpeningBalance) {
	  Accs[i]->setbalance(OpeningBalance);
	  cout << "Sorry, your account only has $" << OpeningBalance << " dollars\n";}
 
i = FindAccountbyNumber(accnum);
 if (i != -1)
 {
  Accs[i]->withdraw(amount);
  //Get the current balancel
  Newbalance = Accs[i]->getbalance();
  cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
 
}
//transfer = transfer - amount;
 acount=acount+1;
cout << "\nTotal Withdraw: " << acount;
}
////////////////DEPOSITE////////////////////////
void Bank::Deposit(){
 int i;
 int acount_d=0;

 char ch;
  
 double amount, Newbalance; 

 cout<<"ENTER THE ACCOUNT S NUMBER YOU WANT TO DEPOSE TO: ";
 cin>>accnum;//the account number from the user

 cout<<"HOW MANY HE/SHE WANT TO DEPOSE? ";
 cin>>amount;//the amount to be depsite

 i = FindAccountbyNumber(accnum);

 if (i != -1)
 {
  Accs[i]->deposit(amount);
  //Get the current balance

  Newbalance = Accs[i]->getbalance();
//Newbalance = balance+amount;
  cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
  	
	acount_d=acount_d+1;
	cout << "\nTotal Deposits: " << acount_d;
	cout<<"do you want to deposit another amount(y/n)"<<endl;
	cin>>ch;
	if(ch=='y')
		exit(1);
}

}

  	//transfer =transfer + amount;
//////////////Display///////////////////////////
void Bank::ShowAccount() 
{
int i;

 cout<<"ENTER THE  NUMBER OF ACCOUNT YOU WANT TO DISPLAY: ";
 cin>>accnum;
cout<<"\nname:"<<name<<endl;
if (i != -1)
  //Newbalance = Accs[i]->getbalance();

  cout<<"NEW BALANCE = "<<Newbalance<<endl;//Display the current balance
 }


///////////////////////MAIN/////////////////////////
void main()
{
 Bank b;

char choice;


 bool flag =0;
while (flag == false) {
      cout << "\t\t\n\n" << "Main Menu";
      cout << "\t\n\n" << "Select by letter:";
      cout << "\t\n" << "o - open new account.";
      cout << "\t\n" << "d - Deposit money.";
      cout << "\t\n" << "w - Withdraw money.";
      cout << "\t\n" << "v - Show Account Information.";
      cout<<"\t\n"<<"t- transiction";
	  cout<<"\t\n"<<"s- standing order";
      cout << "\t\n" << "c _ close account.";
      cout << "\t\n" << "q - Quit Application.\n\n";
      cout << "\t" << "Choice: ";
      cin>>choice ;
	  // END OF THE MENU
	  cout<<fixed;
      switch(choice) {
         case 'o':
            system("cls");
            b.OpenAccount();
            
            break;

         case 'd':
            system("cls");
            
            b.Deposit();
            
            break;

         case 'w':
            system("cls");
           
            b.Withdraw();
              
            system("cls");
            break;
         case 'v':
            system("cls");
            
            b.DisplayAllAccounts();
            getche();
            system("cls");

            break;
		case 't':
            system("cls");
            
           b.transactions();
		   
          getche();
            break;
		case 's':
            system("cls");
            
           b.Standing_Order();
		   
          getche();
            break;
		
		 
           case 'c':
            system("cls");
            
            b.CloseAccount();
			
            system("cls");
            break;

         case 'q':
            flag = 1;
            break;

         default:
            cout << "\nInvalid selection. Press a key to return to main menu.";
           
      }

      if (flag == true) {
         break;
      }

   }
   
  
}

Recommended Answers

All 6 Replies

please help me please

If you'd posted a normal topic line someone'd likely have come along already.
As it is I'm disinclined to even try, I only dropped in to kill some time ;)

You state yourself there are no errors, so I wonder what the problem is?

hi jwenting there is no compiler error i think there is some think logical that why some function didn't work as expected
display just show the name without balance
transection count the operator just one time
standing order i don't know how to compare the time the user insert with the local time

that's it

i do not know how to compare the date the customer enter with the local time

use the struct tm and associated functions that are in time.h. get local time in time_t (an unsigned int) -- time() function returns that. Then convert the time string the user enters into struct tm, you will have to parse the string and apply its individual parts to the structure. After you have done that, call mktime() to convert struct tm into time_t. Now all you have to do is compare the two time_t objects using normal integer comparison operators.

To me a standing order means add/delete a certain amount on a certain day of each month. Obviously there are other definitions, too, so you really need to decide exactly what you want to do. It could be as simple as extracting the day of the month field from the time_t struct you get from local_time and looking at each Account to see if they have a standing order. If so, what day of the month is the standing order to be done. If the two dates are the same proceed with a transaction based on the standing order.

for each account
if day of month from time_t == day of month for standing order
then do transaction listed in standing order

For that matter, do you even need to use local_time. If you aren't familar with items in ctime header file you could just ask user to input day of month when they want to enter a transaction as opposed to having the computer input the data for you. Not as slick as having the computer running all the time, automatically monitoring the day of the month, and running standing orders automatically, but certainly less complicated to code, and probably meets the assignment criteria.

Maybe it's the yucky green font but I can't find where you define Account::disolayAccount(). I do see Bank::ShowAccount() and in there I strongly recommend to initialize 1 to some value before you try to compare i with -1.

I'm not sure where you are refering to transection, but if it is Bank::transaction() and you are trying to do more than one transaction withing the function (I note you have both deposit and withdrawal listed) then you I would suggest you use a loop similar to the one you used with menu.

thanks all i will try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.