Professional Documents
Culture Documents
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.
Mr. B.
Navadya
Principal
Computer Science
PGT,
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
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.
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;
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]<<",";
}
}
}
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 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;
}
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];
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;
}
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)
{
}
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();
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
{
}return 0;
}
void f1(){
A ob4; }
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:
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;
}
6.
#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 {
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.
#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;
}
}
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++;
}
}
#include<stdlib.h>
#include<process.h>
//For exit()
//prototype
//prototype
int Stack[size],item,top=-1,res;
char ch='y';
system("cls");
while(ch=='y'|| ch=='Y')
{
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;
10.
#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)
{
}
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");
//Function to create
// new node
void Push(Node*np)
{
if(top==NULL)
top=np;
else
{ save=top;
top=np;
np->next=save;
}
}
void Pop()
stack
{
if(top==NULL)
cout<<"Underfl ow!!\n";
else
{ ptr=top;
top=top->next;
delete ptr;
}
}
void Display(Node*np)
{
while(np!=NULL)
{ cout<<np->info<<"->";
np=np->next;
}
cout<<"!!\n";
}
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
}
Insert_End(newptr);
Sandeep Kumar Barik
XII(SCI)
ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void Insert_End(Node*np)
{
if(front==NULL)
front=rear=np;
else
{ rear->next=np;
rear=np;
}
}
void Display(Node*np)
{
while(np!=NULL)
{ cout<<np->info<<"->";
np=np->next;
}
cout<<"!!\n";
}
12.
#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
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<<"Want to delete more elements?(y/n).";
cin>>ch;
}
return 0;
}
int Insert(int Queue[],int ele)
Sandeep Kumar Barik
XII(SCI)
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;
}
return 0;
}
int Remove(int Queue[])
{
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)
13.
#include<iostream.h>
void SelSort(int [],int);
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++)
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]<<" ";
}
}
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;
}
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)
#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;
}
17.
#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;
}
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
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)