Upload
akshanshyo
View
227
Download
0
Embed Size (px)
Citation preview
8/13/2019 computer science practical class 12
1/56
PROGRAM FOR BINARY SEARCH
#include
#include
#include
void main(){ clrscr();
int A[50], n,p;
coutn;
cout
8/13/2019 computer science practical class 12
2/56
else
L=mid+1;
}//end of while loop
if(L>U)
{cout
8/13/2019 computer science practical class 12
3/56
getch();
}
void linear_search(int A[], int n, int p)
{ int count=0; int B[50]; int flag=0;
for(int i=0; i
8/13/2019 computer science practical class 12
4/56
cin>>enumb;
}
employee()
{delay(1000);cout
8/13/2019 computer science practical class 12
5/56
cout
8/13/2019 computer science practical class 12
6/56
void enter()
{ coutrollno;
coutTmarks;
}
void display()
{ cout
8/13/2019 computer science practical class 12
7/56
{
if(a[i]==' ')
while(a[i]==' ')
{
i++;
}
if(isalnum(a[i]))
{
while(a[i]!=' ')
{
i++;
}
words++;
}
}
string
8/13/2019 computer science practical class 12
8/56
for(i=0; i
8/13/2019 computer science practical class 12
9/56
getch();
}
PROGRAM FOR BUBBLE SORT
#include#include
void main()
{clrscr();
int A[80],n;
coutn;
cout
8/13/2019 computer science practical class 12
10/56
PROGRAM FOR SELECTION SORT
#include
#include
void main()
{clrscr();
int A[80],n;
lb: coutn;
if(n80)
{cout
8/13/2019 computer science practical class 12
11/56
}
}
PROGRAM FOR BASIC OPERATIONS IN 1D ARRAY
#include
#include
#include#include
/*--------------------------------------------------------------Function declaration ---------------------------------------------
----------*/
int linear_search(int A[ ],int n, int p);
void binary_search(int A[ ],int n, int p);
void selection_sort(int A[ ],int n);
void bubble_sort(int A[ ],int n);
void insertion_sort(int A[ ], int n);
void merge(int low,int mid,int high);
void merge_sort(int low,int high);
void merging(int A[],int B[], int n, int m, char c);
void insert_element(int A[], int n);
void delete_element(int A[], int n);
int A[50],n,mg=0; // global variable
/*--------------------------------------------------------------- Main's body -------------------------------------------------------
---------------*/
void main()
{clrscr();
int ch,o=0,h=0,t=0,k,m;
int B[50],p,subscript;
char choice;
coutn;
cout
8/13/2019 computer science practical class 12
12/56
for(i=0; i
8/13/2019 computer science practical class 12
13/56
cout
8/13/2019 computer science practical class 12
14/56
8/13/2019 computer science practical class 12
15/56
case 6: exit(0); break;
default : cout
8/13/2019 computer science practical class 12
16/56
else
exit(1);
}
}
void selection_sort(int A[], int n)
{int small; int k,count=0;
for(int i=0; i
8/13/2019 computer science practical class 12
17/56
void insertion_sort(int A[], int n)
{int j,t;
A[n]=0;
for(int i=n; i>=0; i--) //shifting each element to its succesive position
A[i]=A[i-1];
A[0]=INT_MIN; // INT_MIN= -32768
for(i=1; i
8/13/2019 computer science practical class 12
18/56
if(A[h]mid)
{
for(k=j;k
8/13/2019 computer science practical class 12
19/56
{ case 'a' : cout
8/13/2019 computer science practical class 12
20/56
cin>>pos;
if(pos-1>n-1)
{
cout
8/13/2019 computer science practical class 12
21/56
void subtract(int a[80][80],int b[80][80]);
void multiply(int a[80][80],int b[80][80]);
void multiply1(int b[80][80],int a[80][80]);
void equivalency ( int a[80][80],int b[80][80]);
void upper_tri(int a[80][80]);
void lower_tri(int a[80][80]);
void diagonal_1_a(int a[80][80]);
void row_sum_a(int a[80][80]);
void column_sum_a(int a[80][80]);
void main() // main body
{clrscr();
int ch,op; char choice;
l: cout
8/13/2019 computer science practical class 12
22/56
for(i=0; i
8/13/2019 computer science practical class 12
23/56
case 2 : subtract(b,a);break;
default: cout
8/13/2019 computer science practical class 12
24/56
cout
8/13/2019 computer science practical class 12
25/56
case 1 : cout
8/13/2019 computer science practical class 12
26/56
//----------------------------------------------------------- Function Definitions -------------------------------------------------
--------
void add(int a[80][80],int b[80][80])
{
int c[80][80];
for(i=0; i
8/13/2019 computer science practical class 12
27/56
void multiply(int a[80][80],int b[80][80])
{
int c[80][80];
j=0;
int k=0;
cout
8/13/2019 computer science practical class 12
28/56
}
void equivalency ( int a[80][80],int b[80][80])
{int count=0;
for(i=0; i
8/13/2019 computer science practical class 12
29/56
for(i=0; i
8/13/2019 computer science practical class 12
30/56
{
v=m;
u=m;
}
else
{
v=p;
u=q;
}
for(i=0; i
8/13/2019 computer science practical class 12
31/56
class bank { char name[80];
int acc_no;
enum acctype{S,C};
void account_type(int n);
float balance;
public:
float add_bal(float n);
float withdrawl (float k);
void initial();
void display();
}acc;
float bank:: add_bal(float n)
{
cout
8/13/2019 computer science practical class 12
32/56
cout
8/13/2019 computer science practical class 12
33/56
case 4: for(int i=0; i
8/13/2019 computer science practical class 12
34/56
{
cout
8/13/2019 computer science practical class 12
35/56
PROGRAM TO DEFINE THE CLASSES PERSON, GAME AND STUDENT & TO ACCESS THE ESSENTIAL DATA
USING MULTIPLE INHERITANCES.
#include
#include
#include
class person{ char name[21];
int age;
public:
void indata()
{cout
8/13/2019 computer science practical class 12
36/56
8/13/2019 computer science practical class 12
37/56
int push(int[],int&,int);
void display(int[],int);
const int size=50;
void main()
{
clrscr();
char m,ch;
int k,stack[size],item,top=-1,res;
do
{ cout
8/13/2019 computer science practical class 12
38/56
}
break;
case 2: ch='y';
while(ch=='y'||ch=='Y')
{ res=pop(stack,top);
if(res==-1)
{
cout
8/13/2019 computer science practical class 12
39/56
cin>>m;
}while(m=='y'||m=='Y'); // end of do-while loop
getch();
} // end of main()
int push(int stack[],int &top,int el)
{
if(top==size-1)
return -1;
else
{top++;
stack[top]=el;
return 0;
}
}
int pop(int stack[],int &top)
{
int ret;
if(top==-1)
return -1;
else
{
ret=stack[top];
top--;
return ret;
}
}
void display(int stack[],int top)
8/13/2019 computer science practical class 12
40/56
{
cout
8/13/2019 computer science practical class 12
41/56
return r;
}
void display(int q[],int front,int rear)
{
if(front==-1)
return;
else
{
for(int i=front;i
8/13/2019 computer science practical class 12
42/56
case 2: ans='y';
while(ans=='y'||ans=='Y')
{
u=delet(q);
if(u==-1)
{
cout
8/13/2019 computer science practical class 12
43/56
char event[20];
char participants[10][30];
int no_of_participants;
} s[20], s2[20];
void copy(fstream &ob);
int i=0;
void main()
{
clrscr();char choice;
fstream ob("sports.dat",ios::binary|ios::in|ios::out);
do
{
if(i>0)
cin.get();
cout
8/13/2019 computer science practical class 12
44/56
coutchoice;
i++;
} while(choice=='y'||choice=='Y');
cout
8/13/2019 computer science practical class 12
45/56
{
file.write((char*)&s[c], sizeof(sports));
n=1;
break;
}
c++;
}
if(n==0)
{
cout
8/13/2019 computer science practical class 12
46/56
8/13/2019 computer science practical class 12
47/56
cout
8/13/2019 computer science practical class 12
48/56
second=third;
++i;
fibonacci(n);
}
return sum;
}
PROGRAM FOR DELETION IN LINKED LIST
#include
#include
#include
#include
#include
struct node
{ int roll;
char name[20];
node *next;
};
class queue
{ node *rear,*front;
public:queue()
{ front=NULL;
rear=NULL;
}
void insertion();
void deletion();
void display();
};
void queue::insertion()
{ node *temp;
temp= new node;
cout
8/13/2019 computer science practical class 12
49/56
if(front==NULL)
{ front=temp;
rear=temp;
}
else
{ rear->next=temp;rear=temp;
}
}
void queue::deletion()
{ node *temp;
if(front==NULL)
{ cout
8/13/2019 computer science practical class 12
50/56
cout
8/13/2019 computer science practical class 12
51/56
};
void queue::insertion()
{ node *temp;
temp= new node;
coutnext=temp;
rear=temp;
}
}
void queue::display()
{ node *temp;
if(front==NULL)
{ cout
8/13/2019 computer science practical class 12
52/56
queue q;
a:cout
8/13/2019 computer science practical class 12
53/56
1 Nabi Ahmed 101
2 Ravi Sahini 108
3 Jatin 101
4 Nazneen 103
(1)To display the names of all games with their GCODE.(2)To display details of those games which are having price money more than 7000.(3)To display the content of GAMES table in ascending order of scheduled date.(4)To display sum of price money for each type of games.Give the output of the following SQL queries.
(5) Select count(distinct number) from GAMES;
(6) Select max (scheduled date) ,min (scheduled date) from GAMES;
(7)Select GNAME from GAMES and names from PLAYERS where GCODE=PCODE andPRICE> 10000;
(1)Selectgname,gcode from games;GCODE GNAME
101 Carom board
102 Badminton
103 Table tennis
105 Chess
108 Lawn tennis
(2)Select * fromgames where price>7000;GCODE GNAME TYPE NUMBER PRICE SCHEDULED
DATE
102 Badminton Outdoor 2 12000 12-12-2003
103 Table tennis Indoor 4 8000 24-2-2002
105 Chess Indoor 2 9000 1-1-2004
108 Lawn tennis Outdoor 4 25000 19-3-2004
(3)Select * fromgamesorder byscheduled date;
GCODE GNAME TYPE NUMBER PRICE SCHEDULED
DATE
8/13/2019 computer science practical class 12
54/56
8/13/2019 computer science practical class 12
55/56
8/13/2019 computer science practical class 12
56/56