0% found this document useful (0 votes)
74 views7 pages

C++ Programs: Complex Numbers & Banking

1. The document contains 3 C++ programs. The first program adds two complex numbers by defining a complex class with operator overloading. The second program creates a bank account class with methods to create an account, deposit/withdraw amounts, and check the balance. The third program calculates the Fibonacci series using a fibonacci class with a constructor and methods to calculate, display the next number.

Uploaded by

Neeraj Parihar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views7 pages

C++ Programs: Complex Numbers & Banking

1. The document contains 3 C++ programs. The first program adds two complex numbers by defining a complex class with operator overloading. The second program creates a bank account class with methods to create an account, deposit/withdraw amounts, and check the balance. The third program calculates the Fibonacci series using a fibonacci class with a constructor and methods to calculate, display the next number.

Uploaded by

Neeraj Parihar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Program to add two complex nos


#include<iostream.h> #include<conio.h> class complex { floatreal,img; public: voidgetdata() { cout<<"\nEnter the real number->"; cin>>real; cout<<"\nEnter the imaginary number->"; cin>>img; } voidshow_add_data() { cout<<"\nThe addition of complex numbers is->"<<real<<"+"<<img<<"i\n"; } complex operator+(complex c) { complex t; t.real=real+c.real; t.img=img+c.img; return t; }

complex() { cout<<"Constucting\n"; } ~complex() { cout<<"Destructing\n"; } }; main() { complex c1,c2,c3,c4; c1.getdata(); c2.getdata(); c3=c1+c2; c3.show_add_data(); getch(); }

2. Bank Account Program


#include<iostream.h> #include<conio.h> class bank { private: intl,t,d,i,w; char name[10],address[50],category[5]; int age; charpanno[20]; intphoneno; public: voidaccountcreated(); voidamountdeposited(); voidamountwithdrawal(); voidbalancecheck(); }; void bank::accountcreated() { cout<<"enter your name,address,category,age,phoneno,panno"; cin>>name>>address>>category>>age>>phoneno>>panno; cout<<"your name is:"<<name<<"\n"; cout<<"address is:"<<address<<"\n"; cout<<"category is:"<<category<<"\n"; cout<<"your age is:"<<age<<"\n";

cout<<"your phoneno is:"<<phoneno<<"\n"; cout<<"your panno is:"<<panno; cout<<"account is created"; } void bank::amountdeposited() { cout<<"enter amount to be deposited"; cin>>d; i=t+d; cout<<"your new account balance is:"<<i; } void bank::amountwithdrawal() { cout<<"enter amount to be withdrawal:"; cin>>w; l=t-w; cout<<"your balance after withdrawal is:"<<l; } void bank::balancecheck() { cout<<"your account balance is:"<<t; } main() { int x;

bank b; cout<<"***/account creation***"<<"\n"; cout<<"***/amount deposited***"<<"\n"; cout<<"***/amount withdrawal***"<<"\n"; cout<<"***/balance check***"<<"\n"; cin>>x; switch(x) { case 1: b.accountcreated(); break; case 2: b.amountdeposited(); break; case 3: b.amountwithdrawal(); break; case 4: b.balancecheck(); default: cout<<"wrong input"; } getch(); }

3.Program to calculate Fibonacci series using constructor


#include<iostream.h> #include<conio.h> classfibonacci { int f0,f1,f2; public: fibonacci() { f0=0; f1=1; f2=f0+f1; }

voidcal() { f0=f1; f1=f2; f2=f0+f1; } void dis() { cout<<"fibonacci:"<<f2<<endl; }

}; main() { fibonacci f; int n; cout<<"How many no. displayed:"<<endl; cin>>n; for(int i=0;i<=n-1;i++) {

f.dis(); f.cal(); }

getch(); }

You might also like