Wednesday, April 1, 2015

RDBMS examples

Q.3). movie (mvno,mvname,releaseyear)

         Actor (actno,actname)

         Relationships between movie and actor is many to many with descriptive attribute rate of actor for movie.
   
         Constraints:- primary key.


SQL> select * from movie;

 MVNO    MVNAME         RELEASEYEAR
----------  --------------------  -----------
         1     dhoom                       2002
         2     DDLJ                        1999
         3    MBBS                        2000
         4    om kare                     2002
         5    singham                     2011

SQL> select * from actor;

 ACTNO  ACTNAME
----------   ------------------------------
       101    hrithik
       102    amitabh
       103    abhishek
       104    ajay
       105    salaman

SQL> select * from movact;

MVNO  ACTNO    RATE
---------- ---------- ----------
         1        101     500000
         2        102     800000
         3        103     900000
         4        105    1200000
         5        104    1500000
         2        104     700000
         1        101    1200000
7 rows selected.

SQL> set serveroutput on;

a).create or replace a PL/SQL procedure to display details of all movies of actor ‘amitabh’.

SQL>
  1  create or replace procedure showma(t in varchar2)
  2  is cursor c5 is select m.mvno,m.mvname,m.releaseyear
  3     from movie m,actor a,movact ma
  4     where m.mvno=ma.mvno and a.actno=ma.actno and
  5     a.actname=t;
  6  begin
  7     for x in c5 loop
  8       dbms_output.put_line(x.mvno||' '||x.mvname||' '||x.releaseyear);
  9     end loop;
 10* end;
SQL> /

Procedure created.

SQL> declare
  2
  3  begin
  4     showma('amitabh');
  5  end;
  6  /
2 DDLJ 1999

PL/SQL procedure successfully completed.


b).write a cursor to display names of all movies which are released in year 2002.
SQL>
  1  declare
  2    cursor c7 is select mvname from movie
  3    where releaseyear=2002;
  4  begin
  5    for x in c7 loop
  6      dbms_output.put_line(x.mvname);
  7    end loop;
  8* end;
SQL> /
dhoom
om kare

PL/SQL procedure successfully completed.

C program to swap the values of two variables by using call by references.

rite a ‘C’ program to swap the values of two variables by using call by references.

#include<stdio.h>
#include<conio.h>
void main()
{
char name[5][10],temp[10];
int i,j;
clrscr();
printf("\nENTER THE 5 NAMES");
for(i=0;i<5;i++)
{
scanf("%s",&name[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(&name[i],&name[j])>0)
{
strcpy(temp,&name[i]);
strcpy(&name[i],&name[j]);
strcpy(&name[j],temp);
}
}
}
printf("\n SORTED NAMES ARE \n");
for(i=0;i<5;i++)
{
printf("%s\n",name[i]);
}
getch();
}

C program to swap the values of two variables by using call by reference using pointer.

Write a ‘C’ program to swap the values of two variables by using call by reference using pointer.

#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a,b;
clrscr();
printf("\nENTER THE VALUE FOR A & B");
scanf("%d%d",&a,&b);
printf("\n\nVALUES BEFORE SWAPPING \n");
printf("%d\t%d",a,b);
swap(&a,&b);
getch();
}
void swap(int *x,int *y)
{
int t;
{
t=*x;
*x=*y;
*y=t;
}
printf("\n\nVALUES AFTER SWAPPING \n");
printf("%d\t%d",*x,*y);
}

C program to write a macro definition

Write a ‘C’ program to write a macro definition for the following.
> To test whether a character is a lower case letter or not.
> To check whether a character is alphabet or not.
> To obtain the largest of two numbers.

#include<stdio.h>
#include<conio.h>
#define LOWER(ch) islower(ch)
#define ALPHA(ch) isalpha(ch)
#define MAX(a,b) a>b?a:b
void main()
{
int n,a,b;
char c;
clrscr();
do
{
printf("\n1.LOWER");
printf("\n2.ALPHABET");
printf("\n3.MAXIMUM");
printf("\n4.EXIT");
printf("\nENTER UR CHOICE");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nENTER THE CHARACTER");
c=getche();
if(LOWER(c))
{
printf("\nCHARACTER IS IN LOWERCASE\n");
}
else
{
printf("\nCHARACTER IS IN UPPERCASE");
}
break;
case 2:
printf("\nENTER THE CHARACTER");
c=getche();
if(ALPHA(c))
{
printf("\nCHARACTER IS ALPHABET");
}
else
{
printf("CHARACTER IS NOT ALPHABET");
}
break;
case 3:
printf("\nENTER THE VALUES FOR A AND B");
scanf("%d%d",&a,&b);
  if(MAX(a,b))
{
printf("A IS MAXIMUM");
}
else
{
printf("B IS MAXIMUM");
}
break;
case 4:
exit(0);
}
}
while(n!=4);
getch();
}

C program to copy the contents of one file into another file.

Write a ‘C’ program to copy the contents of one file into another file.

#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp,*fq;
char ch;
clrscr();
fp=fopen("a.c","r");
fq=fopen("b.c","w");
if(fp==NULL)
{
printf("FILE DOES NOT EXIST");
exit(0);
}
if(fq==NULL)
{
printf("FILE DOES NOT EXIST");
exit(0);
}
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
fputc(ch,fq);
}
fclose(fp);
fclose(fq);
getch();
}

C program to accept a string from user and generate given pattern.

 Write a ‘C’ program to accept a string from user and generate following pattern.
         (e.g. input is string “abcd”)

          a
          ab
          abc
          abcd
          abc
          ab
          a        
-------------------------------------------------------------------------------------------

Solution:-

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,cnt=0;
char name[10];
clrscr();
printf("enter the string");
scanf("%s",&name);
cnt= strlen(name);
        {
  cnt++;
}
printf("\n");
for(i=0;i<=cnt-1;i++)
{
for(j=0;j<=i;j++)
{
printf("%c",name[j]);
}
printf("\n");
}
for(k=i-1;k>=0;k--)
{
for(j=0;j<k;j++)
{
printf("%c",name[j]);
}
printf("\n");
}
getch();
}

C program to convert given decimal number into binary number.

Write a ‘C’ program to convert given decimal number into binary number.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i=0,n,j;
clrscr();
printf("enter the no");
scanf("%d",&n);
while(n>0)
{
a[i]=n%2;
n=n/2;
i++;
}
for(j=i-1;j>=0;j--)
{
printf("%d",a[j]);
}
getch();
}

Program to develop for cost saving in hotel industry

 To develop a program for cost-saving in a hotel, you can consider the following features: Key Features 1. *Room Management*: Optimize room ...