You are on page 1of 71

C++ Lab

Program Number Program Name Date implemented

: 1 : Implement class and object. : November 19, 2012

This program Loan Management, aimed at accepting the input like bank details, and information about various loans provided by the bank with validation. It also displays all necessary details of a bank to the customers as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class BankDetails { private: int i,n,bcode,lid; char BankName[20],BranchCode[10],BranchName[20],Address[30],Number[10],LoanId[10][10], LoanName[20][20]; public: void getdata(); void putdata(); void loandata(); int display(); }; /*Function to enter all the details of bank*/ void BankDetails :: getdata(void) { LB3: cout<<"\nEnter The Bank Name\n"<<endl; cin>>BankName; if(!isstring(BankName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB3;} cout<<"\nEnter The Bank Address\n"<<endl; cin>>Address; L2: cout<<"\nEnter The Branch Code\n"<<endl; cin>>BranchCode; if(!isint(BranchCode)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto L2;} bcode=atoi(BranchCode); LB2: cout<<"\nEnter The Branch Name\n"<<endl; cin>>BranchName; if(!isstring(BranchName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB2;} } /*Function to display the bank data*/ void BankDetails :: putdata(void) { cout<<"\n\n\n\n\t\t------------\n\t"; cout<<"\tBANK DETAILS\n\t"; cout<<"\t------------\n\n\n\t"; cout<<"\tBank Name : "<<BankName<<"\n\n\t"; cout<<"\tBank Address : "<<Address<<"\n\n\t"; cout<<"\tBranch Code : "<<BranchCode<<"\n\n\t"; cout<<"\tBranch Name : "<<BranchName<<"\n\n\t"; } Department of Computer Science, Christ University

C++ Lab

/*Function to enter all the details of loan*/ void BankDetails :: loandata(void) { L1: cout<<"\nEnter The Total Number Of Loans Provided By The Bank\n"<<endl; cin>>Number; if(!isint(Number)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto L1;} n=atoi(Number); for(i=0;i<n;i++) { L3: cout<<"\nEnter The Loan Id\n"<<endl; cin>>LoanId[i]; if(!isint(LoanId[i])){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto L3;} lid=atoi(LoanId[i]); LB1: cout<<"\nEnter The Loan Name\n"<<endl; cin>>LoanName[i]; if(!isstring(LoanName[i])){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB1;} } /*Function to display the loan data*/ int BankDetails :: display() { cout<<"\n\n\n\n\t---------------------------------"<<endl; cout<<"\n\tLoan Id\t\t\tLoan Name\n"; cout<<"\t---------------------------------"<<endl; for(i=0;i<n;i++) { cout<<"\n\t"; cout<<LoanId[i]; cout<<"\t\t\t"<<LoanName[i]; } return(0); } int main() { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; BankDetails b1; b1.getdata(); b1.loandata(); b1.putdata(); b1.display(); getch(); return(0); }

Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

Department of Computer Science, Christ University

C++ Lab

Program Number Program Name Date implemented

: 2 : Implement constructors and destructors with array of objects. : November 26, 2012

This program aimed at accepting the inputs like bank details, and information about various customers with validation. It also calculate the loan amount, interest and display the details of customers as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include<string.h> #include "validations.h" class BankDetails { private: int bcode; char BankName[20],BranchCode[10],BranchName[20]; public: int i; void getdata(); void putdata(); BankDetails() { cout<<"\nWELCOME TO\n"; cout<<"**********\n"; } BankDetails(char name[20],int code,char branch[20]) { bcode=code; strcpy(BankName,name); strcpy(BranchName,branch); cout<<"\nSouth Indian Bank\n\n"; } ~BankDetails() { cout<<"THANK YOU\n"; cout<<"**********\n"; getch(); } }; class CustomerDetails { private: int CId,ANum; char CustomerName[5],CustomerId[5],AccountNo[5]; public: int i; void get(); Department of Computer Science, Christ University

C++ Lab void put(); }; class Loan { float Irst int Amount; char LoanType[20],Interest[10]; int CId,ANum,DAmount,DTerm,Sal,YWork,InterestAmount,AmountAllowed; char CustomerName[5],CustomerId[5],AccountNo[5],Salary[10],DesiredAmount[10], CampanyName[10],YearOfWorking[5]; public: Loan() { Irst=0.5; DTerm=12; Amount=0; } /*Function to enter all the customer details */ void getdetails() { LL5: cout<<"\nEnter The Campany Name\n"<<endl; cin>>CampanyName; if(!isstring(CampanyName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL5;} LL6: cout<<"\nEnter The Year Of Working\n"<<endl; cin>>YearOfWorking; if(!isint(YearOfWorking)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL6;} YWork=atoi(YearOfWorking); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL1: cout<<"\nEnter The Loan Type\n"; cin>>LoanType; if(!isstring(LoanType)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL1;} LLL2: cout<<"\nEnter The Desired Loan Amount\n"; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function toCalculate,display the loan amount and interest*/ int Calculate() { AmountAllowed=(Sal*DTerm)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((Irst/100)*Amount); cout<<"\nInterest Per Month : "<<InterestAmount; return(0); Department of Computer Science, Christ University

C++ Lab } Loan(Loan &l) { Irst=l.Irst; DTerm=l.DTerm; Amount=l.Amount; cout<<endl<<endl<<l.Calculate(); } }; /*Function to enter all the customer details*/ void CustomerDetails :: get() { LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); } /*Function to display the customer data*/ void CustomerDetails :: put() { cout<<"\n\t"; cout<<CustomerId; cout<<"\t\t"<<CustomerName; cout<<"\t\t\t\t"<<AccountNo; } /*Function to enter all the details of bank*/ void BankDetails :: getdata(void) { LB3: cout<<"\nEnter The Bank Name\n"<<endl; cin>>BankName; if(!isstring(BankName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB3;} L2: cout<<"\nEnter The Branch Code\n"<<endl; cin>>BranchCode; if(!isint(BranchCode)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto L2;} bcode=atoi(BranchCode); LB2: cout<<"\nEnter The Branch Name\n"<<endl; cin>>BranchName; if(!isstring(BranchName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB2;} } /*Function to display the bank data*/ void BankDetails :: putdata(void) { cout<<"\n\n\n\n\t\t------------\n\t"; cout<<"\tBANK DETAILS\n\t"; cout<<"\t------------\n\n\n\t"; Department of Computer Science, Christ University

C++ Lab cout<<"\tBank Name : "<<BankName<<"\n\n\t"; cout<<"\tBranch Code : "<<BranchCode<<"\n\n\t"; cout<<"\tBranch Name : "<<BranchName<<"\n\n\t"; } int main() { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; int i; BankDetails b1; CustomerDetails c[3]; BankDetails b3("SIB",12345,"KARNATAKA"); //BankDetails b2(b3); b1.getdata(); b1.putdata(); for(i=0;i<3;i++) { c[i].get(); } cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\n\n\t----------------------------------------------------"<<endl; cout<<"\n\tCustomerId\tCustomerName\t\tAccountNumber\n"; cout<<"\t----------------------------------------------------"<<endl; for(i=0;i<3;i++) { c[i].put(); } Loan l1; l1.getdetails(); Loan l2(l1); getch(); return(0); }

Department of Computer Science, Christ University

C++ Lab

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

10

Department of Computer Science, Christ University

C++ Lab

11

Program Number

: 3

Department of Computer Science, Christ University

C++ Lab

12

Program Name Date implemented

: Implement Passing and returning parameters by reference. : December 1, 2012

This program aim at accepting the inputs like information about various customers with validation. It also calculates the loan amount, interest for each customers and display the details of customers who have higher loan amount than others as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class Loan { public: int CId,DAmount,Sal,YWork,AmountAllowed,Amount,DTerm,InterestAmount; float Irst; char CustomerName[5],CustomerId[5],Salary[10],DesiredAmount[10],CampanyName[10],YearOfWorking [5]; Loan() { Irst=0.5; DTerm=12; Amount=0; } /*Function to enter all the details of customer*/ void getdetails() { LL2: cout<<"\n\n\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL5: cout<<"\nEnter The Campany Name\n"<<endl; cin>>CampanyName; if(!isstring(CampanyName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL5;} LL6: cout<<"\nEnter The Year Of Working\n"<<endl; cin>>YearOfWorking; if(!isint(YearOfWorking)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL6;} YWork=atoi(YearOfWorking); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); Department of Computer Science, Christ University

C++ Lab LLL2: cout<<"\nEnter The Desired Loan Amount\n\n"; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to display the customer data*/ void putdetails() { cout<<"\n\n\n\n\t\t---------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tId : "<<CId<<"\n\n\t"; cout<<"\tName : "<<CustomerName<<"\n\n\t"; cout<<"\tCampanyName : "<<CampanyName<<"\n\n\t"; cout<<"\tYearOfWorking : "<<YWork<<"\n\n\t"; cout<<"\tSalary : "<<Sal<<"\n\n\t"; cout<<"\tDesiredAmount : "<<DAmount<<"\n\n\t"; getch(); } /*Function to calculate and display the data like loan amount and interest*/ void calculate() { AmountAllowed=(Sal*DTerm)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((Irst/100)*Amount); cout<<"\n\nInterest Per Month : "<<InterestAmount; getch(); } friend Loan &Loandisplay(Loan& ,Loan& ); }; /*Function to calculate the highest loan amount with the interest*/ Loan &Loandisplay(Loan &l1,Loan &l2) { if(l1.Amount==l2.Amount) if(l1.InterestAmount==l2.InterestAmount) cout<<"\n\n\nBoth Loan Amounts Are Equal "; else if(l1.InterestAmount>l2.InterestAmount) cout<<"\n\n\nCustomer : "<<l1.CustomerName<<" Higher Loan Amount Rs : "<<l1.Amount<<" & Interest Amount Rs : "<<l1.InterestAmount; else cout<<"\n\n\nCustomer : "<<l2.CustomerName<<" Higher Loan Amount Rs : "<<l2.Amount<<" & Interest Amount Rs : "<<l2.InterestAmount; else if(l1.Amount>l2.Amount) cout<<"\n\n\nCustomer : "<<l1.CustomerName<<" Higher Loan Amount Rs : "<<l1.Amount<<" & Interest Amount Rs : "<<l1.InterestAmount; Department of Computer Science, Christ University

13

C++ Lab else cout<<"\n\n\nCustomer : "<<l2.CustomerName<<" Higher Loan Amount Rs : "<<l2.Amount<<" & Interest Amount Rs : "<<l2.InterestAmount; getch(); } int main() { Loan l1,l2; l1.getdetails(); l1.putdetails(); l1.calculate(); l2.getdetails(); l2.putdetails(); l2.calculate(); Loan &l3=Loandisplay(l1,l2); return(0); getch(); }

14

OUTPUT:
Department of Computer Science, Christ University

C++ Lab

15

Department of Computer Science, Christ University

C++ Lab

16

Department of Computer Science, Christ University

C++ Lab

17

Program Number Program Name Date implemented

: 4 : Demonstrate Function Overloading. : December 3, 2012

This program aim at accepting the inputs like information about customers with validation. It also calculates the loan amount, interest for the customer and display the details of customer like interest per month as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class Loan { int CId,DAmount,Sal,AmountAllowed,Amount,DTerm,InterestAmount,SSSal,DDAmount,AAAmount,D DDTerm,AAAmountAllowed; float AAmountAllowed,DDTerm,AAmount,DDDAmount,Irst; char CustomerName[5],CustomerId[5],Salary[10],DesiredAmount[10],Interest[10]; public: Loan() { DTerm=12; DDDTerm=12; DDTerm=12.0; Amount=0; AAAmount=0; AAmount=0.0; } /*Function to enter all the details of customer*/ void getdetails() { LL2: cout<<"\n\n\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} } /*Function to display the customer data*/ void putdetails() { cout<<"\n\n\n\n\t\t------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tId : "<<CId<<"\n\n\t"; cout<<"\tName : "<<CustomerName<<"\n\n\t"; } /*Function to calculate and display the loan amount and interest*/ int calculate(int SSSal,int DDAmount) { Department of Computer Science, Christ University

C++ Lab AAAmountAllowed=(SSSal*DDDTerm)/2; if(AAAmountAllowed>DDAmount) { AAAmount=AAAmount+DDAmount; cout<<"\n\nLoan Amount Allowed : "<<AAAmount; } else { AAAmount=AAAmount+AAAmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<AAAmount; } return(AAAmount); getch(); } /*Function to calculate and display the loan amount and interest*/ float calculate(float Irst,int AAAmount) { InterestAmount=(int)((Irst/100)*AAAmount); cout<<"\n\nInterest Per Month : "<<InterestAmount; } }; int main() { int Sal,DAmount,R; float SSal,DDAmount,Rt,Irst; char Salary[10],DesiredAmount[10],SSalary[10],DDesiredAmount[10],Interest[10]; Loan l1; l1.getdetails(); l1.putdetails(); //l1.calculate(); LL1: cout<<"\n\n\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} Sal=atoi(Salary); LLL2: cout<<"\nEnter The Desired Loan Amount\n\n"; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); R=l1.calculate(Sal,DAmount); LL3: cout<<"\n\n\nEnter The Interest Amount\n"<<endl; cin>>Interest; if(!isfloat(Interest)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} Irst=atof(Interest); Rt=l1.calculate(Irst,R); getch(); return(0); }

18

Department of Computer Science, Christ University

C++ Lab

19

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

20

Program Number Program Name Date implemented

: 5 : Demonstrate pointer sort. : December 8, 2012

This program aim at accepting the inputs like information about various customers with validation. It also calculates the loan amount, interest for each customers and display the details of customers in the sorted oder as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include<iomanip> #include<string.h> #include "validations.h" class CustomerDetails { private: float Irst; int CId,ANum,i,n,InterestAmount,DTerm,Amount,Sal,DAmount,AmountAllowed; char CustomerName[5],CustomerId[5],AccountNo[5],Salary[5],DesiredAmount[5]; public: /*Function to enter all the details of customer*/ void getdata() { LL3: cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL2: cout<<"\nEnter The Desired Loan Amount\n"; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to calculate and display the loan amount and interest*/ void put() { Irst=0.5; DTerm=12; Amount=0; AmountAllowed=(Sal*DTerm)/2; if(AmountAllowed>DAmount) Department of Computer Science, Christ University

C++ Lab { Amount=Amount+DAmount; cout<<"\n\t"; cout<<CustomerName; cout<<"\t\t"<<AccountNo; cout<<"\t\t"<<Amount; InterestAmount=(int)((Irst/100)*Amount); cout<<"\t\t"<<InterestAmount; } else { Amount=Amount+AmountAllowed; cout<<"\n\t"; cout<<CustomerName; cout<<"\t\t"<<AccountNo; cout<<"\t\t"<<Amount; InterestAmount=(int)((Irst/100)*Amount); cout<<"\t\t"<<InterestAmount; } } /*Function to return the customer name*/ char *getname() { return CustomerName; } }; int main() { int i,n; char num[5]; void sort(CustomerDetails **, int); CustomerDetails *c[10]; LBL: cout<<"Enter The Number Of Customers"; cin>>num; if(!isint(num)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LBL;} n=atoi(num); for(i=0;i<n;i++) { //cout<<"\nEnter The Customer Id\n"<<endl; cout<<"\nEnter The Customer Name\n"<<endl; c[i]=new CustomerDetails; c[i]->getdata(); } cout<<"\n\nBefore Sort\n"; cout<<"************"; cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\n\n\t--------------------------------------------------------"<<endl; cout<<"\n\tCustomerName\tAccountNumber\tLoanAmount\tInterest\n"; cout<<"\t--------------------------------------------------------"<<endl; for(i=0;i<n;i++) { c[i]->put(); } Department of Computer Science, Christ University

21

C++ Lab sort(c,n); cout<<"\n\nAfter Sort\n"; cout<<"************"; cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\n\n\t--------------------------------------------------------"<<endl; cout<<"\n\tCustomerName\tAccountNumber\tLoanAmount\tInterest\n"; cout<<"\t--------------------------------------------------------"<<endl; for(i=0;i<n;i++) { c[i]->put(); } getch(); return(0); } /*Function to sort the customer name*/ void sort(CustomerDetails **s,int n) { void swap(CustomerDetails **,CustomerDetails **); int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) swap(s+i,s+j); } /*Function to perform swapping*/ void swap(CustomerDetails **s1,CustomerDetails **s2) { if(strcmpi((*s1)->getname(),(*s2)->getname())>0) { CustomerDetails *temp=*s1; *s1=*s2; *s2=temp; } }

22

Department of Computer Science, Christ University

C++ Lab

23

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

24

Department of Computer Science, Christ University

C++ Lab

25

Program Number Program Name Date implemented

: 6 : Perform operator overloading. : December 10, 2012

This program aim at accepting the inputs like information about various customers with validation. It also calculates the loan amount, interest for each customers and display the details of customers as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class CustomerDetails { private: int CId,ANum,Sal; char CustomerName[5],CustomerId[5],AccountNo[5],Salary[5]; public: int i; void get(); void operator()(); void operator[](CustomerDetails ); void operator++(); void operator+(CustomerDetails ); }; /*Function to enter all the details of customer*/ void CustomerDetails :: get() { LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); } /*Function to display the details of customer*/ void CustomerDetails :: operator()() { cout<<"\n\t"; cout<<CustomerName; cout<<"\t\t"<<AccountNo; cout<<"\t\t\t"<<Salary; Department of Computer Science, Christ University

C++ Lab } /*Function to compare the details of customer*/ void CustomerDetails::operator[](CustomerDetails x) { cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"Customer With Higher Salary "<<"\n\n"; cout<<"\n\n\t----------------------------------------------------"<<endl; cout<<"\n\tCustomerName\tAccountNumber\t\tSalary\n"; cout<<"\t----------------------------------------------------"<<endl; if(x.Sal>Sal) { cout<<"\n\t"; cout<<x.CustomerName; cout<<"\t\t"<<x.AccountNo; cout<<"\t\t\t"<<x.Salary; } else if(Sal>x.Sal) { cout<<"\n\t"; cout<<CustomerName; cout<<"\t\t"<<AccountNo; cout<<"\t\t\t"<<Salary; } else { cout<<"\n\n\n\tSame Salary\n\n"; } } /*Function to increment the customer loan*/ void CustomerDetails::operator ++() { int incre=1000; Sal=Sal+++incre; cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"Consider The First Employee "<<"\n\n"; cout<<"\n\n\t----------------------------------------------------"<<endl; cout<<"\n\tCustomerName\tAccountNumber\t\tSalary+Increment\n"; cout<<"\t----------------------------------------------------------"<<endl; cout<<"\n\t"; cout<<CustomerName; cout<<"\t\t"<<AccountNo; cout<<"\t\t\t"<<Sal; } /*Function to add the loan amount with some bonus*/ void CustomerDetails::operator +(CustomerDetails x) { int NewSal; NewSal=x.Sal+Sal; cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"Full Salary Settilmant : "<<NewSal<<"\n\n"; } int main() Department of Computer Science, Christ University

26

C++ Lab { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; int ch; char choise[5]; CustomerDetails c1,c2; c1.get(); c2.get(); do { cout<<"\n\n1. Add\n\n"; cout<<"\n\n2. Compare\n\n"; cout<<"\n\n3. Increment\n\n"; cout<<"\n\n4. Display\n\n"; Label: cout<<"\n\nEnter Your Choise\n\n"; cin>>choise; if(!isint(choise)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto Label;} ch=atoi(choise); switch(ch) { case 1: c1+c2; break; case 2: c1[c2]; break; case 3: ++c1; break; case 4: cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\n\n\t----------------------------------------------------"<<endl; cout<<"\n\tCustomerName\tAccountNumber\t\tSalary\n"; cout<<"\t----------------------------------------------------"<<endl; c1(); c2(); break; default: break; } getch(); }while(ch>0&&ch<4); getch(); return(0); }

27

Department of Computer Science, Christ University

C++ Lab

28

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

29

Department of Computer Science, Christ University

C++ Lab

30

Department of Computer Science, Christ University

C++ Lab

31

Department of Computer Science, Christ University

C++ Lab

32

Program Number Program Name Date implemented

: 7 : Demonstrate friend function and friend class. : December 15, 2012

This program aim at accepting the inputs like information about various customers with validation. It also calculates the loan amount, interest for each customers and display the details of customers who have higher loan amount than others as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class Loan { int CId,DAmount,Sal,YWork,AmountAllowed,Amount,DTerm,InterestAmount; float Irst; char CustomerName[5],CustomerId[5],Salary[10],DesiredAmount[10],CampanyName[10],YearOfWorking [5]; public: Loan() { Irst=0.5; DTerm=12; Amount=0; } /*Function to enter all the details of customer*/ void getdetails() { LL2: cout<<"\n\n\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL5: cout<<"\nEnter The Campany Name\n"<<endl; cin>>CampanyName; if(!isstring(CampanyName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL5;} LL6: cout<<"\nEnter The Year Of Working\n"<<endl; cin>>YearOfWorking; if(!isint(YearOfWorking)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL6;} YWork=atoi(YearOfWorking); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; Department of Computer Science, Christ University

C++ Lab if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL2: cout<<"\nEnter The Desired Loan Amount\n"; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to display all the details of customer*/ void putdetails() { cout<<"\n\n\n\n\t\t------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tId : "<<CId<<"\n\n\t"; cout<<"\tName : "<<CustomerName<<"\n\n\t"; cout<<"\tCampanyName : "<<CampanyName<<"\n\n\t"; cout<<"\tYearOfWorking : "<<YWork<<"\n\n\t"; cout<<"\tSalary : "<<Sal<<"\n\n\t"; cout<<"\tDesiredAmount : "<<DAmount<<"\n\n\t"; getch(); } /*Function to calculate the customer loan amount and interest*/ void calculate() { AmountAllowed=(Sal*DTerm)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((Irst/100)*Amount); cout<<"\n\nInterest Per Month : "<<InterestAmount; getch(); } friend void Loandisplay(Loan ,Loan ); }; /*Function to calculate the highest loan amount with interest*/ void Loandisplay(Loan l1,Loan l2) { cout<<"\n\n\n\nCustomer Name : "<<l1.CustomerName<<"\n"; cout<<"----------------------\n\n"; l1.calculate(); cout<<"\n\n\n\nCustomer Name : "<<l2.CustomerName<<"\n"; cout<<"----------------------\n\n"; l2.calculate(); if(l1.Amount==l2.Amount) if(l1.InterestAmount==l2.InterestAmount) cout<<"\n\n\nBoth Loan Amounts Are Equal "; else if(l1.InterestAmount>l2.InterestAmount) Department of Computer Science, Christ University

33

C++ Lab cout<<"\n\n\nCustomer : "<<l1.CustomerName<<" Higher Loan Amount Rs : <<l1.Amount<<" & Interest Amount Rs : "<<l1.InterestAmount; else cout<<"\n\n\nCustomer : "<<l2.CustomerName<<" Higher Loan Amount Rs : <<l2.Amount<<" & Interest Amount Rs : "<<l2.InterestAmount; else if(l1.Amount>l2.Amount) cout<<"\n\n\nCustomer : "<<l1.CustomerName<<" Higher Loan Amount Rs : <<l1.Amount<<" & Interest Amount Rs : "<<l1.InterestAmount; else cout<<"\n\n\nCustomer : "<<l2.CustomerName<<" Higher Loan Amount Rs : <<l2.Amount<<" & Interest Amount Rs : "<<l2.InterestAmount; getch(); } int main() { Loan l1,l2; l1.getdetails(); l1.putdetails(); l2.getdetails(); l2.putdetails(); Loandisplay(l1,l2); return(0); getch(); } " " " "

34

Department of Computer Science, Christ University

C++ Lab

35

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

36

Department of Computer Science, Christ University

C++ Lab

37

Department of Computer Science, Christ University

C++ Lab

38

Program Number Program Name Date implemented

: 8 : Demonstrate all possible Type Conversions. : December 17, 2012

This program aim at accepting the inputs like information about customer with validation. It also calculates the loan amount, interest for that customer and display the details of customers like total payment as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> class customer2; class customer1 { private: int AccNo,Month; double Amount; float Interest; public: customer1(int num,int mnth,double amt,float irst) { AccNo=num; Month=mnth; Amount=amt; Interest=irst; } /*Function to display all the details of customer*/ void display() { cout<<"\n\nAccount Number : "<<AccNo; cout<<"\n\nNumber Of Month : "<<Month; cout<<"\n\nLoan Amount : "<<Amount; cout<<"\n\nInterest / Month : "<<Interest; } /*Function to return customer number*/ int getAccNo() { return(AccNo); } /*Function to return month*/ int getMonth() { return(Month); } /*Function to return customer loan amount*/ double getAmount() { return(Amount); } Department of Computer Science, Christ University

C++ Lab

39

/*Function to return customer loan interest*/ float getInterest() { return(Interest); } /*Function to calculate total amount*/ operator double() { //double d; return(Amount+(Interest*Month)); // return(d); } }; class customer2 { private: int AccNo; double Total; public: customer2() { AccNo=0; Total=0; } customer2(int num,double tot) { AccNo=num; Total=tot; } /*Function to display all the details of customer*/ void display() { cout<<"\n\nAccount Number : "<<AccNo; cout<<"\n\nTotal Amount : "<<Total; } customer2(customer1 c1) { AccNo=c1.getAccNo(); Total=(c1.getAmount()+(c1.getInterest()*c1.getMonth())); } }; int main() { customer1 c1(1225927,24,20000,11.5); customer2 c2; c1.display(); double total=c1; c2=c1; cout<<"\n\nTotal Amount : "<<total; getch(); return(0); }

Department of Computer Science, Christ University

C++ Lab

40

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

41

Program Number Program Name Date implemented

: 9 : Implement different types of inheritances. : December 22, 2012

This program aim at accepting the inputs like information about a customer with validation. It also calculates the loan amount, interest for a customer and display the details of customer as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include<string.h> #include "validations.h" class BankDetails { public: int bcode; char BankName[20],BranchCode[10],BranchName[20]; int i; void getdata(); void putdata(); }; /*Function to enter all the details of bank*/ void BankDetails :: getdata(void) { LB3: cout<<"\nEnter The Bank Name\n"<<endl; cin>>BankName; if(!isstring(BankName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB3;} L2: cout<<"\nEnter The Branch Code\n"<<endl; cin>>BranchCode; if(!isint(BranchCode)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto L2;} bcode=atoi(BranchCode); LB2: cout<<"\nEnter The Branch Name\n"<<endl; cin>>BranchName; if(!isstring(BranchName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LB2;} } /*Function to display all the details of bank*/ void BankDetails :: putdata(void) { cout<<"\n\n\n\n\t\t------------\n\t"; cout<<"\tBANK DETAILS\n\t"; cout<<"\t------------\n\n\n\t"; cout<<"\tBank Name : "<<BankName<<"\n\n\t"; cout<<"\tBranch Code : "<<BranchCode<<"\n\n\t"; cout<<"\tBranch Name : "<<BranchName<<"\n\n\t"; Department of Computer Science, Christ University

C++ Lab } class CustomerDetails { public: int CId,ANum; char CustomerName[5],CustomerId[5],AccountNo[5]; int i; void get(); void put(); }; /*Function to enter all the details of customer*/ void CustomerDetails :: get() { LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); }

42

/*Function to display all the details of customer*/ void CustomerDetails :: put() { cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tCustomer Id : "<<CId<<"\n\n\t"; cout<<"\tCustomer Name : "<<CustomerName<<"\n\n\t"; cout<<"\tAccount Number : "<<AccountNo<<"\n\n\t"; } class Loan : public CustomerDetails, public BankDetails { public: float Irst; int Amount; char LoanType[20],Interest[10]; int CId,ANum,DAmount,DTerm,Sal,YWork,InterestAmount,AmountAllowed; char CustomerName[5],CustomerId[5],AccountNo[5],Salary[10],DesiredAmount[10],CampanyName[10],Y earOfWorking[5]; Loan() { Irst=0.5; DTerm=12; Amount=0; } /*Function to enter all the details of customer*/ void getdetails() { BankDetails :: getdata(); CustomerDetails :: get(); Department of Computer Science, Christ University

C++ Lab LL5: cout<<"\nEnter The Campany Name\n"<<endl; cin>>CampanyName; if(!isstring(CampanyName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL5;} LL6: cout<<"\nEnter The Year Of Working\n"<<endl; cin>>YearOfWorking; if(!isint(YearOfWorking)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL6;} YWork=atoi(YearOfWorking); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL1: cout<<"\nEnter The Loan Type\n"<<endl; cin>>LoanType; if(!isstring(LoanType)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL1;} LLL2: cout<<"\nEnter The Desired Loan Amount\n"<<endl; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to display all the details of customer*/ void putdetails() { BankDetails :: putdata(); CustomerDetails :: put(); } }; class Calculate : public Loan { public: /*Function to calculate the customer loan amount and interest*/ void Cal() { Loan :: getdetails(); Loan :: putdetails(); AmountAllowed=(Sal*DTerm)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((Irst/100)*Amount); cout<<"\n\nInterest Per Month : "<<InterestAmount; } }; class Display : public Calculate { public: void dis() { Calculate :: Cal(); Department of Computer Science, Christ University

43

C++ Lab } }; int main() { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; Display d; d.dis(); getch(); return(0); }

44

Department of Computer Science, Christ University

C++ Lab

45

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

46

Department of Computer Science, Christ University

C++ Lab

47

Program Number Program Name Date implemented

: 10 : Demonstrate the use of Virtual Functions and Abstract classes : January 1, 2013

This program aim at accepting the inputs like information about various customers with validation. It also calculates the loan amount, interest for each customers and display the details of customers as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream.h> #include<conio.h> #include "validations.h" class Customer { public: int CId,ANum; int Amount; char LoanType[20],Interest[10]; int DAmount,Sal,YWork,InterestAmount,AmountAllowed; char Salary[10],DesiredAmount[10],CampanyName[10],YearOfWorking[5]; int DTerm; float Irst; char CustomerName[5],CustomerId[5],AccountNo[5]; /*Function to display all the basic details */ virtual void Common() { cout<<"\tSouth Indian Bank Next Generation Banking\n\t"<<endl; cout<<"\t-----------------------------------------\n\n\t"<<endl; } virtual void Cal()=0; }; class Customer1: public Customer { public: /*Function to display all the details of customer*/ void Common() { Customer::Common(); cout<<"\tEnter Customer Detailes\n\t"<<endl; cout<<"\t#######################\n\n\t"<<endl; } /*Function to enter all the details of customer*/ void getput() { LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} Department of Computer Science, Christ University

C++ Lab LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL2: cout<<"\nEnter The Desired Loan Amount\n"<<endl; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to calculate the customer loan amount,interest and display it */ void Cal() { cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tCustomer Id : "<<CId<<"\n\n\t"; cout<<"\tCustomer Name : "<<CustomerName<<"\n\n\t"; cout<<"\tAccount Number : "<<AccountNo<<"\n\n\t"; cout<<"\tCustomer Salary : "<<Sal<<"\n\n\t"; cout<<"\tDesire Amount : "<<DAmount<<"\n\n\t"; Amount=0; AmountAllowed=(Sal*12)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((0.5/100)*Amount); cout<<"\n\nInterest Per Month : "<<InterestAmount<<"\n\n\n"; } }; class Customer2 : public Customer { public: /*Function to enter all the details of customer*/ void putget() { LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; Department of Computer Science, Christ University

48

C++ Lab cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); LL4: cout<<"\nEnter The Customer Salary\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Sal=atoi(Salary); LLL2: cout<<"\nEnter The Desired Loan Amount\n"<<endl; cin>>DesiredAmount; if(!isint(DesiredAmount)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LLL2;} DAmount=atoi(DesiredAmount); } /*Function to calculate customer loan,interest and display it*/ void Cal() { cout<<"\n\n\n\n\t\t----------------\n\t"; cout<<"\tCUSTOMER DETAILS\n\t"; cout<<"\t----------------\n\n\n\t"; cout<<"\tCustomer Id : "<<CId<<"\n\n\t"; cout<<"\tCustomer Name : "<<CustomerName<<"\n\n\t"; cout<<"\tAccount Number : "<<AccountNo<<"\n\n\t"; cout<<"\tCustomer Salary : "<<Sal<<"\n\n\t"; cout<<"\tDesire Amount : "<<DAmount<<"\n\n\t"; Amount=0; AmountAllowed=(Sal*12)/2; if(AmountAllowed>DAmount) { Amount=Amount+DAmount; cout<<"\n\nLoan Amount Allowed : "<<Amount; } else { Amount=Amount+AmountAllowed; cout<<"\n\nLoan Amount Allowed : "<<Amount; } InterestAmount=(int)((0.5/100)*Amount); cout<<"\n\nInterest Per Month : "<<InterestAmount<<"\n\n\n"; } }; int main() { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; Customer *c; Customer1 c1; Customer2 c2; c1.Common(); c1.getput(); c=&c1; c->Cal(); c2.putget(); c=&c2; c->Cal(); getch(); return(0); } Department of Computer Science, Christ University

49

C++ Lab

50

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

51

Department of Computer Science, Christ University

C++ Lab

52

Program Number Program Name Date implemented

: 11 : Demonstrate function Templates, and overload the function Templates. : January 28, 2013

This program aim at accepting the inputs like information about a customers with validation. It also calculates the loan amount, interest for a customer and display the details of customer with interest and without interest as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream> #include<conio.h> using namespace std; template<class t1,class t2> /*Function to calculate total amount of a customer*/ float calculation(t1 x,t2 y) { t1 total; total=x+y; return total; } template<class t> /*Function to return the total amount*/ float total(t x) { return x; } template <class T1, class T2> class temp { T1 a; T2 b; public: temp(T1 x, T2 y) { a = x; b = y; } void show(); /*Function to calculate loan amount without interest*/ void cal() { double tot; tot = a; cout<<"\n-------------------------------"; cout<<"\n\nAMOUNT WITHOUT INTEREST Rs. "<<tot; } /*Function to calculate loan amount with interest*/ Department of Computer Science, Christ University

C++ Lab void cal(float t) { double sum; b=12*t; sum = a+b; cout<<"\n-------------------------------"; cout<<"\n\nAMOUNT WITH INTEREST Rs. "<<sum; cout<<"\n-------------------------------"; } }; /*Function to display the customer details*/ template <class T1, class T2> void temp<T1, T2> :: show() { cout<<"\n\n Customer ID : "<<a; cout<<"\n\n Customer Name : "<<b; }

53

int main() { double p; char ch; int choice; double d; cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@ *@*@*@*@*@*@*@*@*@*@*@*@*@"; printf("\n\n L O A N M A N A G E M E N T \n\n"); cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@ *@*@*@*@*@*@*@*@*@*@*@*@*@"; cout<<endl<<endl<<endl; cout<<"\n\n1. Interest\n\n2. No Interest\n\n"; cout<<"\n\nEnter your choice : "; cin>>choice; int id; char name[10]; float q; double p1; char ch1; switch(choice) { case 1: cout<<"\nEnter the Customer Id : "; cin>>id; cout<<"\nEnter the Customer Name : "; cin>>name; cout<<"\nEnter Loan Amount:Rs."; cin>>p; break; case 2: cout<<"\nEnter the Customer Id : "; cin>>id; cout<<"\nEnter the Customer Name : "; cin>>name; temp <int ,char*> t(id,name); cout<<"\nEnter The Loan Amount : "; cin>>q; cout<<"\nEnter The Interest : "; cin>>p1; temp<float ,double> v(q,p1); cout<<"\n\n\nTotal Payment\n\n "; t.show(); v.cal(); Department of Computer Science, Christ University

C++ Lab v.cal(5.0); break; } getch(); return 0; }

54

Department of Computer Science, Christ University

C++ Lab

55

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

56

Department of Computer Science, Christ University

C++ Lab

57

Program Number Program Name Date implemented

: 12 : Demonstrate generic stack class and member functions to perform stack operations. : February 4, 2013

This program aim at accepting the inputs like information about a customer with validation. It display the details of ca ustomer and perform loan apply and cancel process as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream> #include<conio.h> #define max 10 using namespace std; template<class ams> class loan { ams a[20]; int top; public: loan() { top=-1; } /*Function to push the items to the stack*/ void push(ams g) { if((top+1)>= max) { cout<<"over flow"; } else { top++; a[top]=g; } } /*Function to pop the items to the stack*/ ams pop() { ams p; if(top==-1) { cout<<"no flow of stock"; return(-1); } else { p=a[top]; top--; cout<<endl; cout<<"\nLoan Cancelled \n"<<p; cout<<endl; return p; } Department of Computer Science, Christ University

C++ Lab } }; int main() { loan <int> i; loan<int> q; loan <float> p; int id,ch,qu; float pr; do { cout<<"\n\t\t------------------\n"; cout<<"\n\t\t Loan Management "; cout<<"\n\t\t------------------\n"; cout<<"\n\n\t\t 1.Loan Apply\n\n\t\t 2.Loan Cancele\n\n\t\t 3.Exit\n\n"; cout<<"\n\nEnter your choice:="; cin>>ch; switch(ch) { case 1: cout<<"\nEnter Customer Id =:"; cin>>id; cout<<"\nEnter The Loan Amount=:"; cin>>qu; cout<<"\nEnter The Duration =:"; cin>>pr; i.push(id); q.push(qu); p.push(pr); getch(); break; case 2: int h=i.pop( ); int j=q.pop( ); float k =p.pop( ); if(h!=-1) { cout<<"\n\n\n\t\t Details Removed \n\t\t_________________\n"; cout<<"\n\nid="<<h<<"\t Amount="<<j<<"\t Duration="<<k; } getch(); break; } }while(ch!=3); getch(); return(0); }

58

Department of Computer Science, Christ University

C++ Lab

59

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

60

Department of Computer Science, Christ University

C++ Lab

61

Program Number Program Name Date implemented

: 13 : Demonstrate I/O streams and functions. : February 11, 2013

This program aim at accepting the inputs like information about various customers with validation. It also calculates the total loan amount, and display the details of customers with username and password as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iomanip.h> #include<iostream.h> #include<stdlib.h> #include <conio.h> #include "validations.h" using namespace std; class Customer { int CId,ANum,Sal; char CustomerName[5],CustomerId[5],AccountNo[5],Salary[5],Sa[10]; int id; char name[10]; float Amount,Interest,Amount1; public: /*Function to enter the details of the customer*/ void getdata() { cout.width(25); cout<<"ENTER EMPLOYEE DETAILS "<<endl; cout.setf(ios::left,ios::adjustfield); cout.fill('*'); cout.width(30); cout<<"\n"; LL2: cout<<"\n\n\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); LL4: cout<<"\nEnter The Customer Loan Amount\n"<<endl; cin>>Salary; if(!isint(Salary)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL4;} Amount=atoi(Salary); LL5: cout<<"\nEnter The Interest On Loan Amount\n"<<endl; Department of Computer Science, Christ University

C++ Lab cin>>Sa; if(!isint(Sa)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL5;} Interest=atoi(Sa); Amount1=Amount+Interest; cout<<"\n\n\n"; } /*Function to display the details of the customer*/ void putdata() { cout.width(25); cout<<"\n EMPLOYEE DETAILS ARE "<<endl; cout.setf(ios::left,ios::adjustfield); cout.fill('_'); cout.width(30); cout<<"\n"; cout<<"\n\n\nUser ID : " << CId << endl; cout.setf ( ios::hex, ios::basefield ); cout<< "\nPassword : " << CId << endl; cout.setf ( ios::dec, ios::basefield ); cout<<"\n\nAccount Number : "<< ANum << endl; cout<<"\nCustomer Name : " << CustomerName<<endl; cout<<"\nTotal Amount : "<< Amount1 << endl; } }; int main() { cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\n\t"<<endl; Customer c; c.getdata(); c.putdata(); getch(); return(0); }

62

Department of Computer Science, Christ University

C++ Lab

63

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

64

Program Number Program Name Date implemented

: 14 : Demonstrate Overloading << and >> operators as a member and as a non-member operator functions. : February 18, 2013

This program aim at accepting the inputs like information about a customer with validation. It also calculates the loan amount, interest of the customer and display the total payment as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream> #include<conio.h> #include<stdlib.h> #include<stdio.h> #include<ctype.h> #include "validations.h" using namespace std; class loan { public: float amount,interest; loan operator+(loan y); friend ostream & operator<<(ostream &out,loan x); friend istream & operator>>(istream &in,loan &x); }; /*Function to calculate the loan amount and interest of the customer*/ loan loan::operator+(loan y) { loan t; t.amount=amount+y.amount; t.interest=interest+y.interest; return t; } /*Function to input the loan amount and interest of the customer*/ istream & operator>>(istream &in,loan &x) { in>>x.amount>>x.interest; return in; } /*Function to display the loan amount and interest of the customer*/ ostream & operator << (ostream &out,loan x) { out<<" \n\nLoan Amount : "<<x.amount<<" Interest : "<<x.interest<<"\n"; return out; } int main() { // public: int CId,ANum; int Amount; Department of Computer Science, Christ University

C++ Lab char LoanType[20],Interest[10]; int DAmount,Sal,YWork,InterestAmount,AmountAllowed; char Salary[10],DesiredAmount[10],CampanyName[10],YearOfWorking[5]; int DTerm; float Irst; char CustomerName[5],CustomerId[5],AccountNo[5]; cout<<"\n\n\t"; cout<<"***************\n\t"<<endl; cout<<"\tLOAN MANAGEMENT\n\t"<<endl; cout<<"\t***************\n\n\t"<<endl; LL2: cout<<"\nEnter The Customer Id\n"<<endl; cin>>CustomerId; if(!isint(CustomerId)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL2;} CId=atoi(CustomerId); LL3: cout<<"\nEnter The Customer Name\n"<<endl; cin>>CustomerName; if(!isstring(CustomerName)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL3;} LL1: cout<<"\nEnter The Account Number\n"<<endl; cin>>AccountNo; if(!isint(AccountNo)){ printf("\nERROR IN INPUT :TRY AGAIN\n"); goto LL1;} ANum=atoi(AccountNo); loan l1,l2,l3; cout<<"\n\nEnter The First Loan Amount And \n"; cout<<"\n\nEnter The Corresponding Interest Amount\n"; cin>>l1; cout<<"\n\nEnter The Second Loan Amount And \n"; cout<<"\n\nEnter The Corresponding Interest Amount \n"; cin>>l2; l3=l1+l2; cout<<""; cout<<l1; cout<<""; cout<<l2; cout<<"\n\n\n TOTAL PAYMENT \n"; cout<<"********************\n"; cout<<l3; getch(); return(0); }

65

Department of Computer Science, Christ University

C++ Lab

66

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

67

Program Number Program Name Date implemented

: 15 : Demonstrate the file operations. : February 25, 2012

This program aim at accepting the inputs like information about a customer with validation. It also calculates the loan amount, interest for a customer and display the details of customer as the result.
/*************************************************************** * Author: Mintu Movi ***************************************************************/ #include<iostream> #include <fstream> #include<conio.h> using namespace std; class customer{ public: int cid; char cname[20]; int amount; int interest; /*Function to enter the details of the customer */ void getdata(){ cout<<"\n\nEnter the Customer id :"; cin>>cid; cout<<"\n\nEnter the Customer name :"; cin>>cname; cout<<"\n\nEnter the Loan Amount:"; cin>>amount; cout<<"\n\nEnter the interest:"; cin>>interest; } /*Function to display the details of the customer */ void putdata(){ cout<<"\nCustomer Id cout<<"\nCustomer Name cout<<"\nLoan Amount cout<<"\nInterest } };

:"<<cid; :"<<cname; :"<<amount; :"<<interest;

int main() { cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@ *@*@*@*@*@*@*@*@*@*@*@*@*@"; printf("\n\n L O A N M A N A G E M E N T \n\n"); cout<<"@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@ *@*@*@*@*@*@*@*@*@*@*@*@*@"; ofstream outfile; outfile.open("loan.dat", ios::app); cout << "\n\nWriting to the file..." << endl; customer c; c.getdata(); outfile<<c.cid<<"\t"<<c.cname<<"\t"<<c.amount<<"\t"<<c.interest<<"\n"; Department of Computer Science, Christ University

C++ Lab outfile.close(); ifstream infile; infile.open("loan.dat"); cout << "\n\nReading from the file...\n\n\n" << endl; cout<<"CustID\tName\tAmount\tInterest"<<endl; cout<<"********************************\n"; char str[100]; while(infile){ infile.getline(str,100); cout <<str<< endl; } infile.close(); getch(); return 0; }

68

Department of Computer Science, Christ University

C++ Lab

69

OUTPUT:

Department of Computer Science, Christ University

C++ Lab

70

Department of Computer Science, Christ University

C++ Lab

71

Department of Computer Science, Christ University

You might also like