136
 UNIVERSI T Y OF MUMBAI INS T I T UT E OF DIS T ANCE AND OPEN LEARNING (IDOL)* *(I ns titut e of Di s ta nc e Educa tion (I DE) is rena m ed ) CERTIFICATE  T HE EXPERI MENT S DULY S I GNED IN THI S JO URNAL REPR ES ENT  T HE BONAFIDE WORK BY MISS ____________ ROLL NO. IN SEMESTER III OF SECOND YEAR OF MASTER IN COMPUTER APPLICATION (MCA)  IN THE COMPUTER LABORATORY OF PCP CENTER SHREE RAM COLLAGE, BHANDUP  FOR SUBJECT _______________________ DURING ACADEMI C Y EAR 20 14 -2 0 15 .  _______ _ ___________ LECT URE IN CHARGE HEAD, DEPAR T EMENT OF MCA  ________ EXTERNAL EXAMINER

Mumbai Univeristy MCA IDOL Shree Ram College

  • Upload
    unknown

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 1/136

 

UNIVERSITY OF MUMBAI

INSTITUTE OF DISTANCE AND OPEN LEARNING (IDOL)*

*(Institute of Distance Education (IDE) is renamed)

CERTIFICATE

 THE EXPERIMENTS DULY SIGNED IN THIS JOURNAL REPRESENT THE BONAFIDE WORK BY MISS ______________________________ROLL NO. IN SEMESTER III  OF SECOND YEAR OF MASTER INCOMPUTER APPLICATION (MCA) IN THE COMPUTER LABORATORYOF PCP CENTER SHREE RAM COLLAGE, BHANDUP  FOR SUBJECT

_______________________ DURING ACADEMIC YEAR 2014 -2015 .

 ____________________ ____________________________

LECTURE IN CHARGE HEAD, DEPARTEMENT OF MCA

 ______________________

EXTERNAL EXAMINER

Page 2: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 2/136

 

INDEX 

Database Management System

SR.NO CONTENT SIGNATURE

1. Creation of banking enterprise database.

2. Creation of employee table.

3. Creation of department table.

4. Types of cursor.

5. Creation of function.

6. Creation of stored procedure.

7. Creation of package.

8. Creation of trigger.

9. Write a block that accept names and displayits 5 times in output screen.

10. Write a PL/Sql block that accepts principal,duration (in months) and rate of interest andcalculate maturity amount.

11. Write a block that accepts radius andcalculate area of circle use PI as constant.

12. Write a block that accepts number anddisplay whether is less than or equal orgreater than 10.

Page 3: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 3/136

Practical No.1

Aim: Creation of banking enterprise database.

create table branch(br_name varchar(15) primary key, br_city varchar(10),asset int) ;

create table account(acc_no varchar(10) primary key, br_name varchar(15), balance int,foreign key(br_name) references branch) ;

create table depositor(cust_name varchar(15),acc_no varchar(10) foreign key references account,foreign key(cust_name) references customer) ;

create table customer(cust_name varchar(15) primary key,cust_street varchar(20),cust_city char(10)) ;

create table borrower(cust_name varchar(15) foreign key references customer,loan_no varchar(15) foreign key references loan) ;

create table loan(loan_no varchar(15) primary key, br_name varchar(15) foreign key references branch,amount int) ;

insert into customer values('Adams','Spring','Pittsfield')insert into customer values('Brooks','Senator','Brooklyn')insert into customer values('Curry','North','Rey')insert into customer values('Glenn','Sand Hill','Woodside')insert into customer values('Glenn','Walnut','Stamford')insert into customer values('Hayes','Main','Harrison')insert into customer values('Johnson','Alma','Palo Alto')

Page 4: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 4/136

insert into customer values('Jones','Main','Harrison')insert into customer values('Lindsay','Park','Pittsfield')insert into customer values('Smith','North','Rey')insert into customer values('Turner','Putnam','Stamford')insert into customer values('Williams','Nassau','Princeton')

insert into depositor values('Hayes','A-102')insert into depositor values('Johnson','A-101')insert into depositor values('Johnson','A-201')insert into depositor values('Jones','A-217')insert into depositor values('Lindsay','A-222')insert into depositor values('Smith','A-215')insert into depositor values('Turner','A-305')select * from depositor

insert into branch values('Brighton','Brooklyn',7100000)insert into branch values('Downtown','Brooklyn',9000000)insert into branch values('Mianus','Horseneck',400000)insert into branch values('North Town','Rye',3700000)insert into branch values('Perryridge','Horseneck',17000000)insert into branch values('Pownal','Bennington',300000)insert into branch values('Redwood','Palo Alto',2100000)insert into branch values('Round Hill','Horseneck',8000000)select * from branch

insert into account values('A-101','Downtown',500)insert into account values('A-102','Perryridge',400)insert into account values('A-201','Brighton',900)insert into account values('A-215','Mianus',700)insert into account values('A-217','Brighton',750)

insert into account values('A-222','Redwood',700)insert into account values('A-305','Round Hill',350)select * from account

insert into loan values('L-11','Round Hill',900)insert into loan values('L-14','Downtown',1500)insert into loan values('L-15','Perryridge',1500)insert into loan values('L-16','Perryridge',1300)insert into loan values('L-17','Downtown',1000)insert into loan values('L-23','Redwood',2000)

Page 5: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 5/136

insert into loan values('L-93','Mianus',500)select * from loan

insert into borrower values('Adams','L-16')insert into borrower values('Curry','L-93')

insert into borrower values('Hayes','L-15')insert into borrower values('Johnson','L-14')insert into borrower values('Jones','L-17')insert into borrower values('Smith','L-11')insert into borrower values('Smith','L-23');insert into borrower values('Williams','L-17');select * from borrower;

1)Find the names of all branches in the loan relation.

SQL> select distinct br_name

2 from loan;

2)Find all loan numbers for loans made at the perryridge branch with loan amount greater

than 1200.

SQL> select l_no2 from loan3 where br_name='perryridge' and amt>1200;

3)Find the loan number with loan amounts between 90000 and 100000.

SQL> select l_no2 from loan3 where amt between 90000 and 100000;

4)Find all customers who have a loan from the bank, Find their names,loan numbers and

loan amount.

SQL> select c_name,b.l_no,l.amt2 from borrower b,loan l

3 where b.l_no=l.l_no;williams l-17 1000

5)Find the customer names,loan numbers and loan amounts for all loans at th perryridge

branch.

SQL> select c_name,b.l_no,amt2 from borrower b,loan l3 where b.l_no=l.l_no and br_name='perryridge';

6)Find the names of all branches that have assets greater than at least one branch located

in Brooklyn.

Page 6: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 6/136

SQL> select distinct t.br_name2 from branch t,branch s3 where t.assets>s.assets and s.br_city='brooklyn';

7)Find the names of all customers whose street address includes the substring ‘main’.

SQL> select c_name2 from customer3 where c_street like '%main%';

8)Find in alphabetic order all customers who have a loan at the Perryridge branch.

SQL> select distinct c_name2 from borrower b,loan l3 where b.l_no=l.l_no and4 br_name='perryridge'5 Order by c_name;

9)Find all customers having a loan ,an account or both at the bank.

SQL> select c_name2 from depositor3 union4 select c_name5 from borrower;

10)Find all customers who have both a loan and an account at the bank.

SQL> select c_name2 from depositor3 intersect4 select c_name5 from borrower;

11)Find the average account balance at each branch.

SQL> select br_name,avg(bal)2 from account3 group by br_name;

12)Find the number of depositors for each branch.

SQL> select br_name,count(distinct c_name)2 from depositor d,account a3 where d.acc_no=a.acc_no4 group by br_name;

13)Find the branch name whose average balance is greater than 1200.

Page 7: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 7/136

SQL> select br_name,avg(bal)2 from account3 group by br_name4 having avg(bal)>1200;

14)Find the average balance for each customer who lives in Harrison and has at least threeaccounts.

SQL> select d.c_name,avg(bal)2 from depositor d,account a,customer c3 where d.acc_no=a.acc_no and d.c_name=c.c_name and4 c_city='harrison'5 group by d.c_name6 having count(distinct d.acc_no)>=3;

15)Find the loan numbers in the loan relation with null values for amount.

SQL> select l_no2 from loan3 where amt is null;

16)Find those customers who are borrowers from bank.

SQL> select distinct c_name2 from borrower3 where c_name in(select c_name from depositor);

17)Find all customers who have both an account and a loan at the perryridge branch.

SQL> select distinct c_name2 from borrower b,loan l3 where b.l_no=l.l_no and br_name='perryridge' and4 (br_name,c_name)in5 (select br_name,c_name

6 from depositor d,account a7 where d.acc_no=a.acc_no);

18)Find all customers who do have a loan at the bank,but do not have an account at the

bank.

SQL> select distinct c_name2 from borrower3 where c_name not in(select c_name from depositor);

19)Find the names of all branches that have assets greater than those of at least one branch

located in Brooklyn.

Page 8: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 8/136

SQL> select br_name2 from branch3 where assets>some(select assets from branch4 where br_city='brooklyn');

20)Find those customers who are borrowers from bank.SQL> select distinct c_name

2 from borrower3 where c_name in(select c_name from depositor); 

21)Find an delete branch name where it is perryridge.

SQL-> Delete from account where br_name=’ perryridge’

22) Delete all loans with loan amounts between 1300 and 1500 SQL-> delete from loan where amount  between 1300 and 1500

23) Delete ball account tuples at every branch located in Needham

SQL-> Delete from accountwhere br_namein(select br_name from branch where br_city=’needham’)

Page 9: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 9/136

Practical No.2

Aim: Creation of employee table.

create table Employee (Empno number(4),Ename varchar(20),desig varchar(8),cader number(4),Doj date,Salary nuber(7,3),comm number(7,3),deptno number(2));

1. Make EmpNo as primary key.

Alter table Employee add constraint pk2 primary key (empno);

2. Select all employees who are under the manager designation or have salary

Greater than 10000.

Select Empno,Ename,design,salary from Employee where design ="Manager" or salary>10000

3. List all employee whose name begin with "v"

Select * from employee where ename like "v%"

4. Display all employee with their salary listed in descending order.

Select * from employee order by salary Desc

5. Give a query to increase the salary of the manager to 10%

Update employee set salary =1.1 *salary where design="Manager"

6. Find the highest & lowest salaries & the difference between them.Select Max(salary),Min(salary),max(salary)-min(salary)from employee.

7.Find the total salary & total commissions of managers.

Select sum (salary), sum(comm)from Employee where design="Manager"

Page 10: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 10/136

Page 11: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 11/136

Practical No.3

Aim: Creation of department table.

Create table Depat(DepatNO number(2),Dname varchar(20),Location varchar(15));

1.Make DeptNo as primary key.

Alter table Dpat add constraint pk2 primary key (deptno);

2.Give the command to view the details of tables Depat.

Desc Depat.

3.Increase the column width by 1 from deptno in depat table.

Alter table depat modify deptno mumber(3);

4. Insert records in Depat table.

Insert into Depat values(301,’Web’,’Chennai’);

Insert into Depat values(302,”Hr”,”Bombay”);

Insert into Depat values(303,”Sales”,’Chennai’);

5. Select all records from Depat tables

Select * from Depat.

Page 12: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 12/136

Page 13: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 13/136

 Explicit Cursor:

The bank manager has decided to mark all those accounts as inactive (I) on which there are no

transactions performed in the last 365 days. Whenever any such update takes place, a record for

the same is maintained in the INACTIVE_MSTR table which contains the account number, the

opening date and the type of account. Write a PL/SQL block to implement this.

We first create the INACTIVE_MSTR table as follows:

CREATE TABLE INACTIVE_MSTR(ACCTNO VARCHAR2(10),OPENDT DATE,TYPE VARCHAR2(2)); Now we write the PL/SQL code block:DECLARECURSOR Crsr NoTrans ISSELECT ACCTNO, STATUS, OPENDT, TYPE FROM ACCT_MSTR WHERE ACCTNO IN(SELECT ACCTNO FROM TRANS_MSTRGROUP BY ACCTNO HAVING MAX(SYSDATE — OPENDT) > 365;/* declare memory variables to hold data fetched from the cursor a/str_ACCTNO ACCTMSTR.ACCTNO%TYPE; str_STATUS ACCTMSTR.STATUS%TYPE;dt_OPENDT ACCTMSTR.OPENDT%TYPE; strTYPE ACCTMSTR.TYPE%TYPE;BEGINOPEN CrsrNoTrans;/* if the cursor is open, continue with the data processing else display an appropriate errormessage */IF Crsr NoTrans%ISOPEN THEN

100PFETCH Crsr_NoTrans INTO str_ACCTNO, str_STATUS, dt_OPENDT, str_TYPE;EXIT WHEN CrsrNoTrans%NOTFOUND;IF Crsr NoTrans%FOUND THEN/*update status to 'I' and insert each record into the INACTIVE_MSTR table a/UPDATE ACCTMSTR SET STATUS = 'I' WHERE ACCTNO = str ACCTNO;INERT INTO INACTIVE_MSTR VALUE (str_ACCTNO, dt_opendt, str TYPE);END IF;END LOOP;/*make the changes permanent!COMMIT

ELSEDbms_outputput_line ('Error: Unable to open cursor');END IF;CLOSE Crsr_NoTrans;END;In the above example, the %TYPE means that the data type of these variables will be as that fromthe table.Since the query may return more than one row, a loop is created which does the following:

Page 14: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 14/136

Page 15: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 15/136

BEGIN/* we use the cursor FOR loop */FOR NoTransRec IN Crsr NoTrans/* update the inactive status and insert each record into the INACTIVE_MSTR table */ UPDATEACCT_MSTR SET STATUS = 'I'WHERE ACCTNO= NoTransRec.ACCTNO;INSERT INTO INACTIVE_MSTRVALUES(NoTransRec.ACCTNO, NoTransRec.OPENDATE, NoTransRec.ACCTYPE); ENDLOOP;COMMIT;END;

Write a PL/SQL code block that will merge the data available in the newly created table

NEW_BRANCHES with the data available in the table BRANCH MASTER. If the data in the first

table already exists in the second table, then that data should be skipped.

CREATE TABLE NEW_BRANCHES( BRANCHNO VARCHAR2(1 0), NAMEVARCHAR2(30));INSERT INTO NEW_BRANCHES (BRANCHNO, NAME) VALUES (`B4', `MAHIM');INSERT INTO NEW_BRANCHES (BRANCHNO, NAME) VALUES (`BS', `MATUNGA');INSERT INTO NEW_BRANCHES (BRANCHNO, NAME) VALUES (`BC, `DADAR');INSERT INTO NEW_BRANCHES (BRANCHNO, NAME) VALUES (`BT, `KHAR'); Now WE WRITE THE PL/SQL CODE BLOCK:DECLARE/* This cursor retrieves all records of NEW_BRANCHES table 5/CURSOR Crsr_Newbranches (str_BRANCHNAME VARCHAR2) IS SELECT * FROM NEW_BRANCHES;/* this cursor accepts the value of NAME from the current row of the cursor Crsr Nevvbranches

*/ CURSOR Crsr_Branchchk (str_BRANCHNAME varchar2) ISSELECT BRANCHNO FROM BRANCHMSTRWHERE NAME = strBRANCHNAME;/* we create variables that hold the data from the cursor Crsr Newbranches */str BRANCHNO BRANCH_MSTRBRANCHNO.%TYPE;str BRANCHNNAME BRANCH_MSTR.NAME.%TYPE;/* we create a variable that holds data from the cursor Crsr_Branchchk */ temp VARCHAR2(10);BEGIN/* open the Crsr_Newbranches cursor */ OPEN CrsrNewbranches;LOOP/* fetch the records from the Crsr_Newbranches cursor */

FETCH Crsr_Newbranches INTO str_BRANCHNO, str BRANCHNAME; EXIT WHEN Crsr Newbranches%NOTFOUND;/* open the Crsr_Branchchk cursor. Note that the value of variable passed to the CrsrBranchchkcursor is set to the value of NAME in the current row of the cursor Crsr Newbranches */OPEN Crsr_Branchchk(str_BRANCHNAME); FETCH CrsrBranchchk INTO temp;IF Crsr BRANCHCHK%FOUND THENdbms_output.put_line (`Branch ' II str_BRANCHNAME II `exists');ELSE

Page 16: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 16/136

dbms_output.put_line (`Branch II str_BRANCHNAME II 'does not exist. Insertingnew branch in database');INSERT INTO BRANCH_MSTR VALUES (str_BRANCHNO,str_BRANCHNAME);END IF;CLOSE Crsr_BRANCHCHK;END LOOP;CLOSE Crsr_Newbranches;COMMIT;END;

Page 17: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 17/136

Practical No.5

Aim: Creation of function.

Consider the tables TRANS_MSTR and ACCT_MSTR. Bothe the tables belong to the bankingsystem. The TRANS_MSTR table issued to register the deposit or withdrawal performed .As a batch process the initial opening balance value must be written to the TRANS_MSTR tablewherever an account is opened with the bank. Write a pl/sql block of code that would insert arecords representing the opening balance with the bank. in the TRANS_MSTR tables depend onACCT_NO is not present in the TRANS_MSTR table.i.e there is no entry made for the initialdeposit then a record is inserted in TRANS_MSTR table representing the initial deposit ,then arerecord is inserted in the TRANS_MSTR table representing the initial payment made whileopening an account .The function will search fro a matching value. in the TRANS_MSTR tablewhen a value is passed it to when begin invoked.

The function will return 1 indication that a match is found or 0 indication that no match is foundthe value returned by the function is used to make a decision to insert a ;record or skip theinsertion in the TRANS_MSTR table.

create function for use

A store function is created to perform the function the ACCT_NO check .CChkAcctNO is the name of thefunction which accepts a variable ACCT_NO and return a value to the host environment the valuechanges from(i.e if Acct_NO does not exist) to 1(i.e if Acct_No exists) depending on the recordingreceived

Create or replace function F_CheckACCTNO(VACCT_NO IN VARCHA2)RETURN NUMBER ISDUMMY ACCINO VARCHAR2( 10);BEGINSELECT DISTINCT ACCT. NO INTO DUNIMYACCINWHERE ACCT_NOaVACCI_NO:RETURN 1;EXCEPTIONWHEN NO_DATA_FOUND THENEND:

Output:Function created

Page 18: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 18/136

Calling the Function F_CHKACCTNO in A PL/SQL Code Block

DECLARECURSOR SCANTABLE IS SELECT ACCT_NO,TYPE FROM ACCT_MSTR;MACCT_NO ACCT_MSTR TPE%TYPE; 

VALEXIST NUMBER( I );BEGINOPEN SCANTABLE;LOOPFETCH SCANTABLE INTO MACCT NO,MTYPE;EXIT WHEN SCANTABLE%NOTFOUND;VALEXISTS: =F CIIKACCTNONACCT NO);IF VALEXISTS=0) THENIF MTYPE=’SB' THENINSERT INTO TRANS MSTR (TRANS NO,ACCT NO,DT,TYPE,PARTICULAR, DR_CR,AMT, BALANCE)VALUES(SELECT ‘T' ||TO CHAR(MAX(TO NUMBER(SUBSTR(TRANS N0,2))+1 )FROMTRANS_MSTR),MACCT_NO,SYSDATE,'C','INITTAL PAYEMENT',D,500,500);ELSEINSERT INTO TRANS MSTR (TRANS NO,ACCT N0,DT,TYPE,PARTICULAR DR_CR,ANIT, BALANCE)VALUES((SELECT 'T' ||TOCHAR(MAX(TO NUMBER(SUBSTR(TRANS N0,2)))+ 1)FROMTRANS MSTR),MA-COINO,SYSDATE/C,INITIA1 PAY EMENT',D',200,200);END IF;

END IF;END LOOP;CLOSE SCANTABLE;

COMMIT;END;

Output :-

PL/SQL procedure successfully completed.

Deleting Function:DROP FUNCTION F_CHLACCTNO;

Page 19: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 19/136

Practical No.6

Aim: Creation of Stored Procedure.

Using a procedure

Example.The current example deals with the Fixed Deposit Maturity system. The tables involved with this processing are FD_DTLS,Trans_MSTR and ACCT_MSTR.Whenever a fixed deposit is due for payment and if there are instruction given to the bank for crediting the fixed deposit amount onmaturity to their account held in the bank an entity is passed in the TRANS_MSTR table fordeposit of the fixed .Finally the status of that fixed deposit is updated to reflect the increase ofthe current balance, Finally the status of that fixed deposits is updated to reflect the increase ofthe current balance. In order to simply of that fixed deposit is updated as Mie. Matured in theFD_DTLS tables. In order to simplify the job of insertion and updating of threetables(TRANS_MSTR,FD_DTLS and ACCT_MSTR)each time a fixed deposit is due for

 payment a procedure is created .This procedure is then called in the PL/SQL block whilechecking for those fixed deposits due for payment.

CREATE OR REPLACE PROCEDURE PROC_INSUPD(VFD_NO IN VARCHAR2, VACCT_NO INVARCHAR2, AMT IN NUMBER) IS/* Variable declarations */

mCurBal number;

BEGIN/* Retrieving the current balance */

SELECT CURBAL INTO mCurBal FROM ACCT_MSTR WHERE ACCT_NO = vACCT_NO;

/* Inserting a record in the TRANS_MSTR table */INSERT INTO TRANS_MSTR (TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR, DR_CR,

AMT, BALANCE)VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR(TRANS_NO, 2))) + 1)

FROM TRANS_MSTR), vACCT_NO, SYSDATE, 'C', 'Fixed Deposit Payment', 'D', vAMT, (mCurBal +vAMT));

/* Updating the CURBAL in the ACCT_MSTR table */UPDATE ACCT_MSTR SET CURBAL = CURBAL + vAMT WHERE ACCT_NO = vACCT_NO;

/* Updating the STATUS in the FD_DTLS table */UPDATE FD_DTLS SET STATUS = 'M' WHERE FD_NO = vFD_NO;

END;

DECLARE/* Cursor CRSR_FDCHK retrieves all the records of table FD_DTLS which are active and due for payment */

CURSOR CRSR_FDCHK IS

Page 20: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 20/136

  SELECT FD_NO, PAYTO_ACCTNO, DUEAMT FROM FD_DTLSWHERE TO_CHAR(DUEDT,'DD-MM-YY') = TO_CHAR(SYSDATE,'DD-MM-YY')

AND STATUS = 'A' AND PAYTO_ACCTNO IS NOT NULL;

/* Declaration of memory variables that will hold values */mFD_NO VARCHAR2(10);mPAYTO_ACCTNO VARCHAR2(10);mAMT NUMBER(8,2);mState NUMBER := 0;

BEGIN/* Opening the cursor */

OPEN CRSR_FDCHK;LOOP

FETCH CRSR_FDCHK INTO mFD_NO, mPAYTO_ACCTNO, mAMT;EXIT WHEN CRSR_FDCHK%NOTFOUND;/* Call procedure proc_insupd to perform insert/update operations on tables. */

 proc_insupd(mFD_NO, mPAYTO_ACCTNO, mAMT);/* Updating the state to 1 i.e. there are fds due for payment */

mState := 1;END LOOP;

/* Display a message if no FDs are due for payment based on the mState variable */IF mState = 0 THEN

DBMS_OUTPUT.PUT_LINE('Currently there are no fixed deposits due for payment.');END IF;

CLOSE CRSR_FDCHK;

COMMIT;END;

Output:

Currently there is no fixed deposit due to payment.PL/SQl procedure successfully completed.

Deleting a Stored Procedure

DROP PROCEDURE PROC_INSUPD;

Page 21: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 21/136

 

Practical No.7

Aim: Creation Package.

The first step to creating a package is to create its specification. the specification declares theobject that are contained in the body of the package. A package is created using Oracle’s SQL *Plus interactive tool. A package can include Function and Procedure. The Variable declaredwithin the package can be accessed by any Function Procedure within the package. To Create aspecification issue the CREATE PACKAGE command

Example 1:

CREATE OR REPLACE PACKAGE TRANSACTION_MGMT AS

PROCEDURE PERFORM_TRANS(mACCT_NO VARCHAR2, MD VARCHAR2, AMT NUMBER);PROCEDURE CANCEL_FD(mFD_NO VARCHAR2);BAL NUMBER;P_ACCT_NO VARCHAR2(10);D_AMT NUMBER;END TRANSACTION_MGMT;

Output:-

Package Created.

Example 2:

CREATE OR REPLACE PACKAGE BODY TRANSACTION_MGMT ASPROCEDURE PERFORM_TRANS(mACCT_NO VARCHAR2, MD VARCHAR2, AMT NUMBER) ISBEGIN

SELECT CURBAL INTO BAL FROM ACCT_MSTR WHERE ACCT_NO = mACCT_NO;IF MD = 'D' THEN

INSERT INTO TRANS_MSTR(TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR,DR_CR, AMT, BALANCE)VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR( TRANS_NO, 2))) + 1)FROM TRANS_MSTR), mACCT_NO, SYSDATE, 'C', 'Deposit', MD, AMT, (BAL + AMT));UPDATE ACCT_MSTR SET CURBAL = CURBAL + AMTWHERE ACCT_NO = mACCT_NO;

ELSEIF AMT < BAL THEN

INSERT INTO TRANS_MSTR(TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR, DR_CR,AMT, BALANCE) VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR(TRANS_NO, 2))) + 1) FROM TRANS_MSTR), mACCT_NO, SYSDATE, 'C', 'Withdrawal', MD,AMT, (BAL - AMT));UPDATE ACCT_MSTR SET CURBAL = CURBAL - AMTWHERE ACCT_NO = mACCT_NO;

END IF;END IF;END;

Page 22: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 22/136

 

Example 3.

CREATE OR REPLACE PROCEDURE PROC_INSUPD(VFD_NO IN VARCHAR2, VACCT_NO IN

VARCHAR2, vAMT IN NUMBER) IS

/* Variable declarations */mCurBal number;

BEGIN/* Retrieving the current balance */

SELECT CURBAL INTO mCurBal FROM ACCT_MSTR WHERE ACCT_NO = vACCT_NO;

/* Inserting a record in the TRANS_MSTR table */INSERT INTO TRANS_MSTR (TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR, DR_CR, AMT,BALANCE)VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR(TRANS_NO, 2))) + 1) FROMTRANS_MSTR), vACCT_NO, SYSDATE, 'C', 'Fixed Deposit Payment', 'D', vAMT, (mCurBal + vAMT));

/* Updating the CURBAL in the ACCT_MSTR table */UPDATE ACCT_MSTR SET CURBAL = CURBAL + vAMT WHERE ACCT_NO = vACCT_NO;

/* Updating the STATUS in the FD_DTLS table */UPDATE FD_DTLS SET STATUS = 'M' WHERE FD_NO = vFD_NO;

END;

Example 4.

CREATE OR REPLACE FUNCTION F_CHKACCTNO(vACCT_NO IN VARCHAR2)/* Variable that hold data from the TRANS_MSTR table */dummyAcctNo VARCHAR2(10);

BEGINSELECT DISTINCT ACCT_NO INTO dummyAcctNo FROM TRANS_MSTRWHERE ACCT_NO = vACCT_NO;

/* If the SELECT statement retrieves data, return value is set to 1. */RETURN 1;

EXCEPTION/* If the SELECT statement does not retrieve data, return value is set to 0 */

WHEN NO_DATA_FOUND THENRETURN 0;

END;DECLARE/* Cursor SCANTABLE retrieves the required data from the table ACCT_MSTR */

CURSOR SCANTABLE ISSELECT ACCT_NO, TYPE FROM ACCT_MSTR;

/* Variables that hold data from the cursor scantable */mACCT_NO ACCT_MSTR.ACCT_NO%type;mTYPE ACCT_MSTR.TYPE%type;

Page 23: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 23/136

 /* Variable that stores the value returned by the f_ChkAccctNo function i.e. 1 or 0 */

valexists NUMBER(1);

BEGINOPEN SCANTABLE;

LOOPFETCH SCANTABLE INTO MACCT_NO, MTYPE;EXIT WHEN SCANTABLE%NOTFOUND;

/* Call function F_CHKACCTNO to check if ACCT_NO is present in TRANS_MSTR table */valexists := F_CHKACCTNO(MACCT_NO);

/* If ACCT_NO does not exist insert a record in the TRANS_MSTR table */IF valexists = 0 THENIF mTYPE = 'SB' THENINSERT INTO TRANS_MSTR (TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR, DR_CR,AMT, BALANCE)

VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR( TRANS_NO, 2))) + 1)FROM TRANS_MSTR), mACCT_NO, SYSDATE, 'C', 'Initial Payment', 'D', 500, 500);ELSEINSERT INTO TRANS_MSTR (TRANS_NO, ACCT_NO, DT, TYPE, PARTICULAR, DR_CR,AMT, BALANCE) VALUES((SELECT 'T' || TO_CHAR(MAX(TO_NUMBER(SUBSTR(TRANS_NO, 2))) + 1) FROM TRANS_MSTR), mACCT_NO, SYSDATE, 'C', 'Initial Payment','D', 2000, 2000);END IF;END IF;

END LOOP;CLOSE SCANTABLE;COMMIT;

END;

Package body

CREATE OR REPLACE PACKAGE BODY PCK_DEL ISPROCEDURE DEL_EMP_BRANCH(mBRANCH_NO VARCHAR2) IS noemp NUMBER;BEGIN

noemp := CNT_EMP_BRANCH(mBRANCH_NO);IF noemp < 2 AND noemp > 0 THEN

DELETE EMP_MSTR WHERE BRANCH_NO = mBRANCH_NO;DBMS_OUTPUT.PUT_LINE('All the employees belonging to the branch ' ||mBRANCH_NO || ' deleted sucessfully');

DELETE BRANCH_MSTR WHERE BRANCH_NO = mBRANCH_NO;

DBMS_OUTPUT.PUT_LINE('Branch ' || mBRANCH_NO || ' deleted sucessfully');END IF;

IF noemp = 0 THENDBMS_OUTPUT.PUT_LINE('There exist no employees in the branch.');

END IF;

IF noemp >= 2 THENDBMS_OUTPUT.PUT_LINE('There exist ' || noemp || ' employees in the branch ' ||

Page 24: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 24/136

  mBRANCH_NO || ' Skipping Deletion.');END IF;

END;FUNCTION CNT EMP BRANCH)mBRANCH_NO_VARCHAR)RETURN NUMBERnoemp NUMBER;

BEGIN

SELECT COUT(*) INTO noemp FROM EMP_MSTR WHEREBRANCH NO =mBRANCHNO;RETURN noemp;EXCEPTION WHEN NO_DATA_FOUND THENRETURN ):ENDEND PCK_DEL:

Output:

Package Body created

OVERLOADING PROCEDURE AND FUNCTION

Example 1:

Create a package to check that a numeric value is greater than zero and a date is less than or equal tosysdate.

CREATE OR REPLACE PACKAGE CHECK_FUNC IS FUNCTION VALUE_OK(DATE_ININDATE)RETURN VARCHAR2;FUNCTION VALUE_OK (NUMBER_IN IN NUMBER) RETURN VARCHAR2;END;

Output:

PACKAGE CREATED

CREATE OR REPLACE PACKAGE BODY CHECK FUNC IS FUNCTION VALUE_OKEND;(DATE_IN IN DATE) RETURN VARC2 IS BEGINIF DATE_IN==SYSDATE THENRETURN ‘output from the first-over function “true;END IF;ENDFUNCTION VALUE_OK(NUMBER_IN IN NUMBER)RETURN VARCHAR2 ISBEGINIF NUMBER_IN>0 THEN

RETURN ‘OUTPUT FROM THE SECOND OVER LOADED FUNCTION:TRUE”;ELSERETURN ‘OUTPUT FROM THE SECOND OVER LOADED FUNCTION:FALSE”;END IF;END;END;

OUTPUT:Package body created.

Page 25: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 25/136

 

Example 2:

The bank manager decides to activate all those accounts, which were previously marked as inactive or performing no transactions in last 365 days.Create a package spec and a package body named ACCT_MNTC that includes two procedures of thesame name and the second procedure accepts branch name.

Package Specification:

CREATE OR REPLACE PACKAGE ACCT_MNTC IS PROCEDUREACT_ACCTS(vBRANCH_NO IN NUMBER);

PROCEDURE ACT ACCTS(v NAME IN VARCHAR2);END;

OUTPUT:Package created.

Package Body:

CREATE OR REPLACE PACKAGE BODY ACCT_MNTC IS PROCEDUREACT_ACCTS(v BRANCH_NO IN NUMBERS)IS

BEGINUPDATE ACCT_MSTR SET STATUS = `A`WHERE BRANCH NO=`B`|| v BRANCH_NO AND STATUS =`S`IF SQL%ROWCQNT> O THENDBMS OUTPUT. PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ‘ACCOUNTS ACTIVATEDSUCCESSFULLY`);ELSE

DBMS_OUTPUT.PUT_LINE(‘CURRENTLY THERE EXIST NO INACTIVE ACCOUNTS INTHE BRANCH NO’|| v BRANCH_NO);END IF;

PACKAGE BODY

CREATE OR REPLACE PACKAGE BODY PCK_DEL IS PROCEDUREDELEMP_BRANCH(m BRANCH_NO VARCHAR)IS noemp number;BEGINnoemap:=CNT_EMP_BRANCH(m BRANCH_NO);IF noemap<2 AND noemap> 0 THENDELETE EMP MSTR WHERE BRANCH_NO=mBRANCH_NO;DBMS_OUTPUT.PUT_LINE(*All the employees belonging to the branch*

m BRANCHNO I ‘deleted successfully’);DELETE Branch_MSTR WHERE BRANCH_NO= m BRANCHNO;DBMSS_OUTPUT.PUT_LINE(*Branch*||m BRANCH_NO||’DELEATED SUCCESSFULLY’),END IF;

ENDPROCEDURE ACT_ACCTS(vname IN varchar2) IS

Page 26: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 26/136

BEGINUPDATE ACCT_MSTR SET STATUS =’A’ WHERE STATUS=’S’AND BRANCH_NO IN (SELECT BRANCH_NO FROM BRANCH_MSTR WHER NAME=Vname);IF SQL%ROWCOUTN>0 THENDBMS_OUTPUT.PUT_LINE(TO CHAR(SQL%ROWCOUNT)||’ACCOUNTS ACTIVIATEDSUCCESSFULLY’);

ELSEDBMS_OUTPUT.PUT_LINE(“currently there exist no inactive accounts in the branch’,vNames);ENDIF;END;END ACCT_MNTC;

Output:  package body created.

EXECUTE ACCTMNTC_ACCTACCTS(1);EXECUTE ACCT_MNTC.ACCT ACCTS(‘Vile Parle’);

Page 27: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 27/136

 

Practical No.8

Aim: Creation Triggers.

Create a transparent audit system for a table CUST_MSTR. The system must keep track of the

records that are being deleted or updated. The functionality being when a record is deleted ormodified the original record details and the date of operation are stored in the audit table, then the

delete or update operation is allowed to go through.

The table definition for audit system is given below:

Create table statement for the AUDIT_CUST table:

CREATE TABLE AUDIT_CUST(CUST_NO VARCHAR2(10),FNAME VARCHAR2(25),MNAME VARCHAR2(25),LNAME VARCHAR2(25), DOB_lNC DATE NOT NULL,OCCUP VARCHAR2(25),PHOTOGRAPH

VARCHAR2(25), SIGNATURE VARCHAR2(25), PANCOPY VARCHAR2(1),FORM60VARCHAR2(1), OPERATION VARCHAR2(20),USERID VARCHAR2(20),ODATE DATE);

Output:Table created.

CREATE TRIGGER AUDIT_TRAILAFTER UPDATE OR DELETE ON CUST_MSTRFOR EACH ROWDECLAREOPER VARCHAR2(8);BEGIN

IF updating THENOPER := 'UPDATE';END IF;IF deleting THENOPER := 'DELETE';END IF;INSERT INTO AUDIT_CUST VALUES (:OLD.CUST_NO, :OLD.FNAME, :OLD.MNAME,:OLD.LNAME,.:OLD.D0B_INC, :OLD.OCCUP, :OLD.PHOTOGRAPH,:OLD.SIGNATURE, :OLD.PANCOPY, :OLD.FORM60,OPER, USER, SYSDATE);END; 

Output:

Trigger created. 

Example 2

Write a database trigger on the TRANS_MSTR that checks the following:

  The account number for which the transaction is being performed is a valid account number

Page 28: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 28/136

  The Transaction Amount is not zero and is positive and  In case of a withdrawal the amount does not exceed the current balance for that account number

CREATE OR REPLACE TRIGGER TRANS_CHECKBEFORE INSERT ON TRANS_MSTR FOR EACH ROW

DECLAREv_CNT_ACCT_NO VARCHAR2(10);v_CURBAL NUMBER(10);BEGINSELECT COUNT(ACCT_NO) INTO v_CNT_ACCT_NOFROM ACCT_MSTR WHERE ACCT_NO = :new.ACCT_NO;IF v_CNT_ACCT_NO = 0 THENRAISE_APPLICATlON_ERROR( -20000,'The Account number is invalid.');END IF;IF :new.AMT <= 0 THENRAISE_APPLICATlON_ERROR(-20001,'The Transaction amount cannot' be negative or zero.');END IF;SELECT CURBAL INTO v_CURBALFROM ACCT_MSTR WHERE ACCT_NO= :new.ACCT_NO;IF v_CURBAL < :new.AMT AND :new.DR_CR = 'W' THENRAISE_APPLICATION_ERROR(-20002,'The amount of withdrawal cannot exceed the balance held in theaccount.');END IF;END;

Output:Trigger created .

Example 3

Generating Primary Key Using SequencesSequence Creation

CREATE SEQUENCE CUST_SEQ INCREMENT BY 1 START WITH 1;

Output:

Sequence created.

Database Trigger Creation

CREATE OR REPLACE TRIGGER CUST_NO_GENERATION

BEFORE INSERT ON CUST_MSTR FOR EACH ROW

DECLARE

PRIMARY_KEY_VALUE VARCHAR2(10);

BEGIN

SELECT ‘C’||TO_CHAR(CUST_SEQ.NEXTVAL) INTO PRIMARY_KEY_VALUE FROM DUAL;

:NEW.CUST_NO:=PRIMARY_KEY_VALUE;

END;

Page 29: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 29/136

Output: Trigger created

Practical No.9

Aim: Write a program that accepts names and display it 5 times in output screen.

DECLARE

 NAME VARCHAR2 (15) =’&NAME’;

 N NUMBER (2) =1;

BEGIN

WHILE N <=5

LOOP

DBMS_OUTPUT.PUT_LINE (NAME); N=N+1;

END LOOP;

END

Output:

SQL

SQL

SQL

SQL

SQL

Page 30: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 30/136

 

Practical No.10

Aim: Write a program that accepts principal,duration(in months) and rate of interest &

calculate Maturity amount.

DECLARE

PRINCIPAL NUMBER: =&PRINCIPAL;

MONTHS NUMBER: =&AMOUNT;

ROI NUMBER: =&ROI

MAMOUNT NUMBER;

BEGIN

MAMOUNT: =PRINCIPAL+ (PRINCIPAL*ROI/100)*MONTHS;

DBMS_OUTPUT.PUT_LINE (MAMOUNT);

END

Output:

PRINCIPAL=400

ROI=5%

MONTHS=6

MAMOUNT=5200

Page 31: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 31/136

 

Practical No.11

Aim: Write a program that accepts radius &calculate area of circle. Use PI as Constant.

DECLARE

RADIUS NUMBER: = &RADIUS

PI NUMBER: = 3.14;

AREA NUMBER;

BEGIN

AREA: = PI *(RADIUS * RADIUS);

DBMS_OUTPUT.PUT_LINE (“AREA IS “||AREA);

END

Output :

RADIUS = 40AREA IS 5024

Page 32: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 32/136

 

Practical No.12

Aim: Write a program that accepts number & display whether it is less than or equal to or

greater than 10.

DECLARE

 N NUMBER: = 5;

BEGIN

IF N =10 THEN

DBMS_OUTPUT.PUT_LINE (“GIVEN NUMBER IS EQUAL TO 10”);

ELSE IF N <10 THEN

DBMS_OUTPUT.PUT_LINE (“GIVEN NUMBRE IS LESS THAN 10”);

ELSE IF N >10 THEN

DBMS_OUTPUT.PUTLIN (“GIVEN NUMBER IS GREATER THAN 10);

END IF;

END

Output:

GIVEN NUMBER IS LESS THAN 10. 

Page 33: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 33/136

 

UNIVERSITY OF MUMBAI

INSTITUTE OF DISTANCE AND OPEN LEARNING (IDOL)*

*(Institute of Distance Education (IDE) is renamed)

CERTIFICATE

 THE EXPERIMENTS DULY SIGNED IN THIS JOURNAL REPRESENT THE BONAFIDE WORK BY MISS ______________________________ROLL NO. IN SEMESTER II  OF FIRST YEAR OF MASTER INCOMPUTER APPLICATION (MCA) IN THE COMPUTER LABORATORYOF PCP CENTER SHREE RAM COLLAGE, BHANDUP  FOR SUBJECT

_______________________ DURING ACADEMIC YEAR 2014 -2015 .

 ____________________ ____________________________

LECTURE IN CHARGE HEAD, DEPARTEMENT OF MCA

 ______________________

EXTERNAL EXAMINER

Page 34: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 34/136

 

INDEX 

Data Communication & Networking

SR.NO CONTENT SIGNATURE

1. Write a program to implement VRC

2. Write a program to implement LRC

3. Write a program to implement CRC

4. Write a program to implement checksum method

5. Write a program to check and correct the error in

the data at receiver end by implementing hammingcode.

6. Write a program to generate chipping sequenceusing Walsh matrix method

7. Write a program to implement character levelencryption by mono alphabetic encryption method

8. Write a program to implement character levelencryption by poly alphabetic encryption method

9. Write a program to implement bit stuffing

10. Write a program to shortest path routing algorithm11. Write a program to implement RSA Algorithm

12. Write a program to implement sink tree

Page 35: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 35/136

INDEX

Data Communication & Networking 

SR.NO CONTENT Date Sign

1. Write a program to implement VRC2. Write a program to implement LRC3. Write a program to implement CRC4. Write a program to implement

checksum method5. Write a program to check and correct

the error in the data at receiver end byimplementing hamming code.

6. Write a program to generate chippingsequence using Walsh matrix method

7. Write a program to implementcharacter level encryption by monoalphabetic encryption method

8. Write a program to implementcharacter level encryption by poly

alphabetic encryption method9. Write a program to implement bitstuffing

10. Write a program to shortest pathrouting algorithm

11. Write a program to implement RSAAlgorithm

12. Write a program to implement sinktree

Page 36: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 36/136

Page 37: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 37/136

Page 38: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 38/136

Page 39: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 39/136

Page 40: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 40/136

Page 41: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 41/136

Page 42: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 42/136

Page 43: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 43/136

Page 44: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 44/136

Page 45: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 45/136

Page 46: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 46/136

Page 47: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 47/136

Page 48: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 48/136

Page 49: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 49/136

Page 50: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 50/136

Page 51: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 51/136

Page 52: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 52/136

Page 53: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 53/136

Page 54: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 54/136

Page 55: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 55/136

Page 56: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 56/136

Page 57: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 57/136

Page 58: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 58/136

Page 59: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 59/136

Page 60: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 60/136

Page 61: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 61/136

Page 62: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 62/136

Page 63: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 63/136

Page 64: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 64/136

Page 65: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 65/136

Page 66: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 66/136

Page 67: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 67/136

Page 68: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 68/136

 

UNIVERSITY OF MUMBAI

INSTITUTE OF DISTANCE AND OPEN LEARNING (IDOL)*

*(Institute of Distance Education (IDE) is renamed)

CERTIFICATETHE EXPERIMENTS DULY SIGNED IN THIS JOURNAL REPRESENT

THE BONAFIDE WORK BY MISS ______________________________

ROLL NO. IN EME TER III  OF ECOND YEAR OF MA TER IN

COMPUTER APPLICATION (MCA)  IN THE COMPUTER LABORATORY

OF PCP CENTER HREE RAM COLLAGE, BHANDUP   FOR SUBJECT

_______________________ DURING ACADEMIC YEAR 2014 -2015 .

____________________ ____________________________

LECTURE IN CHARGE HEAD, DEPARTEMENT OF MCA 

  ______________________

  EXTERNAL EXAMINER 

Page 69: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 69/136

Practical No .1#include <stdio.h>

#include <conio.h>#define MAXSIZE 5

struct stack /* Structure definition for stack */{

int stk[MAXSIZE];

int top;};

typedef struct stack STACK;STACK s;

/* Function declaration/Prototype*/void push (void);

int pop(void);void display (void);

int main ()

{int choice;

int option = 1;

s.top = -1; printf ("STACK OPERATION\n");

while (option)

{

 printf ("------------------------------------------\n"); printf (" 1 --> PUSH \n");

 printf (" 2 --> POP \n");

 printf (" 3 --> DISPLAY \n"); printf (" 4 --> EXIT \n");

 printf ("------------------------------------------\n");

 printf ("Enter your choice\n");

scanf ("%d", &choice);

switch (choice){

case 1: push(); break;

case 2: pop();

 break;

case 3: display(); break;

case 4: return 0;

}

Page 70: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 70/136

fflush (stdin);

 printf ("Do you want to continue(Type 0 or 1)?\n");

scanf ("%d", &option);}

}

/*Function to add an element to the stack*/

void push ()

{int num;

if (s.top == (MAXSIZE - 1))

{ printf ("Stack is Full\n");

return;

}else

{  printf ("Enter the element to be pushed\n");

scanf ("%d", &num);s.top = s.top + 1;

s.stk[s.top] = num;

}return;

}

/*Function to delete an element from the stack*/int pop ()

{

int num;if (s.top == - 1)

{

 printf ("Stack is Empty\n");return (s.top);

}

else{

num = s.stk[s.top];

 printf ("poped element is = %d\n", s.stk[s.top]);s.top = s.top - 1;

}

return(num);}

/*Function to display the status of the stack*/

void display (){

int i;

Page 71: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 71/136

if (s.top == -1)

{

 printf ("Stack is empty\n");return;

}

else{

 printf ("\nThe status of the stack is\n");

for (i = s.top; i >= 0; i--){

 printf ("%d\n", s.stk[i]);

}}

 printf ("\n");

}

Output :

 

Page 72: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 72/136

Page 73: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 73/136

DATA STRUCTURES

INDEX

SR.NO  CONTENT  SIGNATURE 

1 Write a program create a Stack& addelements into the

stack,delete elementsfrom the same stack.

2 Write a program to create a Stack.

3 Write a program to create a Queue, addelements into

the queue & delete elementsfrom the same queue.

4 Write a program to create a Queue.

5 Write a program to traverse binary tree in :1 ) In-order form

2 )Pre-order form

3 )Post-order form

6 Write a program to count the leaf nodes in binary tree.

7 Write a program to create a SingleLinked

List, Insert & Delete elements from it.

8 Write a program to create a singlelinked list

9 Write a program to implement Bubble Sort

10 Write a program to implement Heap Sort11 Write a program to implement Insertion

Sort

12 Write a program to sort the given numbers by using

Bubble sort technique.

13 Write a program to join circular linked lists.

14 Write a program to join single linked lists.

Page 74: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 74/136

Practical No. 2

#include<stdio.h>

#include<conio.h>#include<alloc.h>

struct stack

{

int data;

struct stack *next;

};

struct stack *pop(struct stack *top);

struct stack *push(struct stack *top);

void main()

{

struct stack *top;

int reply,option,data;

clrscr();

top=NULL;

do

{

 printf("\nStack Operations: \n");

 printf(" --------------------- ");

 printf("\n 1.push \n 2.pop \n 3.exit\n\n");

 printf("Select Your option:");

scanf(" %d" ,&option);

switch(option)

{

Page 75: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 75/136

  case 1:top=push(top);

 break;

case 2:top=pop(top);

 break;

case 3: exit(0);

 break;

}

}

while(1);

}

struct stack *push(struct stack *top)

{

struct stack *c;

c=(struct stack*)malloc(sizeof(struct stack));

if(c==NULL)

{

 printf("\nlnsufficient Memory! ");

return(top);

}

 printf("\nEnter data: ");

scanf("%d",&c->data);

c->next=NULL;

 printf("\n\tTha Data item %d has been pushed into the stack \n\n",c->data);

if(top==NULL)

top=c;

else

{

c->next=top;

top=c;

}

Page 76: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 76/136

Page 77: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 77/136

Output:

Page 78: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 78/136

Practical No. 3

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

int queue[50],item;

int ch,n=0,front,rear,i;

void main()

{

void create();

void add();

void deletelast();

void display();

do

{

clrscr();

 printf("Queue operations");

 printf("\n ------------------- \n");

 printf("\n1:Create\n2.Add\n3.Delete last\n4.Display\n5.Exit");

 printf("\n Enter Your Choice:");

scanf("%d",&ch);

if(ch==1)

{

 printf("\nEnter maximum size of queue you wish to have:");

scanf("%d",&n);

}

switch(ch)

{

case 1:create();getch();break;

case 2:add();getch();break;

Page 79: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 79/136

  case 3:deletelast();getch();break;

case 4:display();getch();break;

case 5:exit(0);getch();break;

default:

 printf("Invalid choice! Try again ");

 break;

}

}

while (ch!=5);

getch();

}

void create()

{

 printf("\nCreating a Queue ");

 printf("\n---------------------- \n ");

front=0,rear=0;

 printf("\nQueue created");

return;

}

void add()

{

if(rear>=n){

 printf("\nQueue is full !");

getch();

return;

} else {

 printf("\nAdding eleme_ntinto a queue");

 printf("\n------------------------- \n");

 printf("Enter item to be inserted: ");

scanf("%d",&item);

Page 80: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 80/136

  rear++;

queue[rear]=item;

if(front==0)

front=1 ;

 printf("\nItem %d has been inserted into queue" ,item);

 printf("\nItems of queue are: ");

for(i=front;i<=rear;i++ )

{

 printf(" %d",queue[i]);

}

return;

}

}

void deletelast()

{

 printf("\nDeleting element from queue");

 printf("\n----------------------------- \n");

if(front==rear){

 printf("\nQueue is empty! ");

getch();

return;

}

front++;

item=queue[front];

 printf("\nItem %d has been deleted from queue",item);

 printf("\nItems of queue are:");

for(i=front;i<=rear;i++)

{

 printf(" %d",queue[i]);

}

Page 81: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 81/136

  return;

}

void display(){

 printf("\nDisplay all elements of Queue");

 printf("\nItems of queue are:");

for(i=front;i<=rear;i++)

{

 printf(" %d",queue[i]);

}

return;

}

Page 82: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 82/136

Output:

Page 83: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 83/136

 

Page 84: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 84/136

Practical No. 4

#include<stdio.h>

#include<conio.h>

#define max 3

int queue[max],data;

int front,rear,reply,option,x;

void main()

{

clrscr();

front=rear=-1;

do {

 printf("\nQueue Operations : \n1.Insert into Queue \n2.Delete from Queue\n3.Exit");

 printf("\nEnter Your choice: ");

scanf("%d",&option);

switch(option)

{

case 1: printf("\nEnter data to insert:");

scanf("%d", &data);

reply=insertq(queue,&rear,&data);

if(reply==-1)

 printf("\nQueue is full! ");

else

 printf("\nData %d inserted into Queue successfully !",data);

 break;

case 2: reply=deleteq(queue,&rear,&data);

if(reply==-1)

 printf("\nQueue is Empty! ");

else

 printf("\nData %d is deleted ....",data);

Page 85: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 85/136

  break;

case 3:exit(0);

default: printf("\nInvalide choice ..Try again ");

 break;

}

} while(1);

}

int insertq(int queue[max],int *rear, int *data)

{

if(*rear == max-1)

return (-1);

else //doubt about brackets

*rear=*rear+1;

queue[*rear]=*data;

return (1);

}

int deleteq(int queue[max],int *front, int *rear,int *data)

{

if(*front==*rear)

return (-1);

else//doubt about brackets

(*front)++;

*data=queue[*front];

return(1);

}

Page 86: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 86/136

Output:

Page 87: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 87/136

Practical No. 5

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

struct treerec

{

struct treerec *lchild;

struct treerec *rchild;

char data;

};

struct treerec *item;

struct treerec *rdata[50];

void main()

{

int i,n;

clrscr();

 printf("\nEnter no of data-items to be entered in tree: ");

scanf("%d" ,&n);

 printf("\nEnter data-items: ");

for(i=1;i<=n;i++)

{

rdata[i]=(struct treerec *)malloc(sizeof(struct treerec));

scanf("\r%c",&rdata[i]->data);

rdata[i]->lchild=NULL;

rdata[i]->rchild= NULL;

}

for(i=1;i<=n;i++)

{

Page 88: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 88/136

  rdata[i]->lchild=rdata[2*i];

rdata[i]->rchild=rdata[2*i+1];

}

item=rdata[1];

 printf("\nGiven Data in Tree\n");

for(i=1 ;i<=n;i++)

{

 printf("%c " ,rdata[i]->data);

}

 printf("\n\nInorder tree traversal - \t");

inorder(item);

 printf("\n\nPreorder tree traversal - \t");

 preorder(item);

 printf("\n\nPostorder tree traversal - \t");

 postorder(item);

getch();

}

inorder(cnode)

struct treerec *cnode;

{

if(cnode != NULL)

{

inorder(cnode->lchild);

if(cnode->data != '_')

{

 printf("%c" ,cnode->data);

}

inorder(cnode->rchild);

}

Page 89: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 89/136

  return (1);

}

 preorder(cnode)

struct treerec *cnode;

{

if(cnode != NULL)

{

if(cnode->data != '_')

{

 printf("%c" ,cnode->data);

}

 preorder(cnode->lchild);

 preorder(cnode->rchild);

}

return (1);

}

 postorder(cnode)

struct treerec *cnode;

{

if(cnode != NULL)

{

 postorder(cnode->lchild);

 postorder(cnode->rchild);

if(cnode->data != '_')

{

 printf("%c" ,cnode->data);

}

}

return (1);

}

Page 90: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 90/136

Output:

Page 91: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 91/136

Practical No. 6

#include<stdio.h>

#include<conio.h>#include<stdlib.h>

#include<alloc.h>

struct node {

int data;

struct node*left;

struct nade*right;

};

unsigned int getleafcount(struct node* node){

if(node==NULL)

return 0;

if(node->left==NULL && node->right==NULL)

return 1;

else

return (getleafcount(node->left)+getleafcount(node->right));

}

struct node*newnode(int data){

struct node*node=(struct node*)malloc(sizeof(struct node));

node->data=data;

node->left= NULL;

node->right= NULL;

return(node);

}

int main(){

Page 92: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 92/136

  struct node *root=newnode(1);

clrscr();

root->left=newnode(2);

root->right=newnode(3);

root->left->left=newnode(4);

root->left->right=newnode(5);

 printf("Leaf count of the tree is %d",getleafcount(root));

getch();

return 0;

}

Page 93: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 93/136

Output:

Page 94: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 94/136

Practical No. 7

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

struct studinfo{

int data;

struct studinfo *next;

};

struct studinfo *start=NULL,*ptr,*disp;

void insertnode();

void deletenode();

void display();

void main() {

int ch;

clrscr();

do{

 printf("\nMenu:\n------------");

 printf("\n1.Insert node \n2.Delete node\n3.Display\n4.Exit");

 printf("\nEnter Your Choice:");

scanf("%d",&ch);

fflush(stdin);

switch(ch){

case 1: insertnode();

 break;

case 2: deletenode();

 break;

case 3: display();

 break;

Page 95: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 95/136

  case 4: exit(1);

 break;

default:printf("\nInvalid choice entered! Enter again..");

 break;

}

} while(1);

}

void insertnode(){

struct studinfo *newnode;

newnode=(struct studinfo *)malloc(sizeof(struct studinfo ));

 printf("\nEnter data of for the node to be inserted .");

scanf("%d",&newnode->data);

 ptr=start;

if(start == NULL){

start=newnode;

newnode->next= NULL;

 ptr=newnode;

 printf("\n\New node with data:%d inserted",newnode->data);

} else {

 ptr->next=newnode;

newnode->next= NULL;

 ptr=newnode;

 printf("\nNew node with data:%d inserted",newnode->data);

}

fflush(stdin);

}

void deletenode(){

struct studinfo *del;

Page 96: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 96/136

  if( start== NULL)

 printf("\nList is empty");

else {

 ptr=start;

start=start->next;

free(ptr);

 printf("\nDeleted");

}

}

void display(){

 ptr=start;

for(disp=start; disp!=NULL; disp=disp->next){

if(ptr== NULL)

 printf("\nList is empty");

else{

 ptr=ptr->next;

 printf("\nData: %d",disp->data);

}

}

}

Page 97: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 97/136

Output:

Page 98: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 98/136

Practical No. 8

#include<stdio.h>

#include<stdlib.h>

struct node{

int data;

struct node *next;

};

struct node* add(struct node *head, int data)

{

struct node *tmp;

if(head == NULL)

{

head=(struct node *)malloc(sizeof(struct node));

if(head == NULL)

{

 printf("\nError! memory is not available");

exit(0);

}

head-> data = data;

head-> next = head;

}

else

{

tmp = head;

while (tmp-> next != head)

tmp = tmp-> next;

tmp-> next = (struct node *)malloc(sizeof(struct node));

if(tmp -> next == NULL)

{

Page 99: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 99/136

  printf("\nError! memory is not available");

exit(0);

}

tmp = tmp-> next;

tmp->data = data;

tmp->next = head;

}

return head;

}

void printlist(struct node *head){

struct node *current;

current = head;

if(current!= NULL){

do{

 printf("%d\t",current->data);

current = current->next;

} while (current!= head);

 printf("\n");

} else

 printf("\nThe list is empty");

}

void destroy(struct node *head){

struct node *current, *tmp;

current = head->next;

head->next = NULL;

while(current != NULL){

tmp = current->next;

free(current);

Page 100: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 100/136

  current = tmp;

}

}

void main(){

struct node *head = NULL;

clrscr();

head = add(head,1);

 printlist(head);

head = add(head,20);

 printlist(head);

head = add(head,10);

 printlist(head);

head = add(head,5);

 printlist(head);

destroy(head);

getch();

}

Page 101: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 101/136

Output:

Page 102: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 102/136

Practical No. 9

#include <stdio.h>

#include <conio.h>

void main(){

int i, j, temp;

int arr[5] = {25, 17,31,13,2};

clrscr();

 printf("Bubble sort.\n" );

 printf("\nArray before sorting:\n");

for (i = 0; i <= 4; i++)

 printf("%d\t", arr[i]);

for (i = 0; i <= 3; i++){

for ( j = 0 ; j <= 3 - i ; j++ ){

if(arr[j] > arr[j+1]){

temp = arr[j] ;

arr[j] = arr[j + 1] ;

arr[j + 1] = temp;

}

}

}

 printf ( "\n\nArray after sorting:\n") ;

for ( i = 0 ; i <= 4 ; i++ )

 printf ( "%d\t", arr[i] ) ;

getch();

}

Page 103: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 103/136

Page 104: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 104/136

Practical No. 10

#include <stdio.h>

#include <conio.h>

void makeheap (int [], int);void heapsort (int [], int);

void main(){

int arr[10] = {11,2,9,13,57,25,17,1,90,3};

int i ;

clrscr();

 printf("Heap Sort.\n");

makeheap(arr, 10);

 printf("\nBefore Sorting:\n");

for(i=0; i<=9; i++)

 printf("%d\t", arr[i]);

heapsort(arr, 10);

 printf("\nAfter Sorting:\n");

for (i=0;i<=9;i++)

 printf ("%d\t", arr[i]);

getch();

}

void makeheap(int x[],int n){

int i, val, s, f;

for (i=1;i < n;i++){

val = x[i];

s=i;

f=(s-1)/2;

while (s>0 && x[f]<val){

x[s] = x[f];

s=f;

Page 105: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 105/136

  f=(s-1)/2;

}

x[s] = val;

}

}

void heapsort (int x[], int n){

int i, s, f, ivalue ;

for (i=n-1;i>0;i--){

ivalue=x[i];

x[i]=x[0];

f=0;

if(i== 1)

s=-1;

else

s=1;

if(i>2 && x[2]>x[1])

s=2;

while(s>=0 && ivalue<x[s]){

x[f]=x[s];

f=s;

s=2*f+1;

if(s+1<=i-1 && x[s]<x[s+1])

s++;

if (s>i-1)

s=-1;

}

x[f]=ivalue;

}

}

Page 106: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 106/136

Output:

Page 107: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 107/136

Practical No. 11

#include <stdio.h>

#include <conio.h>

void main(){int arr[5] = {25,17,31,13,2};

int i,j,k,temp;

clrscr();

 printf ("Insertion sort.\n");

 printf ("\nArray before sorting:\n");

for (i=0; i<=4; i++)

 printf("%d\t", arr[i]);

for (i=1; i<=4; i++){

for (j=0; j<i; j++){

if (arr[j] > arr[i]){

temp = arr[j];

arr[j] = arr[i];

for (k=i; k>j; k--)

arr[k] = arr[k - 1];

arr[k + 1] = temp;

}

}

}

 printf("\n\nArray after sorting:\n");

for(i=0; i<=4; i++)

 printf( "%d\t", arr[i]);

getch();

}

Page 108: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 108/136

Output:

Page 109: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 109/136

Practical No. 12

#include <stdio.h>

#include <conio.h>

void main(){int i, j,arr[50],temp;

clrscr();

for(i=0;i<5;i++){

 printf("Enter no. %d: ",i+ 1);

scanf("%d" ,&arr[i]);

}

 printf ( "\nBubble sort.\n" ) ;

 printf ( "\n\nArray before sorting:\n\n\t") ;

for ( i = 0 ; i <= 4; i++ )

 printf("%d\t", arr[i]) ;

for ( i= 0 ; i <= 3 ; i++ ){

for (j = 0 ; j <= 3 - i ;j++ ){

if ( arr[j] > arr[j + 1] ){

temp = arr[j] ;

arr[j] = arr[j + 1] ;

arr[j + 1] = temp;

}

}

}

 printf ( "\n\nArray after sorting:\n\n") ;

for ( i = 0 ; i <= 4 ; i++ )

 printf("\t%d", arr[i] );

getch();

}

Page 110: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 110/136

Output:

Page 111: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 111/136

Page 112: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 112/136

Page 113: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 113/136

Page 114: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 114/136

Page 115: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 115/136

Page 116: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 116/136

Page 117: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 117/136

Page 118: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 118/136

Page 119: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 119/136

 

INDEX Object Oriented Programming in c++

SR.NO CONTENT Date Sign

1. Write a program to handle inlinefunction

2. Write a program to handle function

overloading.3. Write a program for constructor

overloading.4. Write a program using simple array of

character as well as c++string try reversalof string.

5. Write a program for counting words,lines, and character.

6. Write a program to create bank account

class which maintains info of accountholder as array of objects.

7. Write a program to implement operatoroverloading for string concatenation.

8. Write a program for exception witharguments &try with multiple catch.

9. Write a program to specify data inexception class & extracting data from

exception object.10. Write a program to open a file in binarymode.

Page 120: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 120/136

Aim: Program to demonstrate inline function.

#i ncl ude<i ost r eam. h>#i ncl ude<coni o. h> cl ass l i ne{

publ i c:i nl i ne f l oat mul ( f l oat x, f l oat y){

return(x*y) ;}i nl i ne f l oat cube( f l oat x){

r et ur n( x*x*x) ;}

};

voi d mai n( ){

l i ne obj ;f l oat val 1, val 2;cl r s cr ( ) ;cout <<"Ent er t wo val ues: " ;ci n>>val 1>>val 2;cout <<"\ nMul t i pl i cat i on val ue i s: "<<obj . mul ( val 1, val 2) ;

cout <<"\ n\ nCube val ue i s: "<<obj . cube(val 1) <<"\ t "<<obj . cube(val 2) ;get ch( ) ;

}

Out put : -

Enter two val ues: 5 7Mul t i pl i cat i on Val ue i s: 35Cube Val ue i s: 25 and 343

Page 121: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 121/136

Aim: Program to demonstrate function overloading.

#i ncl ude<i ost r eam. h>

#i ncl ude<st dl i b. h>

#i ncl ude<coni o. h>

#def i ne pi 3. 14 

cl ass f n 

publ i c:  

voi d area( i nt ) ; / / ci rc l e 

voi d area( i nt , i nt ) ; / / rect angl e 

voi d area( f l oat , i nt , i nt ) ; / / t r i angl e 

};  

voi d f n: : area( i nt a)  

cout <<"Ar ea of Ci r cl e: "<<pi *a*a;  

voi d f n: : area( i nt a, i nt b)  

cout <<"Ar ea of r ectangl e: "<<a*b;  

voi d f n: : area( f l oat t , i nt a, i nt b)  

cout <<"Ar ea of t r i angl e: "<<t *a*b;  

voi d mai n( )  

i nt ch;  

i nt a, b, r ;  

cl r scr ( ) ;  

f n obj ;  cout <<"\ n\ t \ t Funct i on Over l oadi ng" ;  

cout <<"\ n1. Ar ea of Ci r cl e\ n2. Ar ea of Rect angl e\ n3. Ar ea of

 Tr i angl e\ n4. Exi t \ n: ”;  

cout <<”Ent er your Choi ce: " ;  

ci n>>ch;  

Page 122: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 122/136

  swi t ch( ch)  

case 1:  

cout <<"Ent er Radi ous of t he Ci r cl e: " ;  

ci n>>r ;  

obj . area( r) ;  

break;  

case 2:  

cout <<"Ent er Si des of t he Rectangl e: " ;  

ci n>>a>>b;  

obj . ar ea( a, b) ;  

break;  

case 3:  

cout <<"Ent er Si des of t he Tri angl e: " ;  

ci n>>a>>b;  

obj . ar ea( 0. 5, a, b) ;  

break;  

case 4:  

exi t ( 0) ;  

get ch( ) ;  

Output: -

Funct i on Over l oadi ng

1. Ar ea of Ci r cl e

2. Ar ea of Rectangl e

3. Ar ea of Tr i angl e

4. Exi t

Enter Your Choi ce: 2

Ent er t he Si des of t he Rect angl e: 5 5

Ar ea of Rect angl e i s: 25

Page 123: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 123/136

Aim: Program to demonstrate constructor overloading.

#i ncl ude<i ost r eam>

#i ncl ude<coni o. h>

usi ng namespace st d;

cl ass Exampl e {

/ / Var i abl e Decl ar at i on

i nt a, b;

publ i c :

/ / Const r uct or wui t hout Ar gument

Exampl e( ) {

/ / Assi gn Val ues I n Const r uct ora=50;

b=100;

cout <<"\ nI m Const r uct or ";

}

/ / Const r uct or wi t h Ar gument

Exampl e( i nt x, i nt y) {

/ / Assi gn Val ues I n Const r uct or

a=x;

b=y;

cout <<"\ nI m Const r uct or " ;

}

voi d Di spl ay( ) {

cout <<"\ nVal ues : "<<a<<"\ t "<<b;

}

};i nt mai n( ) {

Exampl e Obj ect ( 10, 20) ;

Exampl e Obj ect2;

/ / Const r uct or i nvoked.

Obj ect. Di spl ay( ) ;

Page 124: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 124/136

  Obj ect2. Di spl ay( ) ;

/ / Wai t For Out put Scr een

get ch( ) ;

r et ur n 0;

}

Output  : -

I m Const r uctor

I m Const r uctor

Val ues : 10 20

Val ues : 50 100

Page 125: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 125/136

Aim: Program to reverse the string with customize string class and with the help of string

header file

#include<iostream.h>

#include<stdio.h>

#include<string.h>

#define MAX 50

class string

{

char st r [ Max] ;

publ i c :

/ / Oper at or over l oadi ng f r o the i nput edi ng st r i ng f r om consol e

Fr i end voi d oper ator >>( i st r eam& di n, st r i ng&s1)

{

di n>>s1. st r ;

}

/ / Oper at or over l oadi ng f or t he out put t i ng st r i ng t o consol e

f r i end voi d operator <<( ost r eam&dout , st r i ng&s1)

{

dout <s1. st r ;

}

/ / concat enat ed oper at i on i s done wi t h oper at or

str i ng reverse( ) ;

St r i ng( )

{

strcpy(s t r , ””) ;

}str i ng( char ss[] )

{

strcpy(s t r , s ) ;

}

};

Page 126: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 126/136

str i ng st r i ng: : reverse( )

{

char r ev[Max] ;

str cpy( rev, str ) ;

str rev( rev) ;

str i ng s(r ev) ;

r et ur n s;

}

voi d mai n( )

{

str i ng s1, s2, s3;

cl r scr ( ) ;

cout <<”Ent er t he st r i ng”;

ci n>>s1;

s2=s1. r ever se( ) ;

cout <<s2;

get ch( ) ;

}

Output: -

Ent er t he st r i ng

Shri

Rever se St r i ng

i r hS

Page 127: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 127/136

 

Aim: Program to count words, lines & characters.

#i ncl ude <i ost r eam. h>

#i ncl ude <i omani p. h>

#i ncl ude <coni o. h>

#def i ne MAX_ROW 5

#def i ne MAX_COL 80

voi d mai n( ) {

char name[ MAX_ROW] [ MAX_COL] , c; i nt l i nes=1; / / bcoz. f i r st l i ne wi l l bel ef t t o count . i nt wor ds=1; / / bcoz. f i r st wor d wi l l be l ef t t o count . i ntchar s=1; / / bcoz. f i r st char wi l l be l ef t t o count .

cl r s cr ( ) ;

cout <<"===I nput St at us===\ n";

cout <<"Ent er st r i ng t ermanate by # : " ;

ci n. get( c) ;

/ / Fi ndi ng no. of l i neswhi l e( c != ' #' ) {

ci n. get (c ) ;

char s++;

i f ( c==' ' | | c==' \ n' )

wor ds++;

i f ( c==' \ n' )

l i nes++;

}

cout <<"\ n"<<set w( 20)<<"Par t i cul ars" <<set w( 20) <<"Detai l s\ n";

cout <<" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ n" ;

cout . set f ( i os: : l ef t , i os: : adj ust f i el d) ;

cout <<"\ n"<<set w( 20)<<"No. of l i nes " ;

cout . set f ( i os: : r i ght , i os: : adj ust f i el d) ;

cout<<set w( 15) <<l i nes;

Page 128: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 128/136

 

cout . set f ( i os: : l ef t , i os: : adj ust f i el d) ;

cout <<"\ n"<<set w( 20) <<"No. of Words " ;

cout . set f ( i os: : r i ght , i os: : adj ust f i el d) ;

cout <<set w( 15) <<wor ds;

cout . set f ( i os: : l ef t , i os: : adj ust f i el d) ;

cout<<"\ n"<<set w( 20) <<"No. of Char act er s " ;

cout . set f ( i os: : r i ght , i os: : adj ust f i el d) ;

cout <<set w( 15) <<char s;

get ch( ) ;

}

Output:- 

===I nput St at us ====

Ent er st r i ng t er manant e by #: Hel l o Wor l d ! ! !

Abcd

Ef gh C++ Pr ogr ammi ng

Part i cul ar Det ai l s

No of l i ne 3

No of words 9

NO of char acters 52

Page 129: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 129/136

 

Aim: Program to create bank account class which maintains info of account holder as

array of objects

.

#i ncl ude <i ost r eam>#i ncl ude<st di o. h>#i ncl ude<st dl i b. h>#i ncl ude<mal l oc. h>#i ncl ude<i omani p>#i ncl ude<coni o. h>usi ng namespace st d;cl ass Bank{

char f name[20] , sname[20] ;l ong acc;f l oat amount ;publ i c :voi d get dat a( ){

cout <<"Ent er account no: \ t " ;ci n>>acc;cout <<"\ nEnt er f i r st name of account hol der " ;ci n>>f name;cout <<"\ nEnt er l ast name of t he account hol der " ;ci n>>sname;cout <<"\ nEnt er l edger bal ance of t he account " ;ci n>>amount ;

}

voi d di spl ay( ){

cout<<"\ nAccount number \ t : "<<set w( 10) <<acc;cout <<"\ nName \ t : "<<f name<<" "<<sname;cout<<"\ nBal ance \ t : "<<amount ;

}};i nt mai n( ){

i nt i , j =0, num=0;Bank b[ 5] ;cout <<"Ent er t otoal no of cust omer( maxi mum5) : " ;ci n>>num;f or( i =0; i <num; i ++){

 j ++;cout <<"Ent er f or account "<<j <<"\ n";b[ i ] . get dat a( ) ;

} j =0;cout <<" - - - - - - - - - - - - - - - - - - - - - - - - - - - - " ;

Page 130: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 130/136

f or( i =0; i <num; i ++){

b[ i ] . di spl ay( ) ;}

}

/ *Output  : -

Enter account no : 123456789Ent er f i r st name of account hol der : RamEnter l ast name of account hol der : sanketEnter l edger bal ance of t he account : 1000

Enter account no : 98707137455Enter f i r st name of account hol der : LaksmanEnter l ast name of account hol der : sanketEnter l edger bal ance of t he account : 1500

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Account number : 123456789Name : Ram sanketBal ance : 1000Account number : 98707137455Name : Laksman sanketBal ance : 1500

Process r etur ned 0 ( 0x0) execut i on t i me : 35. 159 s

*/

Page 131: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 131/136

Page 132: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 132/136

get ch( ) ;

}Output  : -

Ent er st r i ng one: shr ee

Ent er st r i ng t wo: r am st r i ng one i s: shr eestr i ng t wo i s: ram Concat enat ed st r i ng i s: shr ee r am 

Page 133: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 133/136

 

Aim: Program for exception handling with try and multiple catch

#i ncl ude <i ost r eam>#i ncl ude<st di o. h>#i ncl ude<st dl i b. h>#i ncl ude<mal l oc. h>#i ncl ude<i omani p>#i ncl ude<st r i ng. h>#i ncl ude<coni o. h>usi ng namespace st d;

voi d t est( i nt x){

try

{i f ( x>0)

t hr ow x;el se

t hr ow ' x' ;}

cat ch( i nt x){

cout <<"Catch a i nteger and t hat i nt eger i s: \ n"<<x;}

cat ch( char x){

cout <<"Catch a char acter and t hat character i s: \ n"<<x;}

}

i nt mai n( ){

cout <<"Test i ng mul t i pl e cat ches\ n: ";t est( 10) ;test (0 ) ;get ch( ) ;

}

Output: -

 Test i ng mul t i pl e cat chesCat ch a i nt eger and t hat i nt eger i s: 10Catch a char act er and t hat char act er i s: x

Page 134: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 134/136

 

Aim: Program for handling customize exception in c++

#i ncl ude <i ost r eam>

#i ncl ude<st di o. h>#i ncl ude<i omani p>#i ncl ude<st r i ng. h>#i ncl ude<coni o. h>usi ng namespace st d;

cl ass MyDi vi deByZer oExcept i on: publ i c except i on{publ i c :

const char * what ( ){

r et ur n "Di vi de By Zer o Except i on \ n" ;}

};i nt mai n( ){

try{

i nt a, b;cout<<"Ent er t wo number : " ;ci n>>a>>b;i f comput e a/ b

i f ( b==0){

MyDi vi deByZeroExcept i on d;t hr ow d;}el se{

cout <"a/ b ="<<a/ b<<endl}

}cat ch( except i on& e)

{cout<<e. what ( ) <<endl ;

}get ch( ) ;

}Oupt ut : -

$ a. outEnter t wo number : 10 2a/ b =5;Enter t ow number : 10 0Di vi de By Zero Except i on

Page 135: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 135/136

 

Aim: Program to Open file in binary mode

#i ncl ude <i ost r eam>#i ncl ude<st di o. h>

#i ncl ude<st dl i b. h>#i ncl ude<mal l oc. h>#i ncl ude<i omani p>#i ncl ude<st r i ng. h>#i ncl ude<coni o. h>usi ng namespace st d;

cl ass st udent{

i nt admno;char name[ 20] ;publ i c :voi d get dat a( ) ;

voi d showdat a( ) ;i nt r eadadmno( ) ;

};voi d st udent : : get dat a( ){

cout <<"\ Ent er t he admi ssi on no : "ci n>>admno;cout <<"\ n Enter your name : " ;gets( name) ;

}voi d st udent : : showdat a( )

{ cout <<"\ n Admi ssi on no : ="<<admno;cout <<"\ nNameL=";put s( name) ;

}i nt st udent : : r eadadmno( ){

r et urn admno;}voi d wr i t e_dat a( ){

st udent obj ;

of str eam f p2;f p2. open( "st udent . dat ", i os: : bi nary| i os: : app) ;obj . get dat a( ) ;i nt obj esi xe =si zeof ( obj ) ;f p2. wr i t e( ( char *) &obj , obj si ze) ;f p2. cl ose( ) ;

}voi d di spl ay( ){

Page 136: Mumbai Univeristy MCA IDOL Shree Ram College

8/16/2019 Mumbai Univeristy MCA IDOL Shree Ram College

http://slidepdf.com/reader/full/mumbai-univeristy-mca-idol-shree-ram-college 136/136

  st udent obj ;of str eam f p1;f p1. open( "st udent . dat ", i os: : bi nar y) ;i nt obj esi ze =si zeof ( obj ) ;whi l e( f p1. r ead( char *) &obj , obj si ze) ;{

obj . shodat a( ) ;}f p1. cl ose( ) ;

}voi d mai n( ){

cl r s cr ( ) ;wri t e_dat at ( ) ;di spl ay( ) ;get ch( ) ;

}

/ *Output: -

Ent er t he admi ssi on no 1Enter your name Yashadmi ss i on no: =1name: =Yash

*/