computer science practical

18
 FROM:- XII- ROLL NO.:- 

Upload: harshitswami

Post on 02-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 1/18

 

FROM:-

XII-

ROLL NO.:- 

Page 2: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 2/18

 

 

Introduction  

 Classes Headerfiles & Datafiles  

 Program Coding  

 

Program Output(s)  

 Bibliography

:

Page 3: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 3/18

 

Page 4: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 4/18

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

#include<dos.h>

//***************************************************************// CLASS USED IN PROJECT//****************************************************************

class account{

int acno;char fname[50];char mname[50];char lname[50];char sex;char dateofbirth[20];char fathername[50];char mothername[50];char address[80];char city[15];char state[15];char country[50];

char pincode[15];int balance;char type;

 public:void create_account(); //function to get data

from uservoid show_account(); //function to show data

on screenvoid modify(); //function to get new data from

user

void dep(int); //function to accept amount andadd to balance amount

void draw(int); //function to accept amountand subtract from balance amount

void report(); //function to show data in tabularformat

int retacno(); //function to return accountnumber

Page 5: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 5/18

  int retdeposit(); //function to return balanceamount

char rettype(); //function to return type ofaccount}; //class ends here

void account::create_account(){

cout<<"\nAccount No. : ";cin>>acno;cout<<"\nFirst Name of The Account Holder : ";gets(fname);cout<<"\nMiddle Name of The Account Holder : ";gets(mname);cout<<"\nLast Name of The Account Holder : ";gets(lname);cout<<"\nEnter Sex : ";cin>>sex;cout<<"\nEnter Date of Birth DD/MM/YYYY : ";gets(dateofbirth);cout<<"\nFather's Name : ";gets(fathername);cout<<"\nMother's Name : ";gets(mothername);cout<<"\nEnter Address : ";gets(address);cout<<"\nEnter City : ";gets(city);

cout<<"\nEnter State : ";gets(state);cout<<"\nEnter Country : ";gets(country);cout<<"\nEnter Pincode : ";gets(pincode);cout<<"\nEnter type of account (C/S) : ";cin>>type;type=toupper(type);cout<<"\nInitial amount : ";cin>>balance;

}

void account::show_account(){

cout<<"\nAccount No. : "<<acno;cout<<"\nFirst Name of The Account Holder : "<<fname;cout<<"\nMiddle Name of The Account Holder : "<<mname;cout<<"\nLast Name of The Account Holder : "<<lname;

Page 6: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 6/18

  cout<<"\nEnter Sex : "<<sex;cout<<"\nEnter Date of Birth DD/MM/YYYY :

"<<dateofbirth;cout<<"\nFather's Name : "<<fathername;cout<<"\nMother's Name : "<<mothername;

cout<<"\nEnter Address : "<<address;cout<<"\nEnter City : "<<city;cout<<"\nEnter State : "<<state;cout<<"\nEnter Country : "<<country;cout<<"\nEnter Pincode : "<<pincode;cout<<"\nEnter type of account (C/S) : "<<type;cout<<"\nInitial amount : "<<balance;

}

void account::modify(){

cout<<"\nAccount No. : "<<acno;cout<<"\nFirst Name of The Account Holder : ";gets(fname);cout<<"\nMiddle Name of The Account Holder : ";gets(mname);cout<<"\nLast Name of The Account Holder : ";gets(lname);cout<<"\nEnter Sex : ";cin>>sex;cout<<"\nEnter Date of Birth DD/MM/YYYY : ";gets(dateofbirth);

cout<<"\nFather's Name : ";gets(fathername);cout<<"\nMother's Name : ";gets(mothername);cout<<"\nEnter Address : ";gets(address);cout<<"\nEnter City : ";gets(city);cout<<"\nEnter State : ";gets(state);cout<<"\nEnter Country : ";

gets(country);cout<<"\nEnter Pincode : ";gets(pincode);cout<<"\Enter type of account (C/S) : ";cin>>type;type=toupper(type);cout<<"\nAmount : ";cin>>balance;

Page 7: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 7/18

}

void account::dep(int x){

 balance+=x;}

void account::draw(int x){

 balance-=x;}

void account::report(){

cout<<acno<<setw(10)<<" "<<fname<<" "<<mname<<""<<lname<<setw(10)<<" "<<type<<setw(25)<<balance<<endl;}

int account::retacno(){

return acno;}

int account::retdeposit(){

return balance;}

char account::rettype(){

return type;}

//***************************************************************// function declaration//*********************************************************

*******void write_account(); //function to write record in binary filevoid display_sp(int); //function to display accountdetails given by uservoid modify_account(int); //function to modify recordof file

Page 8: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 8/18

void delete_account(int); //function to delete recordof filevoid display_all(); //function to display all accountdetailsvoid deposit_withdraw(int, int); // function to

desposit/withdraw amount for given accountvoid intro(); //introductory screen function

//***************************************************************// THE MAIN FUNCTION OF PROGRAM//****************************************************************

int main(){

char ch;int num;clrscr();for(int i=0;i<25;i++){

gotoxy(1,1+i);delay(20);cout<<"*";

}for(i=0;i<78;i++)

{

gotoxy(1+i,25);delay(10);cout<<"*";

}for(i=0;i<25;i++){

gotoxy(80,25-i);delay(20);

cout<<"*";}for(i=0;i<79;i++){

gotoxy(80-i,1);delay(10);cout<<"*";

Page 9: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 9/18

  }

intro();do{

clrscr();for(int i=0;i<25;i++){

gotoxy(1,1+i);delay(20);cout<<"*";

}for(i=0;i<78;i++){

gotoxy(1+i,25);delay(10);cout<<"*";

}for(i=0;i<25;i++){

gotoxy(80,25-i);delay(20);cout<<"*";

}for(i=0;i<79;i++)

{

gotoxy(80-i,1);delay(10);cout<<"*";

}

cout<<"\n\n\t|||---MAIN MENU---|||";cout<<"\n\n\t1. NEW ACCOUNT";cout<<"\n\n\t2. DEPOSIT AMOUNT";cout<<"\n\n\t3. WITHDRAW AMOUNT";

cout<<"\n\n\t4. BALANCE ENQUIRY";cout<<"\n\n\t5. ALL ACCOUNT HOLDER LIST";cout<<"\n\n\t6. CLOSE AN ACCOUNT";cout<<"\n\n\t7. MODIFY AN ACCOUNT";cout<<"\n\n\t8. EXIT";cout<<"\n\n\tSelect Your Option (1-8) : ";cin>>ch;clrscr();

Page 10: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 10/18

  switch(ch){case '1':

 write_account(); break;

case '2':cout<<"\n\n\tAccount No. : "; cin>>num;deposit_withdraw(num, 1); break;

case '3':cout<<"\n\n\tAccount No. : "; cin>>num;deposit_withdraw(num, 2); break;

case '4':cout<<"\n\n\tAccount No. : "; cin>>num;display_sp(num); break;

case '5':display_all(); break;

case '6':cout<<"\n\n\tAccount No. : "; cin>>num;delete_account(num); break;

case '7':cout<<"\n\n\tAccount No. : "; cin>>num; modify_account(num); break;

case '8':cout<<"\n\n\tThank You for using Bank

 Managemnt System .";getch(); break;

default :cout<<"\a";}getch();

}while(ch!='8');return 0;

}

//***************************************************************// function to write in file//****************************************************************

Page 11: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 11/18

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();

}

//***************************************************************// function to read specific record from file//****************************************************************

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 opened !! Press anyKey...";

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!";}

//***************************************************************// function to modify record of file

Page 12: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 12/18

//****************************************************************

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 opened !! Press anyKey...";

return;} while(File.read((char *) &ac, sizeof(account)) &&

found==0){

if(ac.retacno()==n){

ac.show_account();cout<<"\n\nEnter New Details : "<<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. ";}

//***************************************************************// function to delete record of file//*********************************************************

*******

void delete_account(int n){

account ac;ifstream inFile;ofstream outFile;

Page 13: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 13/18

  inFile.open("account.dat",ios::binary);if(!inFile){

cout<<"File could not be opened !! Press anyKey...";

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 ..";

}

//***************************************************************// function to display all accounts deposit list//*********************************************************

*******

void display_all(){

account ac;ifstream inFile;inFile.open("account.dat",ios::binary);if(!inFile){

cout<<"File could not be opened !! Press anyKey...";

return;}cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";cout<<"===============================================

=================================\n";cout<<setw(5)<<"A/C

 NO."<<setw(10)<<"NAME"<<setw(20)<<"TYPE"<<setw(25)<<"BALANCE\n";

Page 14: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 14/18

  cout<<"================================================================================\n";

 while(inFile.read((char *) &ac, sizeof(account))){

ac.report();

}inFile.close();}

//***************************************************************// function to deposit and withdraw amounts//****************************************************************

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 opened !! Press anyKey...";

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 amount to be deposited

:";cin>>amt;ac.dep(amt);

}if(option==2){

cout<<"\n\n\tTO WITHDRAW AMOUNT, ";

Page 15: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 15/18

  cout<<"\n\nEnter amount to be withdrawn:";

cin>>amt;int bal=ac.retdeposit()-amt;if((bal<500 && ac.rettype()=='S') ||

(bal<1000 && ac.rettype()=='C'))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 ";}//***************************************************************// INTRODUCTION FUNCTION//****************************************************************void intro(){

cout<<"\n\n\n\t BANK";cout<<"\n\n\tMANAGEMENT";cout<<"\n\n\t SYSTEM";cout<<" \n\n\n\n\t\t\tMADE BY : ABHISHEK

 WADHWA & HARSHIT SWAMI";cout<<" \n\n\t\t\tSCHOOL : ST. GEORGE'S

SCHOOL";getch();

}

//*********************************************************

******// END OF PROJECT//*

Page 16: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 16/18

 

The header files used in the coding are: -

  FSTREAM.H

  STRING.H

  STDLIB.H

  STDIO.H

  CONIO.H

  DOS.H

  CTYPE.H

Page 17: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 17/18

 

Page 18: Computer Science Practical

8/10/2019 Computer Science Practical

http://slidepdf.com/reader/full/computer-science-practical 18/18

 

Introductory Computer Science for - A.K.SHARMA

Computer Science with C++ - Sumita Arora

Programming in C++ - Balaguruswamy

Object Oriented Programming - Robert Lafore

in C++

The Waite Group’s Turbo C++ Bible –  

 Nabajyoti Barkaki

HOWARD W.SAMS & CO.