C++ programming help

#include<fstream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>


class account
{
int acno;
char name[50];
int deposit;
char type;
int d,m,y,dd,mm,yy;
int dur;
double capital;
double int_amt;
public:
void create_account(); //to get data from user
void show_account(); // to show data on screen
void modify();//to get new data from user
void dep(int)// to accept amount and add to balance amount
void draw(int); // accept amount and subtract from balance amount
void report(); // show data in tabular format
int retacno(); //return account number
int retdeposit(); //return balance amount

double fd();

};

void account::create_account()
{ char ch;
cout<<"\nEnter The account No.";
cin>>acno;
cout<<"\n\nEnter The Name of The account Holder : ";
gets(name);

cout<<"\nEnter The Initial amount: ";
cin>>deposit;
cout<<"Do you want to invest in a Fixed Deposit?\n";
cout<<"Enter Y or N:\n";
cin>>ch;
if(ch=='Y'||'y')
{
cout<<"Enter the capital amount:\n";
cin>>capital;
cout<<"Enter the period of investment:\n";
cin>>dur;
cout<<"Current rate of interest = 10.5\n";
int_amt=(capital*dur*10.5)/100;
cout<<"Enter the date of investment:\n(Strictly enter in DD MM YYYY format)\n";
cin>>d>>m>>y;

dd=d-1;
mm=m;
yy=y+dur;
cout<<"\n\n\nAccount Created..";
}

}

double account:: fd()
{

int d1,m1,y1; double total;
cout<<"Enter today's date:\n(DD MM YYYY)";
cin>>d1>>m1>>y1;

if(y1>yy||(y1==y&&m1>mm)||(y1==y&&m1==mm&&(d1>dd||d1==d)))
{
total=capital+int_amt;
return total;
}

else
return 0;
}



void account::show_account()
{
cout<<"\nAccount No. : "<<acno;
cout<<"\nAccount Holder Name : ";
cout<<name;
//cout<<"\nType of Account : "<<type;
cout<<"\nBalance amount : "<<deposit;
}


void account::modify()
{
cout<<"\nThe account No."<<acno;
cout<<"\n\nEnterName of The account Holder : ";
gets(name);
//cout<<"\nEnter Type of The account (C/S) : ";

cout<<"\nEnter The amount : ";
cin>>deposit;
}


void account::dep(int x)
{
deposit+=x;
}

void account::draw(int x)
{
deposit-=x;
}

void account::report()
{
cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<deposit<<endl;
}

int account::retacno()
{
return acno;
}

int account::retdeposit()
{
return deposit;
}



void write_account(); //to write record in binary file
void display_sp(int); // to display account details given by user
void modify_account(int); // to modify record of file
void delete_account(int); // to delete record of file
void display_all();
void update_fd(int); //to display all account details
void deposit_withdraw(int, int); // to desposit/withdraw




int main()
{
char ch;
int num;
clrscr();
intro();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW ACCOUNT";
cout<<"\n\n\t02. DEPOSIT AMOUNT";
cout<<"\n\n\t03. WITHDRAW AMOUNT";
cout<<"\n\n\t04. BALANCE ENQUIRY";
cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST";
cout<<"\n\n\t06. CLOSE AN ACCOUNT";
cout<<"\n\n\t07. MODIFY AN ACCOUNT";
cout<<"\n\n\t*. UPDATE FD\n";
cout<<"\n\n\t08. EXIT";
cout<<"\n\n\tSelect Your Option (1-8) ";
cin>>ch;
clrscr();
switch(ch)
{
case '1':
write_account();
break;
case '2':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 1);
break;
case '3':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 2);
break;
case '4':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
delete_account(num);
break;
case '7':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
modify_account(num);
break;
case '*':
cout<<"Enter the acc. no:\n";
cin>>num;
update_fd(num);
case '8':
cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :cout<<"\a";
}
getch();
}while(ch!='8');
return 0;
}



void write_account()
{
account ac;
ofstream outFile;
outFile.open("account.dat",ios::binary|ios::app);
ac.create_account();
outFile.write((char *) &ac, sizeof(account));
outFile.close();
}


void update_fd(int n)
{
int amt; double c;double t;
int found=0;
account ac;
fstream File;
File.open("account.dat", ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(File.read((char *) &ac, sizeof(account)) && found==0)
{
if(ac.retacno()==n)
{
ac.show_account();
c=ac.fd();
if(c!=0)
{
t=c;
ac.dep(t);
}
else
{
cout<<"Investment date is beyond today's date?\n";
}
int pos=(-1)* sizeof(ac);
File.seekp(pos,ios::cur);
File.write((char *) &ac, sizeof(account));
cout<<"\n\n\t Record Updated";
found=1;
}
}
File.close();
if(found==0)
cout<<"\n\n Record Not Found ";
}

void display_sp(int n)
{
account ac;
int flag=0;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<"\nBALANCE DETAILS\n";
while(inFile.read((char *) &ac, sizeof(account)))
{
if(ac.retacno()==n)
{
ac.show_account();
flag=1;
}
}
inFile.close();
if(flag==0)
cout<<"\n\nAccount number does not exist";
}



void modify_account(int n)
{
int found=0;
account ac;
fstream File;
File.open("account.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(File.read((char *) &ac, sizeof(account)) && found==0)
{
if(ac.retacno()==n)
{
ac.show_account();
cout<<"\n\nEnter The New Details of account"<<endl;
ac.modify();
int pos=(-1)*sizeof(account);
File.seekp(pos,ios::cur);
File.write((char *) &ac, sizeof(account));
cout<<"\n\n\t Record Updated";
found=1;
}
}
File.close();
if(found==0)
cout<<"\n\n Record Not Found ";
}



void delete_account(int n)
{
account ac;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
outFile.open("Temp.dat",ios::binary);
inFile.seekg(0,ios::beg);
while(inFile.read((char *) &ac, sizeof(account)))
{
if(ac.retacno()!=n)
{
outFile.write((char *) &ac, sizeof(account));
}
}
inFile.close();
outFile.close();
remove("account.dat");
rename("Temp.dat","account.dat");
cout<<"\n\n\tRecord Deleted ..";
}


void display_all()
{
account ac;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout<<"=========================================\n";
cout<<"A/c no. NAME Balance\n";
cout<<"=========================================\n";
while(inFile.read((char *) &ac, sizeof(account)))
{
ac.report();
}
inFile.close();
}


void deposit_withdraw(int n, int option)
{
int amt;
int found=0;
account ac;
fstream File;
File.open("account.dat", ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(File.read((char *) &ac, sizeof(account)) && found==0)
{
if(ac.retacno()==n)
{
ac.show_account();
if(option==1)
{
cout<<"\n\n\tTO DEPOSIT AMOUNT ";
cout<<"\n\nEnter The amount to be deposited";
cin>>amt;
ac.dep(amt);
}
if(option==2)
{
cout<<"\n\n\tTO WITHDRAW AMOUNT ";
cout<<"\n\nEnter The amount to be withdraw";
cin>>amt;
int bal=ac.retdeposit()-amt;
if(bal<50)
cout<<"InsufficienT balance";
else
ac.draw(amt);
}
int pos=(-1)* sizeof(ac);
File.seekp(pos,ios::cur);
File.write((char *) &ac, sizeof(account));
cout<<"\n\n\t Record Updated";
found=1;
}
}
File.close();
if(found==0)
cout<<"\n\n Record Not Found ";
}




END




I have written a C++ program that implements a savings cum fixed deposit accounts. Howe ever, i am not able to get the output - the balance doesn't increase when the amount in FD has matured. I have attached my code with the mail. Looking forward for your help.

Program Logic
Updating FD:
Take date of investment from user
Compute date of maturity based on duration input
During transaction, ask the user to input today's date; if date of maturity is BEHIND current date, update account balance with (capital_fd + interest_amt)
BUG IN PROGRAM : After updating FD, the new account balance(that should have (capital_fd + interest_amt) is not reflected).
Thanks in advance.





It looks like you are using terribly (at least 12 years) outdated compiler with lax standard enforcement. You code should not work on any modern compilers.

I would look into following line: if(y1>yy||(y1==y&&m1>mm)||(y1==y&&m1==mm&&(d1>dd||d1==d)))

Are you sure there should be y and d instead of yy and dd?
Last edited on
I made the correction. But i'm still not getting the output.
Topic archived. No new replies allowed.