You are on page 1of 48

COMPUTER

SCIENCE
ASSIGNME
NT
2k16-
2k17
PREPARED BY:
SANDEEP CHANDEL
CLASS:
XII A
BOARD NO. :
9192580
K.V A.A.I
RANGPURI

CERTIFICATE
This is to certify that SANDEEP CHANDEL, a
student of class XII-A has successfully
completed the research on the below
mentioned project under the guidance of Mrs.
Neeraj Yadav ( Subject Teacher ) during the
year 2016-17 in partial fulfillment of Comp.
Sci. practical examination conducted by
AISSCE, New Delhi.

Teachers signature
(MRS.NEERAJ YADAV)
ACKNOWLEDGEME
NT
In the accomplishment of this project
successfully, many people have best
owned upon me their blessings and the
heart pledged support, this time I am
utilizing to thank all the people who
have been concerned with project.
Primarily I would thank god for being
able to complete this project with
success. Then I would like to thank my
principal Mr. P.P Yadav and Comp Sci.
Teacher Mrs.Neeraj Yadav, whose
valuable guidance has been the ones
that helped me patch this project and
make it full proof success his
suggestions and his instructions has
served as the major contributor towards
the completion of the project. Then I
would like to thank my parents and
friends who have helped me with their
valuable suggestions and guidance has
been helpful in various phases of the
completion of the project. Last but not
the least I would like to thank my
classmates who have helped me a lot.

PROGRAMS
# Program using linked
stack to enter the name
of players
#include<iostream.h>

#include<conio.h>

#include<process.h>
#include<string.h>

struct Node

char info[30];

Node *next;

*top,*newptr,*save,*ptr;

Node *create_new_node();

void push(Node*);

void Display(Node*);

void main()

clrscr();

charch='y';

top=NULL;

clrscr();

while(ch=='y'||ch=='y')

cout<<"\n Enter information for the new node:";

newptr=create_new_node();

if(newptr==NULL)

{
cout<<"\n ERROR!!!Aborting";

exit(1);

push(newptr);

cout<<"\n Now the stack is:";

Display(top);

cout<<"Press Y to enter more nodes\n..N to exit";

cin>>ch;

Node *create_new_node()

char a[30];

ptr=new Node;

cin>>a;

strcpy(ptr->info,a);

ptr->next=NULL;

returnptr;

void push(Node *np)

if(top==NULL)
top=np;

else

save=top;

top=np;

np->next=save;

void Display(Node *np)

while(np!=NULL)

cout<<np->info<<"->";

np=np->next;

cout<<"!!!\n";

}
# Program using linked
queue to enter the name
of states.
#include<iostream.h>

#include<conio.h>

#include<process.h>

#include<string.h>

struct Node

{
char info[30];

Node *next;

*front,*newptr,*save,*ptr,*rear;

Node *create_new_node();

voidinsert_end(Node*);

void Display(Node*);

void main()

clrscr();

front=rear=NULL;

charinf[20];

charch='y';

clrscr();

while(ch=='y'||ch=='y')

cout<<"\n Enter information for the new node:";

cin>>inf;

newptr=create_new_node();

if(newptr==NULL)

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

insert_end(newptr);

cout<<"\n Now the Queue is:\n";

Display(front);

cout<<"Press Y to enter more nodes\n..N to exit";

cin>>ch;

Node *create_new_node()

char a[30];

cin>>a;

ptr=new Node;

strcpy(ptr->info,a);

ptr->next-NULL;

returnptr;

voidinsert_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";

}
# program to check whether
a number is angstrom
number or not

#include<iostream.h>

#include<conio.h>

void main()
{

clrscr();

inta,b,c,num=0;

cout<<"\n enter the number:";

cin>>a;

c=a;

while(a!=0)

b=a%10;

a=a/10;

b=b*b*b;

num=num+b;

if(num==c)

cout<<"\n It is an angstrom number";

else

cout<<"It is not an angstrom number";

getch();
}

# Program to
demonstrate
bubble sort
#include<iostream.h>

#include<conio.h>

#include<iomanip.h>

void main()
{

clrscr();

constintarraysize=10;

int Bubble[arraysize];

cout<<"\n Please enetr 10 integers:"<<endl;

for(inti=0;i<arraysize;i++)

cin>>Bubble[i];

cout<<"\n unsorted array:";

for(int j=0;j<arraysize;j++)

cout<<setw(4)<<Bubble[j];

for(int y=0;y<arraysize;y++)

for(int k=0;k<<arraysize-1-y;k++)

if(Bubble[k]>Bubble[k+1])

int temp=Bubble[k+1];

Bubble[k+1]=Bubble[k];

Bubble[k]=temp;

cout<<"\n Sorted Bubble array:";

for(int l=0;l<arraysize;l++)
cout<<setw(4)<<Bubble[l];

cout<<endl;

getch();

#program to demonstrate merging


of two arrays
#include<iostream.h>

#include<conio.h>

#include<iomanip.h>

class number
{

private:

int a[10],b[10],mer[40];

public:

void readnum1();

void readnum2();

void merge();

voidprintnum();

};

void number::readnum1()

for(int j=0;j<10;j++)

cin>>a[j];

void number::readnum2()

for(int j=0;j<10;j++)

cin>>b[j];

void number::merge()

for(int j=0;j<10;j++)
mer[j]=a[j];

for(inti=0;i<10;i++,j++)

mer[j]=b[j];

void number::printnum()

for(int j=0;j<20;j++)

cout<<setw(4)<<mer[j];

void main(void)

clrscr();

numberobj;

cout<<"\n Please enter the numbers:";

obj.readnum1();

cout<<"\n Please enter the numbers";

obj.readnum2();

obj.merge();

cout<<"\n Merge array";

obj.printnum();

cout<<endl;

getch();
}

# Program of sum
of n terms
#include<iostream.h>

#include<conio.h>
#include<math.h>

float SUMFUN(float x,int N)

long float sum=0,sign=+1,term=0;

inti,j;

for(i=1;i<=2*N;i+=2)

term=(sign*pow(x,i))/i;

sign*=-1;

sum+=term;

return sum;

void main()

clrscr();

floatx,result;

int N;

cout<<"\n Enter the value of x:";

cin>>x;

cout<<"\n Enter the number of terms:";

cin>>N;
result=SUMFUN(x,N);

cout<<"\n result="<<result<<endl;

getch();

OUTPUT
# Program to check the
divisibility and check
whether prime or not
#include<iostream.h>

#include<conio.h>

int divide(inta,int b)

if(b==0)

return -1;

if((a%b)==0)

return 1;

else

return 0;

int divide(int a)

int j=a/2,flag=1;

for(inti=2;(i<=j)&&(flag);i++)

if(a%i==0)
flag=0;

return flag;

}void main()

clrscr();

intch,res,a,b;

do

cout<<"1.Check for divisibility \n";

cout<<"2.Check for prime \n";

cout<<"3.Exit \n";

cout<<"Enter your choice: ";

cin>>ch;

cout<<"\n";

switch(ch)

case 1:

cout<<"Enter the numenator and denominator \n";

cin>>a>>b;

cout<<((res)?"Numenator is divisible by
denomenator":"Numenator is not divisible by
denominator")<<"\n\n\n\n\n\n" ;
break;

case 2:

cout<<"Enter the number \n";

cin>>a;

res=0;

res=divide(a);

cout<<((res)?"It is prime":"It is not prime")<<"\n\n\n\n\n\n\n";

break;

case 3:

break;

default:

cout<<"Wrong choice \n";

}while(ch>0 &&ch<3);

getch();

}
# Program to display
information
About employees and
managers
#include<iostream.h>

#include<conio.h>

classticbooth

intno_people;

float amount;

public:
void initial();

voidnotsold();

void sold();

voiddisp_totals();

voiddisp_tickets();

};

voidticbooth::initial()

no_people=0;

amount=0.0;

voidticbooth::notsold()

no_people++;

voidticbooth::sold()

no_people++;

amount+=2.50;

voidticbooth::disp_totals()

{
cout<<no_people<<"people visited"<<endl;

voidticbooth::disp_tickets()

int ticket=int(amount/2.50);

cout<<ticket<<"ticket sold"<<endl;

void main()

clrscr();

ticbooth stall1;

stall1.initial();

intch;

do

cout<<"choose one option"<<endl;

cout<<"1. The visitor has only signed the visitor book."<<endl;

cout<<"2. The visitor has purchased the ticket also."<<endl;

cout<<"3. Exit"<<endl;

cout<<"Enter the choice(1-3)"<<endl;

cin>>ch;

switch(ch)
{

case 1: stall1.notsold();

break;

case 2: stall1.sold();

break;

case 3: break;

default: cout<<" Wrong choice!!";

};

}while(ch!=3);

stall1.disp_totals();

stall1.disp_tickets();

getch();

}
# Program to count no of
digits
#include<iostream.h>

#include<conio.h>

#include<fstream.h>

void main()

clrscr();

ofstream f;

f.open("PARA.TXT");

chararr[100];

cout<<"\n please input a line:";

cin.getline(arr,100);

f<<arr;

f.close();

inti,count=0;

ifstream f1;

f1.open("PARA.TXT");

charch;

while(f1.eof()==0)
{

f1.get(ch);

i=ch;

cout<<ch;

if(((i>=48)&&(i>0))&&((i>0)&&(i<=57)))

count++;

cout<<"\n No. of digits:"<<count;

getch();

}
BOOLEAN ALGEBRA
Q.1) An arrayArr[50][10] is stored in the memory along
the row with each element occupying 2 bytes. Find out
the address of the location Arr[20][50] if the location
Arr[10][25] is stored at the address 10000.
ANSWER:

Arr[50][10]

No. of Rows(R)=50

No. of Columns(C)=10

Element size = 2 bytes

Arr[I][J]=Arr[20][50]

I=20,J=50

Address of Arr[10][25] = 10000

Base Address (B) =?

Lowest Row (Ir) =0

Lowest Column(Ic) =0

Formula to calculate address in Row Major arrangement is :

Arr [P] [Q] = B + W[C (P-Ir) + (Q-Ic)]

Arr [10] [25] = B + 2[10(10-0) + (25-0)]

10000 = B + 2[100 + 25]

10000 = B + 250
B = 10000-2520 =

B = 9750

Parallely,

Arr [I][J] = B + W[C(I-Ir) + (J-Ic) ]

i.e.

Arr [20][50] = 9750 + 2[10(20-0) + (50-0) ]

Arr [20][50] = 10250

Thus, the address of Arr [20] [50] is 10250.

Q 2) an array Arr [5] [5] is store in the memory with each


element occupying 4 bytes of space. Assuming the base
address to be 100. Compute of Arr [2] [4], when the array
is stored in
a) Row wise
b) Column wise
ANSWER:

a) Row wise

Given, Arr[5][5]

No. of Rows(R) = 5

No. of Column(C) =5

Element Size (W) = 4 bytes


Base address (B) = 1000

Lowest Row (Ir) = 0

Lowest Column (Ic) = 0

Formula to calculate address in Row major arrangement is:

Arr[P][Q] = B+W [ C(P-Ir) + (Q-Ic)]

i.e., Address for Arr[2][4] is,

Arr[2][4] = 1000 + 4[ 5(2-0) + (4-0) ]

= 1000 + 4(10+4)

= 1000 + 56

= 1056

So,

The address of Arr[2][4] is 1056 (Row wise).

b) Column wise:

Given,

Given, Arr[5][5]

No. of Rows(R) = 5

No. of Column(C) =5

Element Size (W) = 4 bytes

Base address (B) = 1000

Lowest Row (Ir) = 0


Lowest Column (Ic) = 0

Formula to calculate address in Column major arrangement is :

Arr[P][Q] = B+W [ (P-Ir) + R(Q-Ic)]

i.e., Address for Arr[2][4] is,

Arr[2][4] = 1000 + 4[ (2-0) + 5(4-0) ]

= 1000 + 4(2+20)

= 1000 + 88

= 1088.

So,

The Address of Arr[2][4] is 1088 (column wise)


SQL
Given the following relation:
RELATION: student

Write SQL commands for (a) to (f) and give


the output for (g)
a.To show all information about the students of history
department

SELECT * FROM student WHERE DEPARTMENT=history;

b.to list the names of female students who are in hindi


department

SELECT NAME FROM student WHERE GENDER=F AND


DEPARTMENT=hindi;

c.to list the names of all students with date of admission


in ascending order
SELECT NAME FROM STUDENT ORDER BY D_O_A;

d.to display students name, fee, age, for male only

SELECT NAME,FEE,AGE FROM student WHERE GENDER=M;

e.to count the number of students with age<23

SELECT COUNT(*) FROM student WHERE AGE>23;

f.to insert a new row in student table with the following


data

9,Zaheer,36,Computer,12/03/97,230,M.

insert into student

values(9,Zaheer,36,Computer,12/03/97,230,M)

g.give the outputs of the following statements:

1.SELECT COUNT(DISTINCT DEPARTMENT) FROM student;

2. select MAX (AGE) from student where GENDER=F;


3.SELECT AVG(FEE) FROM student where D_O_A<01/01/98;

4.SELECT SUM(FEE) FROM student where D_O_A<01/01/98;

Write the SQL commands for (a) to (d) and


write the output for (e) on the basis of table
RELATION: hospital
a.to show all information about the patients of the
cardiology department

SELECT * FROM hospital WHERE DEPARTMENT=orthopedic;

b.to list the name of female patients who are in ENT


department.

SELECT NAME FROM hospital WHERE GENDER=F and


DEPARTMENT=ENT;

c.to list names of all patients with their date of admission


in ascending order.

SELECT NAME FROM hospital ORDER BY D_O_A;

d. to count the no of patients with age>20

SELECT COUNT(*) FROM hospital WHERE AGE>20;

e.

1. select COUNT(DISTINCT CHARGE) FROM hospital;

2.select MIN(AGE) FROM hospital where GENDER=M;


3.select SUM(CHARGE) FROM hospital where GENDER=F;

Write the SQL commands for (a) to (f) and


write the output for (g) to (i) on the basis of
tables
RELATION: books

RELATION: issued
a. To show book name,authorname and price of books of
first publ,publishers.

SELECT BOOK_NAME,AUTHOR_NAME,PRICE FROM books WHERE


PUBLISHER=First publ;

b. To list the names from books of the text type

SELECT BOOK_NAMEFROM books WHERE TYPE=Text;

c. To display the book_id,book_name and quantity_issued


for all books whichhave been issued.

SELECT BOOK_NAME,PRICE FROM books ORDER BY PRICE;

d. To increase the price of all books of EPB publishers by


50.

UPDATE books

SET PRICE=PRICE+50

WHERE PUBLISHER=EPB;

e. To insert a new row in the table issued having the


following data:F0003,1

INSERT INTO issued

values(F0003,1);

f. Select count(*) from books;


g. Select BOOK_NAME,AUTHOR_NAME from books where
PUBLISHER=EPB;

h. SELECT COUNT(DISTINCT PUBLISHER) FROM books where


PRICE>=400;

i.select MAX(PRICE) FROM books WHERE QUANTITY>=15;


Write the SQL commands for (a) to (e) and
write the output for (f) to (j) on the basis of
tables
RELATION: furniture

a. to show all information about the baby cot from the


furniture table.

SELECT* FROM furniture WHERE TYPE=baby cot;

b. to list the item name which are priced at more than


15000 from thefurniture table.

SELECT ITEM FROM furniture WHERE PRICE>15000;

c. to list item name and type of those items in which


date of stock is before2/01/02 from the furniture
table in decreasing order of item name.

SELECT ITEM, TYPE FROM furniture

WHERE DATE_OF_STOCK<22/01/02 ORDER BY ITEM;


d.to display item name and date of stock of those items
in which the discountpercentage is more than 25 from
the furniture table.

SELECT ITEM,DATE_OF_STOCK FROM furniture

WHERE DISCOUNT>25;

e.to count the no of items whose type is sofa from


furniture table.

SELECT COUNT(*) FROM furniture WHERE TYPE=Sofa;

f.SELECT COUNT(DISTINCT TYPE) FROM furniture;

g. select MAX(DISCOUNT) from furniture;

h. select AVG (DISCOUNT) from furniture where TYPE=Baby cot;


i.select SUM(PRICE) from furniture where
DATE_OF_STOCK<12/02/02;

Thank you.

You might also like