XII-CS-PRACTICAL LIST (UPDATED) 2014-15

(APRIL-MAY)
      1 .Write   an object oriented program to perform mathematical operations  (ADD, SUB, MULT,DIV , CONJUGATE , MOD , RECIPROCAL ) on COMPLEX Numbers.
 2. Write an   object oriented   program to perform mathematical operations (add, sub, multiply)  on MATRICES.
3. Write an   object oriented   program to enter   employee details along with salary details and display complete details and gross salary.
4. Write an   object oriented   program to enter marks details of a number of student s and display percentage and grades of   all students.
                                                           (JUNE-JULY)
5. Write a program   to perform   Binary Search on a list of integers sorted in Ascending Order.
6. Write a program to implement   Bubble   sort.
7. Write a program   to implement   Selection sort.
8. Write a program   to implement    Insertion   sort.
9. Write a program   to implement circular queue using array.
10. Write a program   to implement dynamic queue.
11. Write a program   to implement linear static queue.
12. Write a program to implement   dynamic stack.
13. Write a program   to implement stack using arrays.
                                                            (AUGUST)
14. Write a program to perform following string operations without using in-built library functions
1 Find length of string  2 Reverse a string  3 Change the case of all char in a string
15. Write a program to perform following in a TEXT FILE :
1. Count no. Of vowels   2. Count no. Of consonants   3. Count total no. Of alphabets
 16. Write a program to concat/combine the content of 2 different files into a third file.
17. Write a program to copy one text file into another.
                                                         (SEPTEMBER)
18.Write a menu Based application to do the following on Binary file :-
class Student{
                        int rollno;
                        char name[20];
                        int marks;
            public:
                      void setdata();//to acquire data for the student from user
                      void showdata();// to display the student data for all students
                      int getmarks(){ return marks;}
                      void givegrace(){marks=33;}
      };
                    Write functions to insert objects in “student.dat” file.
  •          Write function to disply objects from the “student.dat” file
  •         Search all the objects whose marks are between 28 and 32, apply givegrace() function and write back to the file.
19.Write a menu driven program to do the following in text file handling:


20. Write a C++ function that calculates the average word size in a text file

  • Swapping the first half with the second half in an 1D integer array
  • Write a C++ function to count the number of occurrence of character passed as the parameter of the function.
  • Write a C++ Function that counts the number of articles(“A”,”An”and”The”) in a given text files.
  •  Write a C++ function that transfers all the vowels from “source.txt” to “target.txt”.
  • Write a C++ function to count the number of lines starting with an alphabet passed as parameters.
  • Write a C++ function that counts the number of lines starting with the word “the”.
21.Write a menu based C++ program to do the following (Use user defined functions in each case):
  • ·         Reversing the 1 D integer Array
  •            Swapping the first half with the second half in an 1D integer array
22.Write a menu based C++ program to do the following (Use user defined functions in each case):
  •         Swapping the top half rows with the bottom half rows in a 2D integer array
  •          Swapping the left half columns with the right half columns in a 2D integer array.
  •       Transpose of a 2D integer array.
*************************************************************************************
**************************************************************************************
Assignment - SQL
1.                                            

TABLE : EMP
EMPNO
ENAME
JOB
HIREDATE
SAL
DOB
DEPTNO
7839
REA
MANAGER
12-DEC-98
5000
10-SEP-48
10
1234
PREM
CLERK
11-FEB-77
12000
12-DEC-50
20
6754
SITA
MANAGER
12-MAR-99
39000
12-MAR-68
50
6574
GITA
SALESMAN
11-JUN-99
7000
11-JUN-61
30
9876
HONEY
CLERK
12-JUN-00
12000
12-JUN-70
20
8976
REETA
SALESMAN
10-SEP-88
9000
10-SEP-48
30
1234
HINA
CLERK
11-FEB-77
39000
12-DEC-83
40
6794
SITA
MANAGER
12-MAR-99
10000
12-MAR-68
20
6578
HINA
SALESMAN
11-JUN-99
8000
11-JUN-60
30
9899
RAM
CLERK
12-JUN-00
12000
12-JUN-70
20
8988
REENA
SALESMAN
10-SEP-88
6000
10-SEP-48
30
6679
TASREEN
CLERK
12-JUN-00
22000
12-JUN-70
40
Table Constraints:
(i)                 . Primary Key : EMPNO ,
(ii) ENAME, DOB, DEPTNO cannot be left blank these are mandatory columns in table.
(ii)               Minimum salary of an employee is 5000. 
[A].Create table as per the specifications mentioned above and insert the records.
 (e) Display names of employees whose names include either of the substring “TA” or “RE”or “NA”.
(f) 1. Display data of all employees sorted in ascending order  by their department no, seniority and salary.
           2. Display DEPTNO,HIREDATE,SAL of all employees sorted by their department , seniority
              (in ascending) and salary (in descending).

(g) Count the no. of employees who have are not  managers.
(h) To display all employees who are retired and not working now a days
     (suppose Retiring Age=60).
(i) Show the average salary for all departments with more than 3 people for a job.
(j) Find out number of employees having ‘MANAGER’ as job.
(k) Create view DEPT20 with empno, name and the salary of employees for dept 20.
(l) Display department no. and number of employees in each department.
       (m)Show sum and average salary for depttNo=20.                                                    
       (n)Display  all employees have unique names.                                                            
        (o)Find al employess whose deptt is same as of ‘TASREEN’.                                                
        (p)Increase the salary of all MANAGER employees by 10%,                                                            
        (q)Find the deptno that is paying max salaries to its employees.                                           
 (r) Display the details of all the employees having salary less than 10000.   
(s) Display the list of all  SALESMAN who are getting salary beween 6000 and 8000.(inclusive range)
    
[B]  Find the output of the following : 
     1. SELECT SYSDATE FROM DUAL;
     2. SELECT ENAME,SAL FROM EMPLOYEE WHERE JOB IN (‘CLERK’,’SALESMAN’);
     3. SELECT COUNT(*) FROM EMP;
                  4. SELECT JOB, AVG(SAL) FROM EMP GROUP BY JOB;                                                         2.[A] Write SQL commands for the statements (i) to (vi) and give outputs for SQL queries (vii) to (x)

TABLE NAME : WORKERS
W_ID
FIRSTNAME
LASTNAME
ADDRESS
CITY
102
Sam
Tones
33 Elm St.
Paris
105
Sarah
Ackerman
440 U.S. 110
New York
144
Manila
Sengupta
24 Friends Street
New Delhi
210
George
Smith
83 First Street
Howard
255
Mary
Jones
842 Vine Ave.
Losantiville
300
Robert
Samuel
9 Fifth Cross
Wasington
335
Henry
Williams
12Moore Street
Boston
403
Ronny
Lee
121 Harrison St.
New York
451
Pat
Thompson
11 Red Road
Paris

TABLE NAME : DESIG
W_ID
SALARY
BENEFITS
DESIGNATION
102
75000
15000
Manager
105
85000
25000
Director
144
70000
15000
Manager
210
75000
12500
Manager
255
50000
12000
Clerk
300
45000
10000
Clerk
335
40000
10000
Clerk
400
32000
7500
Salesman
451
28000
7500
Salesman
(i)                             To display W_ID, FIRSTNAME, ADDRESS and CITY of all employees living in NEW YORK from the table WORKERS.
(ii)                           To display the content of workers table in ascending order of LASTNAME.
(iii)                         To display the FIRSTNAME, LASTNAME and total salary of all clerks from the tables WORKERS and DESIGN, where total salary is calculated as SALARY + BENEFITS.
(iv)                         To display the minimum salary among Managers and Clerks from the table DESIG.
(v)                           To display the W_ID FIRSTNAME, DESIGNATION of all employees.
(vi)                         To display the name of all Clerks.
(vii)                       SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE DESIGNATION = ‘Manager’ AND WORKERS.W_ID = DESIG.W_ID
(viii)                     SELECT COUNT(DISTINCT DESIGNATION) FROM DESIG.
(ix)                         SELECT DESIGNATION, SUM(SALARY FROM DESIGNATION GROUP BY DESIGNATION HAVING COUNT(*)<3;
(x)                           SELECT SUM(BENEFITS) FROM WORKERS WHERE DESIGNATION = ‘Salesman’;
3. (a)Write SQL commands for (a) to ( j) and write output for (h) on the basis of Teacher relation given below.
   TABLE NAME  :  TEACHER
No
Name
Age
Department
Date of Join
Salary
Gender
1.
Ram
34
Computer
10/01/97
12000
M
2.
Sharmila
31
History
24/03/98
20000
F
3.
Sandeep
32
Maths
12/12/96
30000
M
4.
Sangeeta
35
History
01/07/99
40000
F
5.
Rakesh
42
Maths
05/09/97
25000
M
6.
Shyam
50
History
27/02/97
30000
M
7.
Shiv Om
44
Computer
25/02/97
21000
M
8.
Shalakha
33
Maths
31/07/97
20000
F

(a)    To show all information about the teacher of history department.
(b)   To list the names of female teachers who are in Maths department
(c)    To list names of all teachers with their date of joining in ascending order.
(d)   To display students name, fee,age for male teacher only
(e)    To count the number of teachers with age>23.
(f)    To insert a new row in the TEACHER table with the following data:
9,”Raja”,26,”Computer”,13/05/95,2300,”M”.
       (g)To show all information about the teachers in this table
       (h)Add a new column named “Address”.
       (i)Arrange the whole table in the alphabetical order to name
       (j)Display the age of the teachers whose name starts with ‘S,.
       (k)Give the output of following statement.
(i)                 Select COUNT(distinct department) from TEACHER.
(ii)               Select MAX(Age)from Teacher where Gender=”F”
(iii)             Select AVG(Salary) from Teacher where Dateofjoin< ‘12/07/96’
(iv)              Select SUM(Salary) from teacher where Dateofjoin< ‘12/07/96’ 


                       

4.            Write the SQL commands for (a) to (d) and write the output for (e) on
               the basis of table Hospital :

        No
       Name
Age
Department
Dateofadmin
Charge
      Gender
1
Arpit
62
Surgery
21/01/06
300       
     M
2
Zayana
18
ENT
12/12/05
250  
F
3
Kareem
22
Orthopedic
19/02/06
450
M
4
Abhilash
26
Surgery
24/11/06
300
M
5
Dhanya
24
ENT
20/10/06
350
F
6
Siju
23
Cardiology
10/10/06
800
M
7
Ankita
16
ENT
13/04/06
100
F
8
Divya
15
Cardiology
10/11/06
500
F
9
Nidhin
25
Orthopedic
12/05/06
700
M
10
Hari
28
Surgery
19/03/06
450
M

(a)              To show all information about the patients of cardiology department.         
(b)              To list the name of female patients who are in ENT department.        
(c)              To list names of all patients with their date of admission in ascending order.                                 
(d)              To count the no of patients with age > 20.                                               
(e)              Give the output of the following SQL commands:                                   
(i)          Select COUNT(DISTINCT charges ) from hospital;
(ii)       Select MIN(age) from hospital where Gender=’M’;
(iii)           Select SUM(charges) from hospital where Gender =’F’;
(iv)       Select avg(charges) from hospital where dateofadm>{12/05/06};

********************************************************** 
……( SQL  : SOLUTION )……

SQL COMMANDS FOR CREATING TABLE :

CREATE TABLE EMPLOYEE
(EMPNO INT PRIMARY KEY,
ENAME VARCHAR(20) NOT NULL,
JOB VARCHAR(20) ,
HIREDATE DATE,
SAL DECIMAL  CHECK(SAL>=5000),
DOB DATE  NOT NULL,
DEPTNO INTEGER);
INSERT INTO EMPLOYEE VALUES(7839,'REA','MANAGER','12-DEC-98',5000,'12-JAN-51','10'); 
INSERT INTO EMPLOYEE VALUES(1234,'PREM','CLERK','11-FEB-77',12000,'12-DEC-50',20); 
INSERT INTO EMPLOYEE VALUES(6754,'SITA','MANAGER','12-MAR-99',39000,'12-MAR-68',50);

INSERT INTO EMPLOYEE VALUES(6574,'GITA','SALESMAN','11-JUN-99',7000,'11-JUN-61',30); 
INSERT INTO EMPLOYEE VALUES(9876,'HONEY','CLERK','12-JUN-00',12500,'12-JUN-70',20); 
INSERT INTO EMPLOYEE VALUES(8976,'REETA','SALESMAN','10-SEP-88',9000,'12-JAN-51',30); 
INSERT INTO EMPLOYEE VALUES(1243,'HINA','CLERK','11-FEB-77',39000,'12-DEC-83',40); 
INSERT INTO EMPLOYEE VALUES(6794,'SITA','MANAGER','12-MAR-99',10000,'12-MAR-68',20); 
INSERT INTO EMPLOYEE VALUES(6578,'HINA','SALESMAN','11-JUN-99',8000,'11-JUN-60',30); 
INSERT INTO EMPLOYEE VALUES(9899,'RAM','CLERK','12-JUN-00',12000,'12-JUN-70',20); 
INSERT INTO EMPLOYEE VALUES(8988,'REENA','SALESMAN','10-SEP-88',6000,'12-JAN-51',30); 
INSERT INTO EMPLOYEE VALUES(6679,'TASREEN','CLERK','12-JUN-00',22500,'12-JUN-70',40);  
[A]. (e) Display names of employees whose names include either of the substring “TA” or “RE”or “NA”.

SQL> SELECT ENAME FROM EMPLOYEE WHERE ((ENAME LIKE '%TA%') OR (ENAME LIKE '%RE%'
) OR (ENAME LIKE '%NA%'));

ENAME
--------------------
REA
SITA
PREM
GITA
REETA
SITA
HINA
REENA
TASREEN
HINA

10 rows selected.
(f) Display all data of all employees sorted by their department, seniority and salary.

SELECT * FROM EMPLOYEE ORDER BY DEPTNO,HIREDATE,SAL;

Display DEPTNO,HIREDATE,SAL of all employees sorted by their department, seniority and salary.

SQL> SELECT DEPTNO,HIREDATE,SAL FROM EMPLOYEE ORDER BY DEPTNO,HIREDATE,SAL;

    DEPTNO HIREDATE         SAL
---------- --------- ----------
        10 12-DEC-98       5000
        20 11-FEB-77      12000
        20 12-MAR-99      10000
        20 12-JUN-00      12000
        20 12-JUN-00      12500
        30 10-SEP-88       6000
        30 10-SEP-88       9000
        30 11-JUN-99       7000
        30 11-JUN-99       8000
        40 11-FEB-77      39000
        40 12-JUN-00      22500

    DEPTNO HIREDATE         SAL
---------- --------- ----------
        50 12-MAR-99      39000

12 rows selected.

Display DEPTNO,HIREDATE,SAL of all employees sorted by their department , seniority(in ascending) and salary (in descending).

SQL> SELECT DEPTNO,HIREDATE,SAL FROM EMPLOYEE ORDER BY DEPTNO,HIREDATE ASC,SAL DESC;

    DEPTNO HIREDATE         SAL
---------- --------- ----------
        10 12-DEC-98       5000
        20 11-FEB-77      12000
        20 12-MAR-99      10000
        20 12-JUN-00      12500
        20 12-JUN-00      12000
        30 10-SEP-88       9000
        30 10-SEP-88       6000
        30 11-JUN-99       8000
        30 11-JUN-99       7000
        40 11-FEB-77      39000
        40 12-JUN-00      22500

    DEPTNO HIREDATE         SAL
---------- --------- ----------
        50 12-MAR-99      39000

12 rows selected.
(g) Count the no. of  employees who have are not  managers.


SQL> SELECT COUNT(*) FROM EMPLOYEE WHERE (NOT JOB='MANAGER');

  COUNT(*)
----------
         9
SQL> SELECT COUNT(*) FROM EMPLOYEE WHERE (JOB !='MANAGER');

  COUNT(*)
----------
         9
SQL> SELECT COUNT(*) AS "NO OF EMPLOYEES" FROM EMPLOYEE WHERE (JOB !='MANAGER'); 

NO OF EMPLOYEES
---------------
              9

(h) To display all employees who are retired and not working now a days
     (suppose Retiring Age=60).

SQL> SELECT ENAME ,SYSDATE , DOB FROM EMPLOYEE WHERE
  2  MONTHS_BETWEEN(SYSDATE,DOB) >=720;

ENAME                SYSDATE   DOB
-------------------- --------- ---------
REA                  25-OCT-12 12-JAN-51
PREM                 25-OCT-12 12-DEC-50
REETA                25-OCT-12 12-JAN-51
REENA                25-OCT-12 12-JAN-51

DO NOT TRY THIS--->>> SELECT ENAME FROM EMPLOYEE WHERE MONTHS_BETWEEN(DOB,SYSDATE) >=720; 
(i) Show the average salary for all JOBS with more than 3 people for a job.

SELECT AVG(SAL) FROM EMPLOYEE GROUP BY JOB HAVING COUNT(*) >3;

SQL> SELECT JOB, AVG(SAL)FROM EMPLOYEE GROUP BY JOB HAVING CO
UNT(*) >3;

JOB                         AVG(SAL)       COUNT(*)    SUM(SAL)
--------------------         ----------           ----------        ----------
CLERK                         19600               5               98000
SALESMAN                   7500               4               30000

SELECT DEPTNO, AVG(SAL) FROM EMPLOYEE GROUP BY DEPTNO HAVING JOB IN ((SELECT JOB FROM EMPLOYEE GROUP BY JOB HAVING (CO
UNT(*) >3));

(j) Find out number of employees having ‘MANAGER’ as job.
(k) Create view DEPT20 with empno, name and the salary of employees for dept 20.
(l) Display department no. and number of employees in each department.
       (m)Show sum and average salary for depttNo=20.                                                        
       (n)Display  all employees have unique names.                                                                
        (o)Find al employess whose deptt is same as of ‘TASREEN’.                                                 
        (p)Increase the salary of all MANAGER employees by 10%,                                                              
        (q)Find the deptno that is paying max salaries to its employees.                                              
 (r) Display the details of all the employees having salary less than 10000.  
(s) Display the list of all  SALESMAN who are getting salary beween 6000 and 8000.(inclusive range)   
[B]  Find the output of the following :
            1. SELECT SYSDATE FROM DUAL;
            2. SELECT ENAME,SAL FROM EMPLOYEE WHERE JOB IN (‘CLERK’,’SALESMAN’);
            3. SELECT COUNT(*) FROM EMP;
            4. SELECT JOB, AVG(SAL) FROM EMP GROUP BY JOB; 
SELECT ENAME ,SYSDATE , DOB FROM EMPLOYEE WHERE
MONTHS_BETWEEN(SYSDATE,DOB) >=720;

___________________________THE END ...........................................................
.............................................................................................................................................
 1 .Write   an object oriented program to perform mathematical operations  (ADD, SUB, MULT, DIV , CONJUGATE , RECIPROCAL , MODULUS) on COMPLEX Numbers.
.................................................................................................................
 #include<iostream.h>
 #include<conio.h>
 #include<string.h>
 #include<stdio.h>
 #include<math.h>    
 class complex
 {
  double i,r;
  public:
  complex getconjugate();
  complex getreciprocal();
  float getmodulus();
  
  void read()
  {
  cout<<"\nEnter Real Part:";
  cin>>r;
  cout<<"Enter Imaginary Part:";
  cin>>i;
  }
  void display()
  {
  cout<<"\n= "<<r;
  if(i>=0) cout<<"+" ;
  cout<<i<<"i";
  }
  complex add(complex a2)
  {
  complex a;
  a.r=r+a2.r;
  a.i=i+a2.i;
  return a;
  }
  complex subtract(complex a2)
  {
  complex a;
  a.r=r-a2.r;
  a.i=i-a2.i;
  return a;
  }
  complex multiply(complex a2)
  {
  complex a;
  a.r=(r*a2.r)-(i*a2.i);
  a.i=(r*a2.i)+(i*a2.r);
  return a;
  }
  complex divide(complex a2)
  {
  complex a;
  a.r=((r*a2.r)+(i*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
  a.i=((i*a2.r)-(r*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
  return a;
  }
 };
    complex complex::getconjugate()
            {
                 complex tmp;
               tmp.r=this->r;
               tmp.i=this->i * -1;
               return tmp;
            }

            complex complex::getreciprocal()
            {
                 complex t;
               t.r=r;
               t.i=i* -1;
               float div;
               div=(r*r)+(i*i);
               t.r/=div;
               t.i/=div;
               return t;
            }

            float complex::getmodulus()
            {
                 float z;
               z=(r*r)+(i*i);
               z=sqrt(z);
               return z;
            }
 void main()
 {
 int ch;
 clrscr();
 complex a,b,c;
 do
 {
  cout<<"\n1.Addition 2.Substraction";
  cout<<" 3.Mulitplication 4.Division 5.Conjugate 6. Reciprocal 7.Modulus 8.Exit\n";
  cout<<"\nEnter the choice :";
  cin>>ch;
  switch(ch)
  {
  case 1:
       cout<<"\nEnter The First Complex Number:";
       a.read();
       a.display();
       cout<<"\nEnter The Second Complex Number:";
       b.read();
       b.display();
       c=a.add(b);
       c.display();
       break;
  case 2:
       cout<<"\nEnter The First Complex Number:";
       a.read();
       a.display();
       cout<<"\nEnter The Second Complex Number:";
       b.read();
       b.display();
       c=a.subtract(b);
       c.display();
       break;
  case 3:
       cout<<"\nEnter The First Complex Number:";
       a.read();
       a.display();
       cout<<"\nEnter The Second Complex Number:";
       b.read();
       b.display();
       c=a.multiply(b);
       c.display();
       break;
  case 4:
       cout<<"\nEnter The First Complex Number:";
       a.read();
       a.display();
       cout<<"\nEnter The Second Complex Number:";
       b.read();
       b.display();
       c=a.divide(b);
       c.display();
       break;
  case 5:
       cout<<"\nEnter a Complex Number:";
       a.read();
       a.display();
       b=a.getconjugate();
       cout<<"\n Conjugate OF COMPLEX NO. IS : ";
       b.display();
       break;
  case 6:
       cout<<"\nEnter a Complex Number:";
       a.read();
       a.display();
       b=a.getreciprocal();
       cout<<"\n RECIPROCAL OF COMPLEX NO. IS : ";
       b.display();
       break;
  case 7:
       cout<<"\nEnter a Complex Number:";
       a.read();
       a.display();

       cout<<"\n MODULUS OF COMPLEX NO. IS : "<<a.getmodulus();
         break;
    }
  }while(ch!=8);
 getch();

 }
***********************************************************************
***********************************************************************
Syllabus for XII CS  2014-15 (DATA STRUCTURES)

Introduction to data structure – arrays, stacks, queuesArrays: One and two Dimensional arrays: Sequential allocation and address calculation;One dimensional array: Traversal, Searching (Linear, Binary Search), Insertion of an element in an array,deletion of an element from an array, Sorting (Insertion, Selection, Bubble)Two-dimensional arrays: Traversal Finding sum/difference of two NxM arrays containing numericvalues,Interchanging Row and Column elements in a two dimensional array;Stack (Array and Linked implementation of Stack): Introduction to stack (LIFO_Last in FirstOutOperations) Operations on Stack (PUSH and POP) and its Implementation in C++, Convertingexpressionsfrom INFIX to POSTFIX notation and evaluation of Postfix expression;Queue: (Circular Array and Linked Implementation): Introduction to Queue (FIFO - First in Firstoutoperations) Operations on Queue (Insert and Delete and its Implementation in C++.
………. BUBBLE SORT  ……
#include<conio.h>
#include<iostream.h>
void main(){
int a[50];
int i,j,n,temp;
cout<<"\n                     BUBBLE SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DATA ENTRY...  \n";
for(j=0;j<n;j++)
  {   
     cout<<"\n Enter element no. "<<(j+1)<<'\t';
      cin>>a[j];
  }
for(i=0;i<n;i++)
   for(j=0;j<n-i;j++)
            {
              if(a[j]>a[j+1])
                   {
                       temp=a[j];
                       a[j]=a[j+1];
                       a[j+1]=temp;
                    }
            }
cout<<"\n   RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
            cout<<a[j]<<"   ";
cout<<endl;
getch();
}
                                                  ……… INSERTION SORT  ……………
#include<conio.h>
#include<iostream.h>
void main()
{
int a[50];
int i,j,n,temp;
clrscr();
cout<<"\n                     INSERTION SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DATA ENTRY...  \n";
for(j=0;j<n;j++)
{
  cout<<"\n Enter element no. "<<(j+1)<<'\t';
  cin>>a[j];
}
for(i=0;i<n-1;i++)
{     temp=a[i+1];
       j=i;
      while((a[j]>temp)&&(j>=0))
               {
                   a[j+1]=a[j];
                   j--;
               }
      a[j+1]=temp;
}
cout<<"\n   RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
cout<<a[j]<<"   ";
cout<<endl;
getch();
}
……………………… SELECTION SORT ……………………..
#include<conio.h>
#include<iostream.h>
void main()
{
int a[50];
int i,j,n,smallest,temp;
//clrscr(); 
cout<<"\n                     SELECTION SORT  \n";
cout<<"   ENTER TOTAL NO. OF ELEMENTS ( N<=50 )TO BE SORTED :   ";
cin>>n;
cout<<"   NOW START DATA ENTRY...  \n";
for(j=0;j<n;j++)
  {      cout<<"\n Enter element no. "<<(j+1)<<'\t';
        cin>>a[j];
  }
for(i=0;i<n-1;i++)
{
   smallest=i;
   for(j=i+1;j<n;j++)
                 if(a[smallest]>a[j])
                             smallest=j;
   temp=a[i];
   a[i]=a[smallest] ;
   a[smallest]=temp;
 }
cout<<"\n RESULT :  ARRAY AFTER SORTING IS  \n";
for(j=0;j<n;j++)
            cout<<a[j]<<"   ";
cout<<endl;
getch();
}
…………… BINARY SEARCH  ……..........
#include<conio.h>
#include<iostream.h>
void main() {
int a[50];
int j,n,data,found,first,mid,last;
//clrscr(); 
cout<<"\n                 BINARY SEARCH  \n";
cout<<"   ENTER TOTAL NO.OF ELEMENTS ( N<=50 )PRESENT IN THE ARRAY (IN ASCENDING ORDER) :   ";
cin>>n;
for(j=0;j<n;j++)
  {
      cout<<"\n Enter element no. "<<(j+1)<<'\t';
      cin>>a[j];
  }
  cout<<"   NOW ENTER A DATA TO BE SEARCHED...  \n";
  cin>>data;

  first=0; last=n-1; found=0;
  while(first<=last)
  {
    mid=(first+last)/2;
    if(data==a[mid]) {found=1;break;}
    if(data<a[mid]) last=mid-1;
      else first=mid+1;
   }
   if(found) cout<<"  ELEMENT FOUND AT POSITION   "<<(mid+1);
      else  cout<<"   ELEMENT NOT FOUND";
cout<<endl;
getch();
}
.........................................................................................
// A Program To Add Elements (Add At Beginning) In Dynamic Linked List And
 // Display Its Content..(Ok..Tested)
#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL;  //GLOBAL POINTER VARIABLE
  node * create(int d)
  {    node * p;
       p=new node;
       p->data=d;
       p->next=NULL;
       return p;
   }
   void insert_at_begining(node * p)
   {
   if(start==NULL)
   start=p;
   else
   p->next=start;
   start=p;
   }
   void display(node * q)
   {
      while(q)
        { cout<<q->data<<" --->";
          q=q->next;
        }
    }
    void main()
{    node * newptr;
     char ch='y';int d;
        while(ch=='y'|| ch=='Y' )
        {
         cout<<"\n  Enter a data item in LINKED LIST   :  ";
         cin>>d;
         newptr= create(d);
         insert_at_begining(newptr);
         cout<<"\n Do you want to enter more elements ?\n (press y or Y to continue ...)   ";
         cin>>ch;
       }
       cout<<"\n NOW CONTENT OF LINKED LIST IS : \n" ;
       display(start);
       getch();
}
...........................................................................................
// A PROGRAM TO PERFORM PUSH() ,POP() In LINKED STACK ( Dynamic Stack) AND //DISPLAY( ) ITS CONTENT..(OK..TESTED)
#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL , *p; //..GLOBAL POINTER VARIABLE
  node * create(int d)
  {
       p=new node;
       p->data=d;
        p->next=NULL;
       return p;
   }

   void PUSH(node * p)
   {
   if(start==NULL)
   start=p;
   else
   p->next=start;
   start=p;
   }

   void POP()
   {
   if(start==NULL) cout<<"\n EMPTY STACK ..";
   else
   {   p=start;
      start=start->next;
       delete p;
    }
   }

   void display()
   {
      node * p;
      if(start==NULL) cout<<"\n EMPTY STACK ..";
   else
     {  p=start;
        while(p)
         { cout<<p->data<<" --->";
          p=p->next;
         }
      }
    }

    void main()
      {
       node * newptr;
       char ch='y';int d;
        while(ch=='y'|| ch=='Y' )
        {
         cout<<"\n  Enter a data item in LINKED STACK   :  ";
         cin>>d;
         newptr= create(d);
         PUSH(newptr);
         cout<<"\n Do you want to enter more elements ? (press y or Y to continue ...)   ";
         cin>>ch;
       }
       cout<<"\n NOW CONTENT OF STACK IS : \n" ;
       display();
        cout<<"\n Do you want to POP more elements ? (press y or Y to continue ...)   ";
         cin>>ch;
        while(ch=='y'|| ch=='Y' )
        {
         POP();
         cout<<"\n Do you want to POP more elements ? (press y or Y to continue ...)   ";
         cin>>ch;
       }
       cout<<"\n NOW FINALLY CONTENT OF STACK IS : \n" ;
       display();
       getch();
     }                                                                                                                                                                        
// A Program To Add Elements (At End ) In Linked List And
 //Display( ) Its Content..(Ok..Tested)
#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL , *end=NULL;  //GLOBAL POINTER VARIABLES
  node * create(int d)
  {    node *p;
       p=new node;
       p->data=d;
       p->next=NULL;
       return p;
   }
      void insert_at_end(node * p)          //  ADD AT THE END
   {    if(start==NULL) { start=p; end=p; }   // first node
           else
            {
             end->next=p;
             end=p;
           }
   }
   void display(node * q)
   {
      while(q)
        { cout<<p->data<<" --->";
          p=p->next;

        }
    }

void main( )
{    
     node * newptr;
     char ch='y';int d;
        while(ch=='y'|| ch=='Y' )
        {
         cout<<"\n  Enter a data item in LINKED LIST   :  ";
         cin>>d;
         newptr= create(d);
         insert_at_end(newptr);
         cout<<"\n Do you want to enter more elements ? (press y or Y to continue ...)   ";
         cin>>ch;  
      }
       cout<<"\n NOW CONTENT OF LINKED LIST IS : \n" ;
       display(start);
       getch();
}
.......................................................................
// PROGRAM TO INSERT( )  & DELETE( )   ELEMENTS in LINKED QUEUE
// (DYNAMIC QUEUE)  and DISPLAY( )   CONTENT..(OK..TESTED)
#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL , *end=NULL;  //GLOBAL POINTER VARIABLE
  node * create(int d)
  {    node *p;
       p=new node;
       p->data=d;
       p->next=NULL;
       return p;
   }
      void insert(node * p)          //  ADD AT THE END
   {  if(start==NULL) { start=p; end=p; }
        else
          {
           end->next=p;
            end=p;
           }
   }

   void display(node * p)
   {
      if(p==NULL)  {cout <<"\n IT IS EMPTY..."; return ;}
      while(p)
        {
               cout<<p->data<<" --->";
                p=p->next;
        }
    }

    void delete_Node( )
   {   node * ptr;
        ptr=start;
           if(start == NULL)    cout <<"\n IT IS EMPTY...";
            else
                   { start=start->next; delete ptr;}
    }

 void main()
  {
       node * newptr;
       char ch='y';int d;
        while(ch=='y'|| ch=='Y' )
        {
         cout<<"\n  Enter a data item in LINKED LIST   :  ";
         cin>>d;
         newptr= create(d);
         insert(newptr);
         cout<<"\n Do you want to INSERT  more elements in QUEUE ?\n (press y or Y to continue ...)   ";
         cin>>ch;
       }
       cout<<"\n NOW CONTENT OF LINKED QUEUE IS : \n" ;
       display(start);
        cout<<"\n Do you want to DELETE   elements from  QUEUE ?\n (press y or Y to continue ...)   ";
         cin>>ch;
        while(ch=='y'|| ch=='Y' )
        {
        delete_Node();
         cout<<"\n Do you want to DELETE   elements from  QUEUE ? \n (press y or Y to continue ...)   ";
         cin>>ch;
               }
       cout<<"\n NOW CONTENT OF LINKED QUEUE IS : \n" ;
       display(start);
       getch();
}
………..SATATIC  STACK  -  AN  ARRAY  IMPLEMENTATION..........
#include <iostream.h>
#include<ctype.h>
#include<conio.h>
#define MAXSIZE 10
int stack[MAXSIZE];
int top=-1;  //index pointing to the top of stack
int main()
{
void push(int);
int pop();
char ch='y';int d;
while(ch=='y')
 {
    cout<<"\n  Enter a data to be entered/pushed in stack  :  ";
    cin>>d;
    push(d);
    cout<<"\n press y to continue   PUSH  ";
    cin>>ch;
}
ch='y';
while(ch=='y')
{
   cout<<"\n  NOW- CURRENT data present at top of   stack  IS:  ";
   cout<<pop();
   cout<<"\n press y to continue POP     ";
   cin>>ch;
}
getch();
return 0;
}
void push(int y)
{
      if(top==MAXSIZE-1) 
       {
          cout<<endl<<"STACK FULL--STACK OVERFLOW OCCURED";
          return;
        }
     else 
       {
         top++;
         stack[top]=y;
       }
}

int pop( )
{
   int a;
   if(top==-1) 
          {   cout<<endl<<"STACK EMPTY--STACK UNDERFLOW OCCURED";     return 0;   }
   else   {   a=stack[top];top--;   }
    return a;
   } /*  Circular Queue :  Implementation using Array  */
           #include<iostream.h>
   #include<conio.h>
   const int MAX = 5;
           int a[MAX],front=-1,rear=-1;
    void insert(int val)
   {
   if((front==0 && rear==MAX-1) || (rear+1==front))
     cout<<" Circular Queue is Full";
   else
   {
     if(rear==MAX-1)
     rear=0;
     else
    rear++;
     a[rear]=val;
   }
   if(front==-1)
     front=0;
   }
   int deletion()
   {
   int temp;
   if(front==-1)
   cout<<"Circular Queue is Empty";
   else
   {
   temp=a[front];
   if(front==rear)
      front=rear=-1;
   else
   {
      if(front==MAX-1)
      front=0;
      else
      front++;
   }
   }
   return temp;
   }

   void display()
   {
    int i;
    if(front==-1)
    cout<<"Circular Queue is Empty";
        else
       {
       if(rear < front)
      {
    for(i=front;i<=MAX-1;i++)
       cout<<a[i]<<"   ";
    for(i=0;i<=rear;i++)
       cout<<a[i]<<"   ";
    }
    else
    {
    for(i=front;i<=rear;i++)
       cout<<a[i]<<"   ";
    cout<<endl;
    }
    }
   }

   void main()
   {

   int choice,val;
   char option='N';
   do
   {
     clrscr();
     cout<<"-----------Menu------------";
     cout<<  " 1.Insertion \n"
                         <<  " 2.Deletion \n"
                         << " 3.Display  \n"
                         << " 4.Exit     \n";
     cout<<"Enter Your Choice <1..4> ?";
     cin>>choice;
     switch(choice)
     {    case 1 : cout<<"Enter Element to Insert ?";
      cin>>val;
      insert(val);
      break;
      case 2 : val=deletion();
        cout<<"Deleted Element :"<<val<<endl;
      break;
      case 3 : display();
          break;
   }
   cout<<"Do you want to continue<Y/N> ?";
   cin>>option;
    }while(option=='Y' || option=='y');
     getch();  }
…… DYNAMIC  QUEUE.(LATEST updated) .......
#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL,* end=NULL;
   void insert(int d)
   {   node * p;
       p=new node;
       p->data=d;
       p->next=NULL;

       if(start==NULL) {start=p; end=p;}
          else
            {end->next=p;      end=p;}
   }
   void display(node * p)
   {
      while(p)
        { cout<<p->data<<'\t'; p=p->next;
        }
    }   
   int remove()   {
      node * p; int d;
      p=start; d=start->data; start=start->next; delete p; return d;
      }

void main()
{
char ch='y';int d;
while(ch=='y')
{
    cout<<"\n  INSERT a data in DYNAMIC  QUEUE  :  ";
    cin>>d;
    insert(d);
    cout<<"\n CONTENT OF DYNAMIC  QUEUE IS : \n";
    display(start);
cout<<"\n press y to continue  .....";
cin>>ch;
}
ch='y';
while(ch=='y')
{   
    if(start==NULL) cout<<"QUEUE is empty...underflow";
       else cout<<"\n currently element removed from queue is "<<remove();
cout<<"\n press y to continue  .....";
cin>>ch;
}
getch();
}
………DYNAMIC  STACK.(LATEST updated) ……..

#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL;
   void push(int d)
   {   node * p;
       p=new node;
       p->data=d;
       p->next=NULL;

       if(start==NULL)  start=p;
          else
            {p->next=start;  start=p;}
   }

   void display(node * p)
   {
      while(p)
        { cout<<p->data<<'\t'; p=p->next;
        }
    }   
   int pop()   {
      node * p; int d;
      p=start; d=start->data; start=start->next; delete p; return d;
      }


void main()
{
char ch='y';int d;
while(ch=='y')
{
    cout<<"\n  PUSH a data in DYNAMIC  STACK  :  ";
    cin>>d;
    push(d);
    cout<<"\n CONTENT OF DYNAMIC  STACK IS : \n";
    display(start);
cout<<"\n press y to continue  .....";
cin>>ch;
}
ch='y';
while(ch=='y')
{   
    if(start==NULL) cout<<"STACK is empty...underflow";
       else cout<<"\n currently element removed from stack is "<<pop();
cout<<"\n press y to continue  .....";
cin>>ch;}
getch();}
::   POSITIVELY  NOT  THE  END    :: 

NOTE : Some more programs will be added soon to cover entire Syllabus in DATA STRUCTURE 

Popular posts from this blog

XII- CS-- SOLVED SQL queries (SQL PRACTICAL ASSIGNMENS)

SQL--HOME ASSIGNMENTS(XII Class)

Python-MySQL Connectivity