0% found this document useful (0 votes)
2K views6 pages

Class 12 Computer Science Practical Guide

The document describes four programming experiments from a computer science practical examination question paper. The first experiment involves writing a program to swap two numbers using call by value and call by reference. The second experiment involves performing a linear search on an array. The third experiment performs a binary search on a sorted array. The fourth experiment sorts an array using bubble sort. Each experiment provides sample code and output.

Uploaded by

Namdev Shelar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views6 pages

Class 12 Computer Science Practical Guide

The document describes four programming experiments from a computer science practical examination question paper. The first experiment involves writing a program to swap two numbers using call by value and call by reference. The second experiment involves performing a linear search on an array. The third experiment performs a binary search on a sorted array. The fourth experiment sorts an array using bubble sort. Each experiment provides sample code and output.

Uploaded by

Namdev Shelar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Experiment #1
  • Experiment #2
  • Experiment #3
  • Experiment #4
  • Experiment #5

Experiment #1

Maharashtra State Board of Secondary & Higher Secondary Education, Pune


XII Standard Computer Science (D93) Paper-1
HSC Board Practical Examination Question Paper
Time: 3 Hours Max. Marks: 30
-----------------------------------------------------------------------------------------------------------------------------------------------------
1) Write a program in C++ that exchange data (Call by Value) using SWAP function i.e. void swap (int, int)
to interchange the given two numbers. (15)
2) Enter the program and verify proper execution of the same on the computer. (10)
3) Obtain a hardcopy of the program listing as well as output. The output must list the given numbers before
as well as after swapping. (5)

/* Program to Demonstrate call by value */

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

void main ()
{
clrscr();
int a,b;
void swap(int,int);
cout<<"enter the value of two numbers:";
cin>>a>>b;

cout<<"before swapping A="<<a<<"b="<<b<<endl;


swap( a, b);
cout<<"after swapping A="<<a<<"b="<<b<<endl;
getch();
}

void swap(int x,int y)


{
int temp;
temp=x;
x=y;
y=temp;
}

enter the value of two numbers:55


66
before swapping A=55b=66
after swapping A=55 b=66

Vidyasagar Academy, Akola | [Link]


Experiment #2

Maharashtra State Board of Secondary & Higher Secondary Education, Pune


XII Standard Computer Science (D93) Paper-1
HSC Board Practical Examination Question Paper
Time: 3 Hours Max. Marks: 30
-----------------------------------------------------------------------------------------------------------------------------------------------------
4) Write a program in C++ that exchange data (Call by Reference) using SWAP function that is void swap
(int*, int*) to interchange the given two numbers. (15)
5) Enter the program and verify proper execution of the same on the computer. (10)
6) Obtain a hardcopy of the program listing as well as output. The output must list the given numbers before
as well as after swapping. (5)

/* Program to Demonstrate call by reference */

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

void main ()
{
clrscr();
int a,b;
void swap(int*x,int*y);
cout<<"enter the value of two numbers:";
cin>>a>>b;

cout<<"before A="<<a<<"b="<<b<<endl;
swap(& a,& b);
cout<<"after A="<<a<<"b="<<b<<endl;
getch();
}

void swap(int*x,int*y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

enter the value of two numbers:55


66
before A=55 b=66
after A=66 b=55

Vidyasagar Academy, Akola | [Link]


Experiment #3

Maharashtra State Board of Secondary & Higher Secondary Education, Pune


XII Standard Computer Science (D93) Paper-1
HSC Board Practical Examination Question Paper
Time: 3 Hours Max. Marks: 30
-----------------------------------------------------------------------------------------------------------------------------------------------------
1) Write a program in C++, that first initializes an array of given 10 integer numbers. The program must
verify whether a given element belongs to this array or not, using LINEAR SEARCH technique. The
element (to be search) is to be entered at the time of execution. If the number is found, the program should
print: “The Number is Found” otherwise, it should print: “The number is not Found”. (15)
2) Enter the program and verify proper execution of the same on the computer. (10)
3) Obtain a hardcopy of the program listing as well as output. (5)

/* LINEAR SEARCH */

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

void main ()
{
clrscr();
int num[10],n;
cout<<"enter the 10 numbers for the array."<<endl;
for(int i=0;i<10;i++)
cin>>num[i];
cout<<"enter the number for linear search:";
cin>>n;

for(i=0;i<=10;i++)
{
if(num[i]==n)
{
cout<<"the number is present search successful at position"<<i+1<<endl;
break;
}
}

if (i==10)
{
cout<<"the number is absent search unsuccessful"<<endl;
getch();
}

Enter the 10 numbers for the array


1
2
3
4
5
6
78
8
9
10
enter the number for linear search:78
the number is present search successful at position 7

Vidyasagar Academy, Akola | [Link]


Experiment #4

Maharashtra State Board of Secondary & Higher Secondary Education, Pune


XII Standard Computer Science (D93) Paper-1
HSC Board Practical Examination Question Paper
Time: 3 Hours Max. Marks: 30
-----------------------------------------------------------------------------------------------------------------------------------------------------
4) Write a program in C++, that first initializes an array of given 10 sorted integer numbers. The program
must verify whether a given element belongs this array or not, using BINARY SEARCH technique. The
element (to be search) is to be entered at the time of execution. If the number is found, the program should
print” The Number is Found” otherwise it should print “The number is not Found”. (15)
5) Enter the program and verify proper execution of the same on the computer. (10)
6) Obtain a hardcopy of the program listing as well as output. (5)

/ * Binary search */

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

void main()
{
clrscr();
int a[10],n,i,x,beg,end,mid;
cout<<"enter number of array elements"<<endl;
cin>>n;
beg=0;
end=n-1;
mid=(beg+end)/2;
cout<<"enter the elements"<<endl;

for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter element to be search";
cin>>x;

while(a[mid]!=x&&beg<=end)
{
if(a[mid]>x)
end=mid-1;

beg=mid+1;
mid=(beg+end)/2;
}
if(a[mid]==x)
cout<<"element is present at position"<<mid+1;
else
cout<<"search unsuccessfull";
getch();
}

enter number of array elements


5
enter the elements
10 20 30 40 50
enter element to be search 30
element is present at position 3

Vidyasagar Academy, Akola | [Link]


Experiment #5

Maharashtra State Board of Secondary & Higher Secondary Education, Pune


XII Standard Computer Science (D93) Paper-1
HSC Board Practical Examination Question Paper
Time: 3 Hours Max. Marks: 30
-----------------------------------------------------------------------------------------------------------------------------------------------------
7) Write a program in C++, that first initializes an array of given 10 integer numbers. The program must sort
numbers in Ascending/Descending order using BUBBLE SORT method. It should print the given list of
numbers as well as the sorted list. (15)
8) Enter the program and verify proper execution of the same on the computer. (10)
9) Obtain a hardcopy of the program listing as well as output. (5)

/* Bubble sort */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,t,sort[10];
cout<<"enter the array element";
for(i=0; i<10;i++)
{
cin>>sort[i];
}
for(i=0;i<10;i++)
{
for(j=10;j>0;j--)
{
if(sort[j-1]>sort[j])
{
t=sort[j-1];
sort[j-1]=sort[j];
sort[j]=t;
}
}
}
cout<<"sorted array is-"<<endl;
for(i=0;i<10;i++)
{
cout<<sort[i]<<endl;
}
getch();
}

enter the array element10


2 5 3 8 25 14 57 25 147 10
sorted array is-
2
3
5
8
10
14
25
25
57
147

Vidyasagar Academy, Akola | [Link]


Vidyasagar Academy, Akola | [Link]

Vidyasagar Academy, Akola | www.vsagar.org  
Experiment #1 
 
 
 
 
 
 
 
 
 
 
 
/* Program to Demonstrate call by v
Vidyasagar Academy, Akola | www.vsagar.org  
Experiment #2 
 
 
 
 
 
 
 
 
 
 
 
/* Program to Demonstrate call by r
Vidyasagar Academy, Akola | www.vsagar.org  
Experiment #3 
 
 
 
 
 
 
 
 
 
 
/* LINEAR SEARCH */ 
 
#include<iostr
Vidyasagar Academy, Akola | www.vsagar.org  
Experiment #4 
 
 
 
 
 
 
 
 
 
 
/ * Binary search */ 
 
#include<iost
Vidyasagar Academy, Akola | www.vsagar.org  
Experiment #5 
 
 
 
 
 
 
 
 
 
/* Bubble sort */ 
#include<iostream.h>
 
      Vidyasagar Academy, Akola | www.vsagar.org

You might also like