Saturday, 13 May 2017

C++ Lab Assignment for STD XII 2017-2018

To be copied in the Lab Note Book. The output should be tested in the Lab and the output should be sketched in the blank sheet of the Lab note book or Output should be pasted after taking the printout
The Lab note book should be submitted before puja Vacation
1.       Write a program to accept three sides of a triangle and find the area and perimeter of the rectangle
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
floata,b,c,s,ar,p;
clrscr();
cout<<"Enter Side A";
cin>>a;
cout<<"Enter Side B";
cin>>b;
cout<<"Enter Side C";
cin>>c;
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
p=a+b+c;
cout<<"Area of Triangle "<<ar<<"\n";
cout<<"Perimeter of Triangle "<<p<<"\n";
getch();
}

2.       Write a program to accept the angle from the user and find the value of sin, cos, tan, cosec, sec, cot of the given angle 
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
floata,ar;
clrscr();
cout<<"Enter Angle";
cin>>a;
ar=(3.142/180)*a;
cout<<"Sin "<<sin(ar)<<"\n";
cout<<"Cos "<<cos(ar)<<"\n";
cout<<"Tan "<<tan(ar)<<"\n";
cout<<"Cosec "<<1/sin(ar)<<"\n";
cout<<"Sec "<<1/cos(ar)<<"\n";
cout<<"Cot "<<1/tan(ar)<<"\n";
getch();
}

3.       Write a program to accept the amount in rupees and display how many 1000 Rs, 500 Rs, 100 Rs note the person receives
#include<iostream.h>
#include<conio.h>
void main()
{
intamt,thou,fivhun,onehun;
clrscr();
cout<<"Enter Amount to be withdrawn";
cin>>amt;
thou=amt/1000;
amt=amt%1000;
fivhun=amt/500;
amt=amt%500;
onehun=amt/100;
cout<<"1000 x "<<thou<<endl;
cout<<"500 x "<<fivhun<<endl;
cout<<"100 x "<<onehun<<endl;
getch();
}

4.       Write a program to accept the amount from the user and calculate the amount the user has to pay has to pay to the income tax department as tax.
#include<iostream.h>
#include<conio.h>
void main()
{
long amt;
clrscr();
cout<<"Enter Amount";
cin>>amt;
if(amt<=150000)
cout<<"No Tax "<<endl;
else if(amt<=250000)
cout<<"Tax Amount "<<.10*(amt-150000)<<endl;
else if(amt<=500000)
cout<<"Tax Amount "<<5000+.15*(amt-250000)<<endl;
else if(amt<=1000000)
cout<<"Tax Amount "<<25000+.25*(amt-500000)<<endl;
else
cout<<"Tax Amount "<<120000+.40*(amt-1000000)<<endl;
getch();
}

5.       Write a program to accept the choice from the user and perform the arithmetic operation as per user choice
1. Add Two Numbers
2. Subtract Two Numbers
3. Product Two Numbers
4. Divide Two Numbers
Enter your choice
#include<iostream.h>
#include<conio.h>
void main()
{
intch,a,b,c,d,e;
float f;
clrscr();
cout<<"1. Add Two Numbers"<<endl;
cout<<"2. Subtract Two Numbers"<<endl;
cout<<"3. Product Two Numbers"<<endl;
cout<<"4. Divide Two Numbers"<<endl;
cout<<"Enter your choice";
cin>>ch;                                                   
switch(ch)
{
case 1: cout<<"Enter A";
                cin>>a;
                cout<<"Enter B";
                cin>>b;
                c=a+b;
                cout<<"Result "<<c;
                break;
case 2: cout<<"Enter A";
                cin>>a;
                cout<<"Enter B";
                cin>>b;
                d=a-b;
                cout<<"Result "<<d;
                break;
case 3: cout<<"Enter A";
                cin>>a;
                cout<<"Enter B";
                cin>>b;
                e=a*b;
                cout<<"Result "<<e;
                break;
case 4: cout<<"Enter A";
                cin>>a;
                cout<<"Enter B";
                cin>>b;
                f=(float)a/b;
                cout<<"Result "<<f;
                break;
default: cout<<"Invalid Choice";
}
getch();
}

6.       Write a program to find the factorial of a given number
#include<iostream.h>
#include<conio.h>
void main()
{
intn,i,f=1;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++)
f=f*i;
cout<<"Factorial "<<f<<endl;
getch();
}

7.       Write a program to find the factors of a given number
#include<iostream.h>
#include<conio.h>
void main()
{
intn,i;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
cout<<"Factors "<<i<<endl;
}
getch();
}

8.       Write a program to find whether the given number is a prime number or a composite number
#include<iostream.h>
#include<conio.h>
void main()
{
intn,i,c=0;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
cout<<"Prime "<<endl;
else
cout<<"Composite "<<endl;
getch();
}

9.       Write a program to check whether the given number is a perfect number or not
#include<iostream.h>
#include<conio.h>
void main()
{
intn,i,c=0;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+i;
}
if(c==2*n)
cout<<"Perfect "<<endl;
else
cout<<"Not Perfect "<<endl;
getch();
}

10.   Write a program to accept two numbers and check whether the number is twin prime or not
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int m,n,i,c1=0,c2=0;
clrscr();
cout<<"Enter number";
cin>>m;
cout<<"Enter number";
cin>>n;
for(i=1;i<=m;i++)
{
if(m%i==0)
c1=c1+1;
}
for(i=1;i<=n;i++)
{
if(n%i==0)
c2=c2+1;
}
if(c1==2 && c2==2 && abs(m-n)==2)
cout<<"Twin prime "<<endl;
else
cout<<"Not Twin Prime "<<endl;
getch();
}


11.       Write a program to accept a number and sum the number of digits of a given number
#include<iostream.h>
#include<conio.h>
void main()
{
intn,s=0,j;
clrscr();
cout<<"Enter number";
cin>>n;
while(n>0)
{
j=n%10;
s=s+j;
n=n/10;
}
cout<<"Sum of digits "<<s<<endl;
getch();
}

12.       Write a program to accept a number and reverse the given number
#include<iostream.h>
#include<conio.h>
void main()
{
intn,s=0,j;
clrscr();
cout<<"Enter number";
cin>>n;
while(n>0)
{
j=n%10;
s=s*10+j;
n=n/10;
}
cout<<"Reverse "<<s<<endl;
getch();
}

13.       Write a program to accept a number and check whether it is palindrome or not
#include<iostream.h>
#include<conio.h>
void main()
{
intm,n,s=0,j;
clrscr();
cout<<"Enter number";
cin>>n;
m=n;
while(n>0)
{
j=n%10;
s=s*10+j;
n=n/10;
}
if(s==m)
cout<<"palindrome "<<s<<endl;
else
cout<<"Not Palindrome "<<s<<endl;
getch();
}

14.       Write a program to accept a number and check whether it is neon number or not
#include<iostream.h>
#include<conio.h>
void main()
{
intm,n,s=0,j;
clrscr();
cout<<"Enter number";
cin>>n;
m=n*n;
while(m>0)
{
j=m%10;
s=s+j;
m=m/10;
}
if(s==n)
cout<<"Neon "<<endl;
else
cout<<"Not Neon "<<endl;
getch();
}

15.       Write a program to accept a number and check whether it is twisted prime number or not
#include<iostream.h>
#include<conio.h>
void main()
{
intn,i,s=0,j,c1=0,c2=0;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
c1=c1+1;
}
while(n>0)
{
j=n%10;
s=s*10+j;
n=n/10;
for(i=1;i<=s;i++)
{
if(s%i==0)
c2=c2+1;
}
if(c1==2 && c2==2)
cout<<"Twisted prime"<<endl;
else
cout<<"Not Twisted prime"<<endl;
getch();
}

16.       Write a program to generate the Fibonacci series upto n terms.
#include<iostream.h>
#include<conio.h>
void main()
{
int f1=0,f2=1,f,i,n;
clrscr();
cout<<"Enter number";
cin>>n;
cout<<f1<<endl;
cout<<f2<<endl;
for(i=3;i<=n;i++)
{
f=f1+f2;
cout<<f<<endl;
f1=f2;
f2=f;
}
getch();
}

17.       Write a program to accept a number and check whether it is special number or not
#include<iostream.h>
#include<conio.h>
void main()
{
intm,n,s=0,j,f,i;
clrscr();
cout<<"Enter number";
cin>>n;
m=n;
while(n>0)
{
j=n%10;
f=1;
for(i=1;i<=j;i++)
f=f*i;
s=s+f;
n=n/10;
}
if(s==m)
cout<<"special number"<<endl;
else
cout<<"Not special number "<<endl;
getch();
}

18.       Write a program to accept five elements in an array and display all the odd elements first and then all the even elements present in  the array
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i;
clrscr();
for(i=0;i<=4;i++)
{
cout<<"enter element";
cin>>a[i];
}
cout<<"Odd elements \n";
for(i=0;i<=4;i++)
{
if(a[i]%2!=0)
cout<<a[i]<<endl;
}
cout<<"Even elements \n";
for(i=0;i<=4;i++)
{
if(a[i]%2==0)
cout<<a[i]<<endl;
}
getch();
}

19.       Write a program to accept five elements in an array and a search element from the user and search the element present in the array or not by linear search method
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,se,c=0;
clrscr();

for(i=0;i<=4;i++)
{
cout<<"enter element";
cin>>a[i];
}
cout<<"Search elements \n";
cin>>se;
for(i=0;i<=4;i++)
{
if(a[i]==se)
c=c+1;
}
if(c>0)
cout<<"Search Found"<<endl;
else
cout<<"Search Not Found"<<endl;
getch();
}              

20.   Write a program to accept five elements in an array and sort the elements in the ascending order by bubble sort method
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,j,t;
clrscr();
for(i=0;i<=4;i++)
{
cout<<"enter element";
cin>>a[i];
}
for(i=0;i<=3;i++)
{
for(j=0;j<=4-i-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}}}
for(i=0;i<=4;i++)
{
cout<<a[i]<<endl;
}
getch();
}

21.   Write a program to accept five elements in an array and a search element from the user and search the element present in the array or not by binary search method
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],i,j,t,m,l=0,h=4,se,c=0;
clrscr();
for(i=0;i<=4;i++)
{
cout<<"enter element";
cin>>a[i];
}
for(i=0;i<=3;i++)
{
for(j=0;j<=4-i-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}}}
cout<<"Enter search element";
cin>>se;
while(l<=h)
{
m=(l+h)/2;
if(a[m]==se)
{
c=c+1;
break;
}
if(a[m]<se)
l=m+1;
if(a[m]>se)
h=m-1;
}
if(c>0)
cout<<"search found"<<endl;
else
cout<<"search not found"<<endl;
getch();
}

22.   Write a program to accept a 3x3 matrix and display the original matrix and transpose of the matrix
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<"enter element";
cin>>a[i][j];
}
}
cout<<"Original Matrix"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"Transpose Matrix"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<a[j][i]<<"\t";
}
cout<<"\n";
}
getch();
}

23.   Accept two matrix of 3 rows and 3 columns and sum both the matrixes
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<"enter A element";
cin>>a[i][j];
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<"enter B element";
cin>>b[i][j];
}
}
cout<<"A Matrix"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"B Matrix"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"C Matrix"<<endl;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j] = a[i][j] + b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

24.   Accept two matrix of 2 rows and 2 columns and multiply both the matrixes
#include<iostream.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j,k;
clrscr();
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
c[i][j]=0;
}
}
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
cout<<"enter A element";
cin>>a[i][j];
}
}
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
cout<<"enter B element";
cin>>b[i][j];
}
}
cout<<"A Matrix"<<endl;
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"B Matrix"<<endl;
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"C Matrix"<<endl;
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
for(k=0;k<=1;k++)
{
c[i][j] =c[i][j]+(a[i][k] * b[k][j]);
}
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}


25. Write a program to create a function which can perform five arithmetic operation addition, difference, product, division and modulus
arithmetic() – to accept the values of a & b and perform all the arithmetic operation and display them.
#include<iostream.h>
#include<conio.h>
void arithmetic()
{
int a,b,c,d,e,g;
float f;
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
c=a+b;
d=a-b;
e=a*b;
f=(float)a/(float)b;
g=a%b;
cout<<"Sum = "<<c<<endl;
cout<<"Difference = "<<d<<endl;
cout<<"Product = "<<e<<endl;
cout<<"Division = "<<f<<endl;
cout<<"Modulus "<<g<<endl;
}
void main()
{
clrscr();
arithmetic();
getch();
}

26. Write a program to create a function which can perform five arithmetic operation addition, difference, product, division and modulus
accept() – To accept the values of a & b
arithmetic() –perform all the arithmetic operation and display them.
#include<iostream.h>
#include<conio.h>
int a,b,c,d,e,g;
float f;
void accept()
{
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
}
void arithmetic()
{
c=a+b;
d=a-b;
e=a*b;
f=(float)a/(float)b;
g=a%b;
cout<<"Sum = "<<c<<endl;
cout<<"Difference = "<<d<<endl;
cout<<"Product = "<<e<<endl;
cout<<"Division = "<<f<<endl;
cout<<"Modulus "<<g<<endl;
}
void main()
{
clrscr();
accept();
arithmetic();
getch();
}

27. Write a program to create a function which can perform five arithmetic operation addition, difference, product, division and modulus
accept() – To accept the values of a & b
add() – To add two numbers and display the sum
sub() – To subtract two numbers and display the difference
mul() – To multiply two numbers and display the product
div() – To divide two numbers and display the quotient with fractional part
mod() – To modulus two numbers and display the remainder
#include<iostream.h>
#include<conio.h>
int a,b,c,d,e,g;
float f;
void accept()
{
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
}
void add()
{
c=a+b;
cout<<"Sum = "<<c<<endl;
}
void sub()
{
d=a-b;
cout<<"Difference = "<<d<<endl;
}
void mul()
{
e=a*b;
cout<<"Product = "<<e<<endl;
}
void div()
{
f=(float)a/(float)b;
cout<<"Division = "<<f<<endl;
}
void mod()
{
g=a%b;
cout<<"Modulus "<<g<<endl;
}
void main()
{
clrscr();
accept();
add();
sub();
mul();
div();
mod();
getch();
}

28. Write a program to create a function which can perform five arithmetic operation addition, difference, product, division and modulus
accept() – To accept the values of a & b
add() – To add two numbers and display the sum
sub() – To subtract two numbers and display the difference
mul() – To multiply two numbers and display the product
div() – To divide two numbers and display the quotient with fractional part
mod() – To modulus two numbers and display the remainder
The user will have the opportunity to select the choice from five arithmetic operators
#include<iostream.h>
#include<conio.h>
int a,b,c,d,e,g;
float f;
void accept()
{
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
}
void add()
{
c=a+b;
cout<<"Sum = "<<c<<endl;
}
void sub()
{
d=a-b;
cout<<"Difference = "<<d<<endl;
}
void mul()
{
e=a*b;
cout<<"Product = "<<e<<endl;
}
void div()
{
f=(float)a/(float)b;
cout<<"Division = "<<f<<endl;
}
void mod()
{
g=a%b;
cout<<"Modulus "<<g<<endl;
}
void main()
{
clrscr();
int ch;
accept();
cout<<"1. Add Two Numbers"<<endl;
cout<<"2. Subtract Two Numbers"<<endl;
cout<<"3. Multiply Two Numbers"<<endl;
cout<<"4. Product Two Numbers"<<endl;
cout<<"5. Divide Two Numbers"<<endl;
cout<<"Enter choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:     add();
      break;
case 2:     sub();
      break;
case 3:     mul();
      break;
case 4:     div();
      break;
case 5:     mod();
      break;
default : cout<<"Invalid Choice";
}
getch();
}

29. Write a program to create a paramatise function which will accept two values as parameter and perform all the arithmetic operation with those two parameters
#include<iostream.h>
#include<conio.h>
void arithmetic(int a,int b)
{
int c=a+b;
int d=a-b;
int e=a*b;
float f=(float)a/(float)b;
int g=a%b;
cout<<"Sum = "<<c<<endl;
cout<<"Difference = "<<d<<endl;
cout<<"Product = "<<e<<endl;
cout<<"Division = "<<f<<endl;
cout<<"Modulus "<<g<<endl;
}
void main()
{
clrscr();
int a,b;
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
arithmetic(a,b);
getch();
}

30. Write a program to create a paramatise and returnable function which will accept two values as parameter and perform all the arithmetic operation separately with those two parameters

#include<iostream.h>
#include<conio.h>
int add(int a,int b)
{
int c=a+b;
return(c);
}
int sub(int a,int b)
{
int d=a-b;
return(d);
}
int mul(int a,int b)
{
int e=a*b;
return(e);
}
float div(int a,int b)
{
float f=(float)a/(float)b;
return(f);
}
int mod(int a,int b)
{
int g=a%b;
return(g);
}
void main()
{
clrscr();
int a,b;
cout<<"Enter A";
cin>>a;
cout<<"Enter B";
cin>>b;
cout<<"Sum = "<<add(a,b)<<endl;
cout<<"Difference = "<<sub(a,b)<<endl;
cout<<"Product = "<<mul(a,b)<<endl;
cout<<"Division = "<<div(a,b)<<endl;
cout<<"Modulus "<<mod(a,b)<<endl;
getch();
}

31. Write a program to accept a number in main. Pass the number to checkprime(), the checkprime() will check whether the number is prime or not
#include<iostream.h>
#include<conio.h>
void checkprime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
cout<<"Prime ";
else
cout<<"Not Prime";
}
void main()
{
clrscr();
int n;
cout<<"Enter Number";
cin>>n;
checkprime(n);
getch();
}

32. Write a program to accept a number in main. Pass the number to checkprime(), the checkprime() will check whether the number is prime or not and return the value to main for display
#include<iostream.h>
#include<conio.h>
int checkprime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
return(c);
}
void main()
{
clrscr();
int n,c;
cout<<"Enter Number";
cin>>n;
c=checkprime(n);
if(c==2)
cout<<"Prime ";
else
cout<<"Not Prime";
getch();
}

33. Write a program to generate all prime number between 1 to 100 using parameter and returnable function
#include<iostream.h>
#include<conio.h>
int checkprime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
return(c);
}
void main()
{
clrscr();
int n,c;
cout<<"Enter Number";
cin>>n;
c=checkprime(n);
if(c==2)
cout<<"Prime ";
else
cout<<"Not Prime";
getch();
}

34. Write a program to accept a number in main. Pass the number to function checkarmstrong, the checkarmstrong  will check whether the number is Armstrong or not and return the value to main for display

#include<iostream.h>
#include<conio.h>
int checkarmstrong(int n)
{
int j,s=0;
while(n>0)
{
j=n%10;
s=s+j*j*j;
n=n/10;
}
return(s);
}
void main()
{
clrscr();
int n,s;
cout<<"Enter number";
cin>>n;
s=checkarmstrong(n);
if(s==n)
cout<<"Armstrong";
else
cout<<"Not Armstrong";
getch();
}

 35. Write a perform to Create a stack of five element and perform the PUSH, POP operation on the Stack on user Choice using Menu Driven Program
#include<iostream.h>
#include<conio.h>
#include<process.h>
int a[5],top=0;
void push()
{
if(top==5)
{
cout<<"Stack Overflow";
getch();
}
else
{
cout<<"enter element";
cin>>a[top];
top++;
}}
void pop()
{
if(top<0)
{
cout<<"Underflow";
getch();
}
else
top--;
}
void display()
{
int i;
for(i=0;i<top;i++)
cout<<a[i];
getch();
}
void main()
{
clrscr();
int ch;
cout<<"1. Push \n";
cout<<"2. Pop \n";
cout<<"3. Display \n";
cout<<"4. Exit \n";
cout<<"Enter choice \n";
cin>>ch;
switch(ch)
{
case 1: push();
 break;
case 2: pop();
 break;
case 3: display();
 break;
case 4: exit(1);
 break;
default:cout <<"Invalid choice";
}
main();
}

36. Write a perform to Create a Queue of five element and perform the INSERT, DELETE operation on the QUEUE on user Choice using Menu Driven Program
#include<iostream.h>
#include<conio.h>
#include<process.h>
int a[5],rear=0,front=0;
void inser()
{
if(rear==5)
{
cout<<"Queue Overflow";
getch();
}
else
{
cout<<"enter element";
cin>>a[rear];
rear++;
}}
void delet()
{
if(front<0||front==rear)
{
cout<<"Queue Underflow";
getch();
}
else
front++;
}
void display()
{
int i;
for(i=front;i<rear;i++)
cout<<a[i];
getch();
}
void main()
{
clrscr();
int ch;
cout<<"1. Insert \n";
cout<<"2. Delete \n";
cout<<"3. Display \n";
cout<<"4. Exit \n";
cout<<"Enter choice \n";
cin>>ch;
switch(ch)
{
case 1: inser();
 break;
case 2: delet();
 break;
case 3: display();
 break;
case 4: exit(1);
 break;
default:cout <<"Invalid choice";
}
main();
}

37. Create a Double Ended Queue where insertion and deletion is done from both end. The size of the array is 5. The options are Insert Left, Insert Right, Delete Left, Delete Right
#include<iostream.h>
#include<conio.h>
#include<process.h>

int a[5],rear=0,front=0;

void insert_right()
{
if(rear==5)
{
cout<<"Queue Overflow";
getch();
}
else
{
cout<<"enter element";
cin>>a[rear];
rear++;
}}
void insert_left()
{
if(front==0)
{
cout<<"Queue Overflow";
getch();
}
else
{
front--;
cout<<"enter element";
cin>>a[front];
}}
void delete_left()
{
if(front<0||front==rear)
{
cout<<"Queue Underflow";
getch();
}
else
front++;
}
void delete_right()
{
if(rear>=5||front==rear)
{
cout<<"Queue Underflow";
getch();
}
else
rear--;
}
void display()
{
int i;
for(i=front;i<rear;i++)
cout<<a[i];
getch();
}
void main()
{
clrscr();
int ch;
cout<<"1. Insert left \n";
cout<<"2. Insert right \n";
cout<<"3. Delete left \n";
cout<<"4. Delete right \n";
cout<<"5. Display \n";
cout<<"6. Exit \n";
cout<<"Enter choice \n";
cin>>ch;
switch(ch)
{
case 1: insert_left();
 break;
case 2: insert_right();
 break;
case 3: delete_left();
 break;
case 4: delete_right();
 break;
case 5: display();
 break;
case 6: exit(1);
 break;
default:cout <<"Invalid choice";
 getch();
}
main();
}

38. Write a program for Linked List with the following options
1. create a node
2. add at beginning
3. add at middle
4. add at end
5. delete at beginning
6. delete at middle
7. delete at end
8. display the result
9. exit
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int roll;
node *next;
}*start,*new1,*ptr,*ptr1;
void create()
{
new1=new node;
start=NULL;
cout<<"enter element";
cin>>new1->roll;
start=new1;
new1->next=NULL;
}
void addbeg()
{
new1=new node;
cout<<"enter element";
cin>>new1->roll;
new1->next=start;
start=new1;
}
void addmid()
{
int pos,i=1;
cout<<"enter position";
cin>>pos;
new1=new node;
cout<<"enter element";
cin>>new1->roll;
ptr=start;
while(i<pos)
{
ptr=ptr->next;
i=i+1;
}
new1->next=ptr->next;
ptr->next=new1;
}

void addend()
{
new1=new node;
cout<<"enter element";
cin>>new1->roll;
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=new1;
new1->next=NULL;

}
void delbeg()
{
ptr=start;
start=ptr->next;
}
void delmid()
{
int pos,i=1;
cout<<"enter position";
cin>>pos;
ptr=start;
ptr1=ptr->next;
while(i<pos)
{
ptr=ptr->next;
ptr1=ptr1->next;
i=i+1;
}
ptr->next=ptr1->next;
}
void delend()
{
ptr=start;
ptr1=ptr->next;
while(ptr1->next!=NULL)
{
ptr=ptr->next;
ptr1=ptr1->next;
}
ptr->next=NULL;
}
void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<ptr->roll<<"\t";
ptr=ptr->next;
}
}
void main()
{
clrscr();
cout<<"1. create a node\n";
cout<<"2. add at beginning\n";
cout<<"3. add at middle\n";
cout<<"4. add at end\n";
cout<<"5. delete at beginning\n";
cout<<"6. delete at middle\n";
cout<<"7. delete at end\n";
cout<<"8. display the result\n";
cout<<"9. exit\n";
cout<<"enter ur choice";
int ch;
cin>>ch;
switch(ch)
{
case 1:create();
    break;
case 2:addbeg();
    break;
case 3:addmid();
    break;
case 4:addend();
    break;
case 5:delbeg();
    break;
case 6:delmid();
    break;
case 7:delend();
    break;
case 8:display();
    break;
case 9:exit(1);
default:cout<<"invalid choice";
}
getch();
main();
}

39. Write a program of Stack using Linked List. The Stack has the following conditions
1. CREATE A NODE
2. PUSH
3. POP
4. DISPLAY
5. EXIT
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int roll;
node *next;
}*start,*new1,*ptr,*ptr1;
void create()
{
new1=new node;
start=NULL;
cout<<"enter element";
cin>>new1->roll;
start=new1;
new1->next=NULL;
}
void addbeg()
{
new1=new node;
cout<<"enter element";
cin>>new1->roll;
new1->next=start;
start=new1;
}
void delbeg()
{
ptr=start;
start=ptr->next;
}
void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<ptr->roll<<"\t";
ptr=ptr->next;
}
}
void main()
{
clrscr();
cout<<"1. create a node\n";
cout<<"2. PUSH\n";
cout<<"3. POP\n";
cout<<"4. display the result\n";
cout<<"5. exit\n";
cout<<"enter ur choice";
int ch;
cin>>ch;
switch(ch)
{
case 1:create();
    break;
case 2:addbeg();
    break;
case 3:delbeg();
    break;
case 4:display();
    break;
case 5:exit(1);
default:cout<<"invalid choice";
}
getch();
main();
}

40. Write a program of Queue using Linked List. The Queue has the following conditions
1. CREATE A NODE
2.INSERT
3.DELETE
4. DISPLAY
5. EXIT
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int roll;
node *next;
}*start,*new1,*ptr,*ptr1;
void create()
{
new1=new node;
start=NULL;
cout<<"enter element";
cin>>new1->roll;
start=new1;
new1->next=NULL;
}
void addbeg()
{
new1=new node;
cout<<"enter element";
cin>>new1->roll;
new1->next=start;
start=new1;
}
void delend()
{
ptr=start;
ptr1=ptr->next;
while(ptr1->next!=NULL)
{
ptr=ptr->next;
ptr1=ptr1->next;
}
ptr->next=NULL;
}
void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<ptr->roll<<"\t";
ptr=ptr->next;
}
}
void main()
{
clrscr();
cout<<"1. create a node\n";
cout<<"2. INSERTION\n";
cout<<"3. deletion\n";
cout<<"4. display the result\n";
cout<<"5. exit\n";
cout<<"enter ur choice";
int ch;
cin>>ch;
switch(ch)
{
case 1:create();
    break;
case 2:addbeg();
    break;
case 3:delend();
    break;
case 4:display();
    break;
case 5:exit(1);
default:cout<<"invalid choice";
}
getch();
main();
}

















Saturday, 6 May 2017

SQL LAB ASSIGNMENT



Assignment 1
The structure of two tables along with the Relation given below
Give the SQL queries for the question given below
1. Select the last name of all employees.
SELECT LastName FROM Employees;

2. Select the last name of all employees, without duplicates.
SELECT DISTINCT LastName FROM Employees;

3. Select all the data of employees whose last name is "Smith".
SELECT * FROM Employees WHERE LastName = 'Smith';

4. Select all the data of employees whose last name is "Smith" or "Doe".
/* With OR */
SELECT * FROM Employees WHERE LastName = 'Smith' OR LastName = 'Doe';

/* With IN */
SELECT * FROM Employees WHERE LastName IN ('Smith' , 'Doe');

5. Select all the data of employees that work in department 14.
SELECT * FROM Employees WHERE Department = 14;

6. Select all the data of employees that work in department 37 or department 77.
/* With OR */
SELECT * FROM Employees WHERE Department = 37 OR Department = 77;
SELECT * FROM Employees WHERE Department IN (37,77);

7. Select all the data of employees whose last name begins with an "S".
SELECT * FROM Employees WHERE LastName LIKE 'S%';

8. Select the sum of all the departments' budgets.
SELECT SUM(Budget) FROM Departments;

9. Select the number of employees in each department (you only need to show the department code and the number of employees).
SELECT Department, COUNT(*)  FROM Employees  GROUP BY Department;

10. Select all the data of employees, including each employee's department's data.
SELECT SSN, E.Name AS Name_E, LastName, D.Name AS Name_D, Department, Code, Budget FROM Employees E INNER JOIN Departments D ON E.Department = D.Code;

11. Select the name and last name of each employee, along with the name and budget of the employee's department.
/* Without labels */
SELECT Employees.Name, LastName, Departments.Name AS DepartmentsName, Budget
FROM Employees INNER JOIN Departments ON Employees.Department = Departments.Code;

/* With labels */
SELECT E.Name, LastName, D.Name AS DepartmentsName, Budget FROM Employees E INNER JOIN Departments D ON E.Department = D.Code;

12. Select the name and last name of employees working for departments with a budget greater than $60,000.
/* Without subquery */
SELECT Employees.Name, LastName FROM Employees INNER JOIN Departments
ON Employees.Department = Departments.Code AND Departments.Budget > 60000;

/* With subquery */
SELECT Name, LastName FROM Employees WHERE Department IN
  (SELECT Code FROM Departments WHERE Budget > 60000);

13. Select the departments with a budget larger than the average budget of all the departments.
SELECT * FROM Departments WHERE Budget>(SELECT AVG(Budget)FROM Departments);

14. Select the names of departments with more than two employees.
/* With subquery */
SELECT Name FROM Departments WHERE Code IN (SELECT Department FROM Employees
      GROUP BY Departmens HAVING COUNT(*) > 2);

/* With UNION. This assumes that no two departments have the same name */
SELECT Departments.Name FROM Employees INNER JOIN Departments ON Department = Code GROUP BY Departments.Name HAVING COUNT(*) > 2;

15. Display all the information of all enployees
Select * from Employees;
16. Add a new department called "Quality Assurance", with a budget of $40,000 and departmental code 11. Add an employee called "Mary Moore" in that department, with SSN 847-21-9811.
INSERT INTO Departments VALUES ( 11 , 'Quality Assurance' , 40000);
INSERT INTO Employees VALUES ( '847219811' , 'Mary' , 'Moore' , 11);

17. Reduce the budget of all departments by 10%.
UPDATE Departments SET Budget = Budget * 0.9;

18. Reassign all employees from the Research department (code 77) to the IT department (code 14).
UPDATE Employees SET Department = 14 WHERE Department = 77;

19. Delete from the table all employees in the IT department (code 14).
DELETE FROM Employees WHERE Department = 14;

20. Delete from the table all employees who work in departments with a budget greater than or equal to $60,000.
DELETE FROM Employees WHERE Department IN (SELECT Code FROM Departments WHERE Budget >= 60000);

21. Delete from the table all employees.
DELETE FROM Employees;

Assignment 2
Table: Sales
OrderID
OrderDate
OrderPrice
OrderQuantity
CustomerName
1
12/22/2005
160
2
Smith
2
8/10/2005
190
2
Johnson
3
7/13/2005
500
5
Baldwin
4
7/15/2005
420
2
Smith
5
12/22/2005
1000
4
Wood
6
10/2/2005
820
4
Smith
7
11/3/2005
2000
2
Baldwin

Give the SQL Queries for the following operations
1. Count how many orders have made a customer with CustomerName of Smith.
2. Find number of unique customers that have ordered from the store.
3. Find out total no. of items ordered by all the customers.
4. Find out average number of items per order.
5. Find out the average OrderQuantity for all orders with OrderPrice greater than 200
6. Find out what was the minimum price paid for any of the orders.
7. Find out the highest OrderPrice from the given sales table
8. List out unique customers‟ name only from the table.
9. List out name of the customers who have given order in the month of DECEMBER
10. Find out the total amount of money spent for each of the customers.
11. Select all unique customers, who have spent more than 1200 in the store.
12. Select all customers that have ordered more than 5 items in total from all their orders.
13. Select all customers who have spent more than 1000, after 10/01/2005.
14. Select orders in increasing order of order price.
15. Select orders in decreasing order of order price.