You are on page 1of 49

ACKNOWLEDGEMENT

I feel pleasure in submitting this project work completed by me. In


the forthcoming statement I express my sense of gratitude toMR.
BHOOPENDRA NAVADYA, PGT (COMPUTER SCIRNCE)under
supervision of whom this assignment could be completed. I thank him
for suggesting the topic and extending all the relevant necessities.
I am also grateful toPRINCIPAL SMT. KULDEEP KAUR for showing
his deep concern and interest by providing essential facilities.
In the course of this project I was obliged to my friends & class
fellows who offered me a great helping hand in the completion of this
project. I am also thankful to my parents who encouraged me
throughout the period of completion of this project.

COMPUTER SCIENCE PROJECT FILE

Sandeep Kumar Barik

XII SCI

Sandeep Kumar Barik


XII(SCI)

CERTIFICATE
Certified that the project work has been
completed by SANDEEP KUMAR BARIK of
class XII(sci) under my guidance and
supervision. I feel pleasure to state that
he has shown his full dedication and
sincerity during the period of its
completion.This does not necessarily
endorse or accept every statement made
or opinion expressed or conclusion
drawn, but only signifies the acceptance
of the project for the purpose it is
submitted for.

Sandeep Kumar Barik


XII(SCI)

SMT. KULDEEP KAUR

Mr. B.

Navadya
Principal
Computer Science

PGT,

Kendriya Vidyalaya, SEC-8, RK PURAM

INDEX
S.N
O
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
1
11.
1
12.
1
13.
1
14.
1
15.

NAME OF EXPERIMENT
Program to print the diagonals of a matrix
Program to perform Binary Search
Program to show the concept of Class
Program to show the concept of Structure
Program to show the concept of Constructors and
Destructors
Program to show the concept of Inheritance
Program to show the concept of Insertion Sort in
array
Program to show the concept of File Handling
Program to show the concept of Pointer
Program to show the concept of Pushing in StackArray
Program to show the concept of Popping from a
Linked-Stack
Program to show the concept of Insertion in
Linked Queue
Program to show the concept of Deletion in ArrayQueue
Program to show the concept of Selection Sort in
array
Program to convert Binary number into Decimal

Sandeep Kumar Barik


XII(SCI)

T.SIGN

number
16. Program to convert Decimal number into Binary
number
17. Program to print sum of each column
1
18. Program to print product of each row
1
19. SQL TABLE 1
1
20. SQL TABLE 2
2
21.

1.Program to print the diagonals of a matrix


#include<iostream.h>
#include<conio.h>

//For clrscr() function

void diagonal(int [50][50],int);


void main()
{

clrscr();
int i,j,n,a[50][50];
cout<<"In square matrix no. of Rows = no. of Columns\n";
cout<<"Enter the size of square matrix : Row=Column=";
cin>>n;

Sandeep Kumar Barik


XII(SCI)

cout<<"Enter the elements of matrix:";


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

for(j=0;j<n;j++)
cin>>a[i][j];

}
cout<<"Given matrix:";
for(i=0;i<n;i++)
{

cout<<"\n";
for(j=0;j<n;j++)
cout<<"\t "<<a[i][j];

}
diagonal(a,n);
}
void diagonal(int a[50][50],int m)
{

int i,j;
cout<<"\nDiagonal one:";
for(i=0;i<m;i++)
{

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

if(i==j)
cout<<a[i][j]<<",";

}
}
cout<<"\nDiagonal two:";
Sandeep Kumar Barik
XII(SCI)

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

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

if (i+j==m-1)
cout<<a[i][j]<<",";

}
}
}

Sandeep Kumar Barik


XII(SCI)

1. Program to perform Binary Search


#include<iostream.h>
#include<conio.h>
int Bsearch(int[],int,int);

//Function for Binary Search

int main()
{

clrscr();
int a[50],item,n,index;
cout<<"Enter desired array size: ";
cin>>n;
cout<<"\nEnter array elements\n";
for(int i=0;i<n;i++)
{

cin>>a[i];

}
cout<<"\nEnter element to be searched for..";
cin>>item;
index=Bsearch(a,n,item);
if (index==-1)
cout<<"\nSorry!! Given element could not found.";
else
cout<<"\nElement found at
index:"<<index<<",Position:"<<index+1<<endl;
return 0;
}
Sandeep Kumar Barik
XII(SCI)

int Bsearch(int a[],int size,int item)//func for binary search


{

int beg,last,mid;
beg=0; last=size-1;
while(beg<=last)
{

mid=(beg+last)/2;
if (item==a[mid])
return mid;
else if(item>a[mid])
beg=mid+1;
else
last=mid-1;

}
return -1;
}

Sandeep Kumar Barik


XII(SCI)

2. Program to show the concept of Class


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
const int obj=5;
const int size=3;
class Student{

int rollno;

char name[21];
fl oat marks[size];
fl oat perc;
char grade;
public:
void getval(void)
{

char ch;
cout<<"\nEnter Data";
cout<<"\nRoll No:";
cin>>rollno;
cin.get(ch);
cout<<"\Name:";
cin.getline(name,21);
for(int i=0;i<size;i++)

{
cout<<"\nMarks for
Subject"<<(i+1)<<":";
Sandeep Kumar Barik
XII(SCI)

cin>>marks[i];
}
cout<<"\n";
}
void calculate(void);
void prnresult(void);
};
void Student::calculate(void)
{

fl oat total;
total=marks[0]+marks[1]+marks[2];
perc=total/3;
if(perc<50)

grade='F';

else if(perc<60)

grade='D';

else if(perc<75)

grade='C';

else if(perc<90)

grade='B';

else

grade='A';

}
void Student::prnresult(void)
{

cout<<"\nRoll No:"<<rollno;
cout<<"\nName:";
cout.write(name,21);
cout<<"\nMarks for Subject 1 :"<<marks[0];
cout<<"\nMarks for Subject 2 :"<<marks[1];

Sandeep Kumar Barik


XII(SCI)

cout<<"\nMarks for Subject 3 :"<<marks[2];


cout<<"\nTotal
marks:"<<(marks[0]+marks[1]+marks[2]);
cout<<"\nPercentage marks:"<<setprecision(2)<<perc;
cout<<"\nGrade:"<<grade<<"\n"<<"\n";
}
Student std10[obj];
int main()
{

clrscr(); int i=0;


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

//Read information for students

cout<<"\nStudent"<<(i+1);
std10[i].getval();

}
for(i=0;i<obj;i++)//calculate and print results of students
{

std10[i].calculate();
cout<<"\tResults of student"<<(i+1);
std10[i].prnresult();

}
return 0;
}

Sandeep Kumar Barik


XII(SCI)

3. Program to show the concept of Structure


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct world
{

char country[30];
char capital[30];

};
void main()
{
clrscr();
world w[10];
int i=0,n;
cout<<"Enter no. of records (<=10): ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the country: ";
gets(w[i].country);
cout<<"Enter the capital: ";
gets(w[i].capital);
}
char ch,*cont;
int fl ag;
cout<<"\n\t1.Search for capital\n\t2.List all
Records\n\t3.Exit";
cin>>ch;
do{
if(ch=='1')
{
cout<<"\nEnter the country : ";
gets(cont);
Sandeep Kumar Barik
XII(SCI)

fl ag=0;
for(i=0;i<n;i++)
{

if(strcmp(cont,w[i].country)==0)
{

cout<<"\n capital is: "<<w[i].capital;


fl ag=1;
break;

}
if(fl ag==0)
cout<<"\ncountry not found";
}
if(ch=='2')
{
cout<<"\nCOUNTRY\t\tCAPITAL";
cout<<"\n-------\t\t-------";
for(i=0;i<n;i++)
cout<<"\n"<<(w[i].country)<<"\t\t"<<(w[i].capital);
}
cout<<"\n\t1.Search for capital\n\t2.List all
Records\n\t3.Exit";
cin>>ch;
}while(ch!='3');
}

getch();

4. Program to show the concept of Constructors


and Destructors
#include<iostream.h>
class A {

static int count;

public:
Sandeep Kumar Barik
XII(SCI)

A()
{

count++;
cout<<"Object"<<count<<"being created\n";

}
~A()
{

cout<<"Object"<<count<<"being distroyed\n";
count--;

};
int A::count=0;
int main()
{

void f1();
A ob1,ob2;
f1(); //func. f1 called that creates and destroys an object
{

A ob3; //another object created inside a block

}return 0;
}
void f1(){

A ob4; }

5. Program to show the concept of Inheritance


#include <iostream.h>
#include<stdio.h>
#include<stdlib.h>
const int LEN=25;
class Employee {
Sandeep Kumar Barik
XII(SCI)

private:

char name[LEN];
unsigned long enumb;
public:
void getdata()
{

cout<<"Enter Name:";
gets(name);
cout<<"Enter Employee Number:";
cin>>enumb;

}
void putdata()
{

cout<<"Name:"<<name<<"\t";
cout<<"Emp. Number:"<<enumb<<"\t";
cout<<"Basic Salary:"<<basic;

}
protected:
fl oat basic;
void getbasic()
{

cout<<"Enter Basic:";
cin>>basic;

}
};
class Manager:private Employee
{

private:

Sandeep Kumar Barik


XII(SCI)

char title[LEN];
public:
void getdata()
{

Employee::getdata();
getbasic();
cout<<"Enter Title:";
gets(title);
cout<<"\n";

}
void putdata()
{

Employee::putdata();
cout<<"\tTitle:"<<title<<"\n";

}
};
int main()
{ Manager m1,m2;
cout<<"Manager 1\n";
m1.getdata();
cout<<"Manager 2\n";
m2.getdata();
cout<<"\t\tManager 1 Details\n";
m1.putdata();
cout<<"\t\tManager 2 Details\n";
Sandeep Kumar Barik
XII(SCI)

m2.putdata();
return 0;
}

Sandeep Kumar Barik


XII(SCI)

6.

Program to show the concept of File Handling

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{

clrscr();
int n,j;
fstream ofi le,afi le;
char str[100];
char ch,ch1;
do {

cout<<"\n\t1.Create Text\n\t2.Read from


File\n\t3.create another fi le";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' :
ofi le.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
Sandeep Kumar Barik
XII(SCI)

ofi le<<str;
ofi le.close();
break;
case '2' :
char tmp1;
afi le.open("smp.txt",ios::in);
while(!afi le.eof())
{

afi le.get(tmp1);
if(isalpha(tmp1))
{

if (islower(tmp1))
{

if (tmp1=='a'||tmp1=='e'||tmp1=='i'||tmp1=='o'||
tmp1=='u')
cout << "\n Lower case vowel "<<tmp1;
else
cout<<"\n Lower case consonants "<<tmp1;
}
if (isupper(tmp1))
{
if (tmp1=='A'||tmp1=='E'||tmp1=='I'||tmp1=='O'||
tmp1=='U')
cout << "\n Upper case vowel "<<tmp1
else
cout<<"\n Lower case consonants "<<tmp1;
Sandeep Kumar Barik
XII(SCI)

}}}
afi le.close();
break;
case '3' :

ofi le.open("smp.txt",ios::in);

afi le.open("smp1.txt",ios::out);
char c;
while(ofi le)
{

ofi le.get(c);
c = tolower(c);
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afi le.put(c);

}
ofi le.close();
afi le.close();
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}

7.

Program to show the concept of Insertion Sort in


Array

Sandeep Kumar Barik


XII(SCI)

#include<iostream.h>
#include<conio.h>
#include<limits.h>// For INT_MIN
void InsSort(int [],int); // Function for insertion sort
int main()
{

clrscr();
int a[50],item,n,index;
cout<<"How many elements do you want to create
array with? ";
cin>>n;
cout<<"\nEnter array elements...";
for(int i=1;i<=n;i++)
cin>>a[i];
InsSort(a,n);
cout<<"\n\nThe Sorted array is as shown below...\n";
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;

}
void InsSort(int a[],int size)
//Function to perform{
tmp,j;
// insertion sort
a[0]=INT_MIN;
Sandeep Kumar Barik
XII(SCI)

int

for(int i=1;i<=size;i++)
{

tmp=a[i];
j=i-1;
while(tmp<a[j])
{

a[j+1]=a[j];
j--;

}
a[j+1]=tmp;
cout<<"Array after pass-"<<i<<"-is:";
for(int k=1;k<=size;k++)
cout<<a[k]<<" ";
cout<<endl;
}
}

Sandeep Kumar Barik


XII(SCI)

8. Program to show the concept of Pointer


#include<iostream.h>
void change(int*);
int main()
{

int a[5]={4,5,6,7,8};
change(a);
for(int i=4;i>=0;i--)
cout<<a[i];
cout<<"\n";
return 0;

}
void change(int*b)
{

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

*b=*b+1;
b++;

}
}

9. Program to show the concept of Pushing in


Stack-Array
#include<iostream.h>
Sandeep Kumar Barik
XII(SCI)

#include<stdlib.h>
#include<process.h>

//For exit()

int Push(int [],int&,int);

//prototype

void Display(int [],int);

//prototype

/*Function Push() receives the Stack-array,its top position and


element to be pushed into.*/
const int size=50;
int main()
{

int Stack[size],item,top=-1,res;
char ch='y';
system("cls");
while(ch=='y'|| ch=='Y')
{

cout<<"\nEnter item for insertion:";


cin>>item;
res=Push(Stack,top,item);
if(res==-1)
{

cout<<"Overfl ow!!!Aborting!!\n";
exit(1);

}
cout<<"\nThe Stack now is:\n";
Display(Stack,top);
cout<<"\nWant to insert more elements?(y/n)..";
cin>>ch;
Sandeep Kumar Barik
XII(SCI)

}
return 0;
}
int Push(int Stack[],int &top,int ele)
{

if(top==size-1)
return -1;
else
{

top++;
Stack[top]=ele;

}
return 0;
}
void Display(int Stack[],int top)
{

cout<<Stack[top]<<"<--"<<endl;
for(int i=top-1;i>=0;i--)
cout<<Stack[i]<<endl;

Sandeep Kumar Barik


XII(SCI)

10.

Program to show the concept of Popping


from a Linked-Stack

#include<iostream.h>
#include<stdlib.h>
#include<process.h>
struct Node {

//for exit()

int info;
Node*next;

} *top,*newptr,*save,*ptr;
Node*Create_New_Node(int);

//prototype

void Push(Node*);

//prototype

void Display(Node*);
void Pop();

//prototype
//prototype

int main()
{

top=NULL;
//In the beginning linked stack is
int info; char ch='y'; //empty,thus,pointers are null
while(ch=='y'|| ch=='Y')
{ cout<<"\nEnter information for the new node..";
cin>>info;
newptr=Create_New_Node(info);
if(newptr==NULL)
{

cout<<"\nCannot create new node!!Aborting!!\n";


system ("pause");
exit(1);

Sandeep Kumar Barik


XII(SCI)

}
Push(newptr);
cout<<"\nPress Yto enter new node,N to exit..";
cin>>ch;
}
system("cls");
do
{ cout<<"\nThe stack now is:\n";
Display(top);

system ("pause");

cout<<"Want to pop an element?(y/n).";


cin>>ch;
if(ch=='y'|| ch=='Y')
Pop();
}while(ch=='y'||ch=='Y');
return 0;
}
Node*Create_New_Node(int n)
{
ptr=new Node;
dynamically
ptr->info=n;
ptr->next=NULL;
return ptr;
}
Sandeep Kumar Barik
XII(SCI)

//Function to create
// new node

void Push(Node*np)
{

//Function to push new node in the stack

if(top==NULL)
top=np;
else
{ save=top;
top=np;
np->next=save;
}

}
void Pop()
stack
{

//Function to pop a node from a linked

if(top==NULL)
cout<<"Underfl ow!!\n";
else
{ ptr=top;
top=top->next;
delete ptr;
}

}
void Display(Node*np)
{

//Function to display linked stack

while(np!=NULL)
{ cout<<np->info<<"->";
np=np->next;

Sandeep Kumar Barik


XII(SCI)

}
cout<<"!!\n";
}

Sandeep Kumar Barik


XII(SCI)

11. Program to show the concept of Insertion in


LinkedQueue
#include<iostream.h>
#include<process.h>//for exit()
struct Node {

int info;
Node*next;

} *front,*newptr,*save,*ptr,*rear;
Node*Create_New_Node(int);
void Insert_End(Node*);
void Display(Node*);
int main()
{
front=rear=NULL;
empty

//In the beginning queue is

int info; char ch='y';


while(ch=='y'|| ch=='Y')
{ cout<<"\nEnter information for the new node..";
cin>>info;
newptr=Create_New_Node(info);
if(newptr==NULL)
{

cout<<"\nCannot create new node!!Aborting!!\n";


exit(1);

}
Insert_End(newptr);
Sandeep Kumar Barik
XII(SCI)

cout<<"\nNow the queue(Front.to.Rear) is :\n";


Display(front);
cout<<"\nPress Yto enter new node,N to exit..";
cin>>ch;
}
return 0;
}
Node*Create_New_Node(int n)
{

ptr=new Node;

//Function to create new


// node dynamically

ptr->info=n;
ptr->next=NULL;
return ptr;
}
void Insert_End(Node*np)
{

//Function to insert in queue

if(front==NULL)
front=rear=np;
else
{ rear->next=np;
rear=np;
}

}
void Display(Node*np)
{

while(np!=NULL)

Sandeep Kumar Barik


XII(SCI)

//Function to display queue

{ cout<<np->info<<"->";
np=np->next;
}
cout<<"!!\n";
}

Sandeep Kumar Barik


XII(SCI)

12.

Program to show the concept of Deletion


in Array-Queue

#include<iostream.h>
#include<stdlib.h>
#include<process.h>//For exit()
int Remove(int []);
int Insert(int [],int);
void Display(int [],int,int);

//prototype
//prototype
//prototype

const int size=50;


int Queue[size],front=-1,rear=-1;
int main()
{

int item,res;
char ch='y';
system("cls");
while(ch=='y'|| ch=='Y')
{ cout<<"\nEnter item for insertion:";
cin>>item;
res=Insert(Queue,item);
if(res==-1)
{

cout<<"Overfl ow!!!Aborting!!\n";
exit(1);

}
cout<<"\nNow the Queue(Front.to.Rear) is:\n";
Sandeep Kumar Barik
XII(SCI)

Display(Queue,front,rear);
cout<<"\nWant to insert more elements?(y/n)..";
cin>>ch;
}
cout<<"Now deletion of elements begins..\n";
ch='y';
while(ch=='y'|| ch=='Y')
{ res=Remove(Queue);
if(res==-1)
{

cout<<"Underfl ow!!Aborting!!\n";
exit(1);

}
else
{

cout<<"\nElement deleted is:"<<res<<endl;


cout<<"Now the Queue(Front.to.Rear) is:\n";
Display(Queue,front,rear);

}
cout<<"Want to delete more elements?(y/n).";
cin>>ch;
}
return 0;
}
int Insert(int Queue[],int ele)
Sandeep Kumar Barik
XII(SCI)

//Function to insert element in

if(rear==size-1)

// Queue

return -1;
else if(rear==-1)
{ front=rear=0;
Queue[rear]=ele;
}
else
{ rear++;
Queue[rear]=ele;
}
return 0;
}
int Insert(int Queue[],int ele)
Queue
{

if(rear==size-1)
return -1;
else if(rear==-1)
{ front=rear=0;
Queue[rear]=ele;
}
else
{ rear++;
Queue[rear]=ele;

Sandeep Kumar Barik


XII(SCI)

//Function to insert element in

}
return 0;
}
int Remove(int Queue[])
{

//Function to delete element

int ret;
if(front==-1)
return -1;
else
{ ret=Queue[front];
if(front==rear)
front=rear= -1;
else
front++;
}
return ret;

}
void Display(int Queue[],int front,int rear)
{

if(front== -1)
return;
for(int i=front;i<rear;i++)
cout<<Queue[i]<<"<-\t";
cout<<Queue[rear]<<endl;

}
Sandeep Kumar Barik
XII(SCI)

Sandeep Kumar Barik


XII(SCI)

13.

Program to show the concept of Selection


Sort in
array

#include<iostream.h>
void SelSort(int [],int);

//Function for selection sort

int main()
{

int a[50],item,n,index;
cout<<"How many elements do you want to create array
with? ";
cin>>n;
cout<<"\Enter array elements..";
for(int i=0;i<n;i++)
cin>>a[i];
SelSort(a,n);
cout<<"\n\nThe Sorted array is as shown below..\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;

}
void SelSort(int a[],int size) //Func to perform selection sort
{

int small,pos,tmp;
for(int i=0;i<size;i++)

Sandeep Kumar Barik


XII(SCI)

small=a[i];
pos=i;
for(int j=i+1;j<size;j++)
{

if(a[j]<small)
{

small=a[j];
pos=j;

}
}
tmp=a[i];
a[i]=a[pos];
a[pos]=tmp;
cout<<"\nArray after pass -"<<i+1<<"-is:";
for(j=0;j<size;j++)
cout<<a[j]<<" ";
}
}

Sandeep Kumar Barik


XII(SCI)

14. Program to convert Binary number into Decimal


Number
#include<iostream.h>
#include<stdlib.h>
int main()
{

long int bin_no,dec_no=0,j=1,remain;


cout<<"Enter any binary number:";
cin>>bin_no;
while(bin_no!=0)
{

remain=bin_no%10;
dec_no=dec_no+remain*j;
j=j*2;
bin_no=bin_no/10;

}
cout<<"\nEquivalent decimal value:"<<dec_no;
return 0;
}

Sandeep Kumar Barik


XII(SCI)

15. Program to convert Decimal number into Binary number


#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int main()
{

clrscr();
long int dec_no,remain,quot;
int bin_no[100],i=0;
cout<<"Enter any decimal number:";
cin>>dec_no;
quot=dec_no;
while(quot!=0)
{

bin_no[i]=quot%2;
quot=quot/2;
i++;

}
cout<<"\nEquivalent binary value of "<<dec_no<<" is ";
for(int j=i-1;j>=0;j--)
cout<<bin_no[j];
return 0;
}

16.
Sandeep Kumar Barik
XII(SCI)

Program to print sum of each column

#include<iostream.h>
#include<conio.h>
void colsum(int [50][50],int,int);
void main()
{

clrscr();
int i,j,r,c,a[50][50];
cout<<"Enter the no. of rows of the matrix :";
cin>>r;
cout<<"Enter the no. of columns of the matrix :";
cin>>c;
cout<<"Enter the elements of matrix:";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cin>>a[i][j];
}
cout<<"Given matrix:";
for(i=0;i<r;i++)
{

cout<<"\n";
for(j=0;j<c;j++)
cout<<"\t"<<a[i][j];

}
colsum(a,r,c);
Sandeep Kumar Barik
XII(SCI)

}
void colsum(int a[50][50],int m,int n)
{

int csum[50];
for(int j=0;j<n;j++)
{

csum[j]=0;
for(int i=0;i<m;i++)
csum[j]+=a[i][j];

}
for(j=0;j<n;j++)
cout<<"\nSum of column"<<j+1<<" is
"<<csum[j]<<endl;
}

Sandeep Kumar Barik


XII(SCI)

17.

Program to print product of each row

#include<iostream.h>
#include<conio.h>
void rowproduct(int [50][50],int,int);
void main()
{

clrscr();
int i,j,r,c,a[50][50];
cout<<"Enter the no. of rows of the matrix :";
cin>>r;
cout<<"Enter the no. of columns of the matrix :";
cin>>c;
cout<<"Enter the elements of matrix:";
for(i=0;i<r;i++)
{

for(j=0;j<c;j++)
cin>>a[i][j];

}
cout<<"Given matrix:";
for(i=0;i<r;i++)
{

cout<<"\n";
for(j=0;j<c;j++)
cout<<"\t"<<a[i][j];

}
rowproduct(a,r,c);
Sandeep Kumar Barik
XII(SCI)

}
void rowproduct(int a[50][50],int m,int n)
{

long prod[50];
for(int i=0;i<m;i++)
{

prod[i]=1;
for(int j=0;j<n;j++)
prod[i]*=a[i][j];

}
for(i=0;i<m;i++)
cout<<"\nProduct of row"<<i+1<<" = "<<prod[i]<<endl;
}

Sandeep Kumar Barik


XII(SCI)

1) Consider the following tables EMPLOYEES and


EMPSALARY. Write SQL commands for the statements (i)
to (iv) and give outputs for SQL queries (v) to (viii).
EMPLOYEES
EMPID

010
105
152
215
244
300
335
400
441

FIRST
NAME

George
Mary
Sam
Sarah
Manila
Robert
Henry
Rachel
Peter

LAST
NAME

ADDRESS

CITY

Smith
Jones
Tones
Ackerman
Sengupta
Samuel
Williams
Lee
Thompso
n

83 First Street
842 Vine Ave.
33 Elm St.
440 U.S. 110
24 Friends Street
9 Fifth Cross
12 Moore Street
121 Harrison St.
11 Red Road

Howard
Losantiville
Paris
Upton
New Delhi
Washington
Boston
New York
Paris

EMPSALARY
EMPID

SALARY

BENEFITS

010
105
152
215
244
300
335
400
441

75000
65000
80000
75000
50000
45000
40000
32000
28000

15000
15000
25000
12500
12000
10000
10000
7500
7500

DESIGNATIO
N

Manager
Manager
Director
Manager
Clerk
Clerk
Clerk
Salesman
Salesman

(i) To display First name, Last name, Address and City of all
employees living in Paris from the table EMPLOYEES.
Ans: SELECT FIRST NAME, LAST NAME, ADDRESS, CITY
FROM EMPLOYEES
WHERE CITY=Paris;
(ii) To display the content of EMPLOYEES table in descending
order of FIRSTNAME.
Ans: SELECT *FROM EMPLOYEES
ORDER BY FIRST NAME DESC;
Sandeep Kumar Barik
XII(SCI)

(iii) To display the First name, Last name, and Total Salary of
all Managers from the tables EMPLOYEES and
EMPSALARY, where Total Salary is calculated as Salary +
Benefits.
Ans: SELECT FIRST NAME, LAST NAME, SALARY+BENEFITS
FROM EMPLOYEES, EMPSALARY
WHERE EMPLOYEES.EMPID=EMPSALARY.EMPID AND
DESIGNATION='Manager';
(iv) To display the Maximum salary among Managers and
Clerks from the table EMPSALARY.
Ans: SELECT MAX (SALARY)
FROM EMPSALARY
WHERE DESIGNATION=`Manager` OR DESIGNATION=`Clerks;
(v) SELECT FIRSTNAME, SALARY
FROM EMPLOYEES, EMPSALARY
WHERE DESIGNATION = Salesman AND
EMPLOYEES.EMPID=EMPSALARY.EMPID;
Ans:FIRST NAME SALARY
Rachel
32000
Peter
28000
(vi) SELECT COUNT(DISTINCT DESIGNATION)
FROM EMPSALARY;
Ans:4
(vii)
SELECT DESIGNATION, SUM(SALARY)
FROM EMPSALARY
GROUP BY DESIGNATION HAVING COUNT (*)>2;
Ans:DESIGNATION
SUM (SALARY)
Clerk
135000
Manager
215000
(viii) SELECT SUM (BENEFITS)
FROM EMPSALARY
WHERE DESIGNATION= Clerk;
Ans:SUM (BENEFITS)
32000

Sandeep Kumar Barik


XII(SCI)

2) Consider the following tables ACTIVITY and COACH and


answer (b) and (c) parts of this question:
ACTIVITY
CODE

ACTIVITY
NAME

1001

Relay

1002

STADIUM

PARTICIPA
NTS
NUM

PRIZE
MONE
Y

SCHEDULE
DATE

16

10000

23- Jan-2004

High jump

100x4 Star
Annex
Star Annex

10

12000

12-Dec-2003

1003

Shot Put

Super Power

12

8000

14-Feb-2004

1005

Long Jump

Star Annex

12

9000

01- Jan-2004

1008

Discuss
Throw

Super Power

10

15000

19-Mar-2004

PCOD
E

COACH
NAME

COD
E

Ahmad Hussain

1001

2
3

Ravinder
Janila

1008
1001

4
Naaz
1003 commands for
(b) Write SQL
the flowing statements:
(i) To display the names of all activities with their codes in
descending order.
Ans:SELECT ACTIVITY NAME, CODE
FROM ACTIVITY
ORDER BY CODE DESC;
(ii) To display sum of PrizeMoney for the Activities played in
each of the Stadiumseparately.
Ans: SELECT SUM(PRIZE MONEY), COUNT (STADIUM)
FROM ACTIVITY
GROUP BY STADIUM;
(iii) To display the coach's name and Codes in ascending order
of Code fromthe table COACH.
Ans: SELECT NAME, CODE
FROM COACH
ORDER BY CODE ASC;
Sandeep Kumar Barik
XII(SCI)

(iv) To display the content of the Activity table whose


ScheduleDate earlier than
01/01/2004in ascending order of ParticipantsNum.
Ans: SELECT *FROM ACTIVITY
WHERE SCHEDULE DATE< {01/01/2004}
ORDER BY PARTICIPANTS NUM ASC;
(c) Give the output of the following SQL queries:
(i) SELECT COUNT (DISTINCT PARTICIPANTSNUM) FROM
ACTIVITY;
Ans:1
2
2
(ii) SELECT MAX (ScheduleDate), MIN (ScheduleDate) FROM
ACTIVITY;
Ans: 19-Mar- 200412-Dec-2003
(iii) SELECT ACTIVITYNAME,NAME
FROM ACTIVITY A, COACH C
WHERE A.code=C.code AND A.ParticipantsNum=10;
Ans: Discuss ThrowRavinder
(iv) SELECT DISTINCT code FROM COACH;
Ans: 1001
1008
1003

Sandeep Kumar Barik


XII(SCI)