Professional Documents
Culture Documents
INDEX
Q. No. QUESTIONS
1. BUBBLE SORTING
2. SELECTION SORTING
3. LINEAR SEARCH
4. BINARY SEARCH
5. SUM OF MATRICES
6. MARKSHEET
7. MAX,MIN,SUM,AVG
8. PUSH OPERATION
9. POP OPERATION
Q. No. QUESTIONS
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[20],i,n,j,t=0;
cout<<"n=";
cin>>n;
cout<<"Enter the array";
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{ for(j=0;j<n-1;j++)
{ if(a[j]<a[j+1])
{ t=a[j];
a[j]=a[j+1];
a[j+1]=t; }
}
}cout<<”Sorted Array”;
for(i=0;i<=n-1;i++)
cout<<a[i]<<"\t";
getch();
}
OUTPUT:
N= 5
Enter the Array 2 5 4 3 1
Sorted Array 1 2 3 4 5
Q-2)WRITE A PROGRAM TO INPUT AN ARRAY OF INTEGER AND ARRANGE THEM IN
THERE ASCENDING USING SEL SORT
#include<iostream.h>
#include<conio.h>
void ss(int [],int);
void main()
{clrscr();
int a[50],item,n,p;
cout<<"Enter n ="; cin>>n;
cout<<"Enter the array";
for(int i=0;i<n;i++)
cin>>a[i];
ss(a,n);
cout<<"Sorted array\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
getch();}
void student::calcgrade()
{ int i;
total=average=grade=0;
for(i=0;i<5;i++)
total+=marks[i];
average=total/5;
if(average>=75)
grade='A';
else if(average>=60)
grade='B';
else if(average>=40)
grade='C';
else
grade='F';}
void student::dispdata()
{ int i;
cout<<"\n\nThe roll no.="<<rollno<<"\nName= ";
puts(name);
cout<<"Marks in 5 subjects= ";
for(i=0;i<5;i++)
cout<<marks[i]<<" ";
cout<<"\nTotal="<<total<<"\nAverage= "<<average;
cout<<"\nGrade= "<<(char)grade; }
void main()
{ int p;
clrscr();
student s[10];
for(p=0;p<10;p++)
{ s[p].input();
s[p].calcgrade();
s[p].dispdata(); }
getch();
}
OUTPUT :
Enter the roll no., name and marks in 5 subjects respectively= 15
Paramjot
90 90 90 90 90
The roll no.=15
Name= Paramjot
Marks= 90 90 90 90 90
Total= 450
Average= 90
Grade= A
Q-7) WRITE A PROGRAM TO CREATE & DISPLAY MAX, MIN, SUM &AVG. OF ARRAY
FOR 10 OBJECTS OF STUDENTS.
#include<iostream.h>
#include<conio.h>
struct NUMBER
{ float arr[10],max,min,sum,avg;};
void main()
{ clrscr();
int max,min,sum,avg;
NUMBER n[10];
for(int i=0;i<10;i++)
{ cout<<”Enter the ARRAY elements=”
for(int j=0;j<10;j++)
cin>>n[i].arr[j];
for(int x=0;x<10;x++)
{ max=min=avg=sum=0;
max=min=n[i].arr[0];
if(n[i].arr[x]>max)
max=n[i].arr[x];
if(n[i].arr[x]<min)
min=n[i].arr[x];
sum+=n[i].arr[x];
avg=sum/10;
}
cout<<” Maximum, Minimum, Sum & Average is=”;
cout<<max<<” “<<min<<” “<<sum<<” “<<avg;
} getch(); }
OUTPUT: Enter array elements= 2 3 1 5 4 6 7 8 9 10
Maximum, Minimum, Sum & Average is=10 1 55 5.5 (Same 10 times)
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int info;
node *next;
}*top,*newptr,*save,*ptr ;
node * create_new_node(int);
void push(node*);
void display(node*);
void main()
{ int inf;
char ch='y';
top=NULL;
clrscr();
while(ch=='y'||ch=='Y')
{
cout<<"\n enter information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"\n can not create new node";
exit(1);
}
push(newptr);
cout<<"\n now the link stack is";
display(top);
cout<<"press Y to enter more nodes,n to exit";
cin>>ch;}}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
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";
}
OUTPUT:
Enter information for the new node…7
Press Y to enter more nodes, n to exit…y
Enter information for the new node…1
Press Y to enter more nodes, n to exit…n
The stack now is:
1->7->!!!
Q-9) WRITE A PROGRAM TO PERFORM POP OPERATION ON LINKED STACK AND
DISPLAY THE STACK ELEMENT
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int info;
node *next;
}*top,*newptr,*save,*ptr ;
node * create_new_node(int);
void push(node*);
void display(node*);
void pop();
void main()
{top=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{cout<<"\n enter information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{ cout<<"\n can not create new node";
getch();
exit(1);
}
push(newptr);
cout<<"\n now the link stack is";
cout<<"press Y to enter more nodes,n to exit";
cin>>ch;
}
clrscr();
do
{ cout<<"the stack now is";
display(top);
getch();
cout<<"want to pop an element(y/n)";
cin>>ch;
if(ch=='y'||ch=='Y')
pop();
} while(ch=='y'||ch=='Y');
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void push(node*np)
{
if (top==NULL)
top=np;
else
{
save=top;
top=np;
np->next=save;
}
}
void pop()
{ if(top==NULL)
cout<<"underflow";
else
{ ptr=top;
top=top->next;
delete ptr; }
}
void display(node*np)
{ while(np!=NULL)
{ cout<<np->info<<" ";
np=np->next; }
cout<<"!!";
}
OUTPUT:
Enter information for the new node…1
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…7
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…2
Press Y to enter more nodes,N to exit…n
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct queue
{ char str[30];
queue *next;
}*START,*REAR,*newptr,*temp;
void INSERT()
{
newptr=new queue;
cout<<"Enter the string of the node\n";
gets(newptr->str);
newptr->next=NULL;
if(REAR==NULL)
START=REAR=newptr;
else
{
temp=REAR;
REAR=newptr;
newptr->next=temp;
}
}
void DISPLAY()
{ int i=0;
while(newptr!=NULL)
{ i++;
cout<<"\n\nString of node " <<i<<" is: "<<newptr->str;
newptr=newptr->next;
}
getch();
delete newptr;
}
void main()
{
clrscr();
char ch='y';
while(ch=='y'||ch=='Y')
{
INSERT();
cout<<"Do you want to enter more nodes to the queue(y/n)\n";
cin>>ch;
clrscr();
}
cout<<"Do you want to see the queue(y/n)\n";
cin>>ch;
if(ch=='y'||ch=='Y')
DISPLAY();
}
OUTPUT:
Enter information for the new node…17
Now the queue is:
17->!!!
Press Y to enter more nodes,N to exit…y
Enter information for new nodes…12
Now the queue is:
17->12->!!!
#include<iostream.h>
#include<process.h>
#include<string.h>
struct node
{ char info[25];
node*next;
}*front,*newptr,*save,*ptr,*rear;
node *create_new_node(char n[25]);
void insert(node*);
void display(node*);
void delnode_q();
void main()
{ front=rear=NULL;
char inf[25],ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n enter the information for new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{cout<<"\n cannot create mew node!!";
exit(1);}
insert(newptr);
cout<<"\n Press Y to enter new node,N to exit\n";
cin>>ch;
}
do
{cout<<"\n The linked queue now is (frontto_rear):\n";
display(front);
cout<<"want to delete first node?(Y/N)";
cin>>ch;
if(ch=='y'||ch=='Y')
delnode_q();
}while(ch=='y'||ch=='Y');
}
node*create_new_node(char n[25])
{ ptr=new node;
strcpy(ptr->info,n);
ptr->next=NULL;
return ptr; }
void insert(node*np)
{ if(front==NULL)
{ front=rear=np;}
else
{ rear->next=np;
rear=np;} }
void delnode_q()
{ if(front==NULL)
cout<<"underflow!!!\n";
else
{ ptr=front;
front=front->next;
delete ptr;} }
void display(node*np)
{ while(np!=NULL)
{ cout<<np->info<<"->";
np=np->next;} }
OUTPUT:
Enter information for the new node…15
Press Y to enter more nodes, N to exit…n
the linked queue now is :
3->4->8->9->15-> !!!
Want to delete first node? (y/n)…y
the linked queue now is :
4->8->9->15-> !!!
Q-12) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “text.txt”,
COUNT & DISPLAY THE NUMBER OF ALPHABETS PRESENT IN IT.
#include<fstream.h>
#include<ctype.h>
#include<conio.h>
void main()
{
char ch; int c=0;
ifstream fin("test.txt");
if(!fin)
{
cout<<"error in opening file";
}
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
if(isalpha(ch))
c++;
}
cout<<"\n No. of alphabets are"<<c;
fin.close();
OUTPUT:
He is playing Football
No. of alphabets are 19.
Q-13) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “sample.txt”,
COUNT & DISPLAY THE NUMBER OF LINE PRESENT IN IT.
#include<fstream.h>
void main()
{
char str[255];
int l=0;
ifstream fin;
fin.open("sample.txt");
if(!fin)
{
cout<<"error in opening the file";
}
while(fin)
{
fin.getline(str,255);
for(int i=0;i<=255;i++)
{
if(str[i]=='\n')
l++;
}
}
cout<<"The no. of lines r"<<l;
fin.close();
}
OUTPUT:
I am a student of class XII
This is my Practical file
Q-14) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “notes.txt”,
COUNT & DISPLAY THE NUMBER OF WORDS PRESENT IN IT.
#include<fstream.h>
void main()
{
char ch; int c=1;
ifstream fin("notes.txt");
if(!fin)
cout<<"error in opening of file";
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
else if(ch==' ')
c++;
}
cout<<"No.of words are"<<c;
fin.close();
}
Q-15) WRITE A PROGRAM TO READ THE CONTENTS FROM A TEXT FILE “paper.txt”,
COUNT & DISPLAY THE NUMBER OF BLANK SPACES WORDS PRESENT IN IT.
#include<fstream.h>
void main()
{
char ch; int c=0;
ifstream fin;
fin.open("notes.txt");
if(!fin)
cout<<"error in opening the file";
while(fin)
{
fin.get(ch);
if(ch==EOF)
break;
else if(ch==' ')
c++;
}
cout<<"No. of blank spaces are"<<c-1;
fin.close();
}
OUTPUT:
book1.txt contains Books on Computer Science
Then book2.txt will have same Books on Computer Science
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct Employee
{char ename[20],designation[10];
long int ecode,salary;
};
void main()
{ clrscr();
char file1[20];
cout<<"Enter file name\n";
cin>>file1;
INPUT(file1);
display(file1);
getch(); }
Q-18) WRITE A PROGRAM TO INPUT THE DETAILS OF 5 STUDENTS IN BINARY FILE
USING FOLLOWING CLASS STUDENT WITH INPUT() & DISPLAY() & FIELDS – STUNAME,
ROLLNO, MARKS, GRADE.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class student
{ int rollno,marks;
char stuname[20],grade;
public:
void input();
void display();
};
void student::input()
{ cout<<"Enter roll number\n";
cin>>rollno;
cout<<"Enter name\n";
gets(stuname);
cout<<"Enter marks\n";
cin>>marks;
cout<<"Enter grade\n";
cin>>grade; }
void student::display()
{ cout<<rollno<<"\t\t"<<stuname<<"\t\t"<<marks<<"\t\t"<<grade<<"\n"; }
void main()
{ char file[10];
int i;
student temp;
clrscr();
cout<<"enter file name\n";
cin>>file;
ofstream fout;
fout.open(file,ios::binary);
if(!fout)
cout<<"Unable to open file!!";
else
{
for(i=0;i<5;i++)
{
temp.input();
fout.write((char*)&temp,sizeof(temp));
}
fout.close();
}
clrscr();
ifstream fin;
fin.open(file,ios::binary);
if(!fin)
cout<<"Unable to open file!!";
else
{ cout<<"\t\tDetails\n";
cout<<"ROLL\t\tNAME\t\tMARKS\t\tGRADE\n";
for(i=0;i<5;i++)
{
fin.read((char*)&temp,sizeof(temp));
temp.display(); }
}
getch(); }
Q-19) WRITE A PROGRAM TO PRINT THE SUM OF LEFT AND RIGHT DIAGONALS OF A
SQUARE MATRIX SEPERATELY. MATRIX IS PASSED TO THE FUNCTION AS AN
ARGUMENT.
#include<iostream.h>
#include<conio.h>
void DiagSum(int A[][],int N)
{ int SumD1=0,SumD2=0;
for (int I=0;I<N;I++)
{SumD1+=A[I][I];
SumD2+=A[N-I-1][I]; }
cout<<”Sum of Diagonal 1=”<<SumD1<<endl;
cout<<”Sum of Diagonal 2=”<<SumD2<<endl;
}
void main()
{ clrscr();
int a[20][20],i,j,n;
cout<<”Enter the size=”;
cin>>n;
cout<<”Enter the array=”;
for(i=0;i<n;i++)
{ for(j=0;j<10;j++)
{ cin>>a[i][j];} }
DiagSum(a[][],n);
getch();
}
OUTPUT :
Enter the size=2
Enter the array= 4 1 5 3
Sum of Diagonal 1= 7
Sum of Diagonal 2= 6
Q-20) WRITE A PROGRAM USING FUNCTIONS WHICH ACCEPTS AN INTEGER ARRAY &
ITS SIZE AS ARGUMENTS & REPLACES ELEMENTS HAVING ODD VALUES WITH
THRICE ITS VALUE & ELEMENTS HAVING EVEN VALUES WITH TWICE ITS VALUE.
#include<iostream.h>
#include<conio.h>
void replace( int a[],int n)
{ int i;
for(i=0;i<n;i++)
{ if(a[i]%2==0)
a[i]=2*a[i];
if(a[i]%3==0)
a[i]=3*a[i]; }
}
void main()
{ clrscr();
int a[10],i,n;
cout<<”Enter the size=”;
cin>>n;
cout<<”Enter the array=”;
for(i=0;i<n;i++)
cin>>a[i];
replace(a,n);
cout<<”The new array=”;
for(i=0;i<n;i++)
cout<<a[i]<<” “;
getch();
}
OUTPUT:
Enter the size=5
Enter Array= 1 2 5 3 4
The new Array= 3 4 15 9 16
Q.NO.1) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
GARMENT
GCODE DESCRIPTION PRICE MCODE LAUNCHDATE
10023 PENCIL SKIRT 1150 F03 19-DEC-08
10001 FORMAL SHIRT 1250 F01 12-JAN-08
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10007 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 31-OCT-08
FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
1) SELECT DCODE,DESCRIPTION
FROM DRESS
ORDER BY DCODE;
2) SELECT *
FROM DRESS
WHERE LAUNCHDATE
BETWEEN 05-DEC-07 AND 20-JUN-08;
3) SELECT AVG(PRICE)
FROM DRESS
WHERE MCODE=M003;
4) SELECT MAX(PRICE),MIN(PRICE)
FROM DRESS, MATERIAL
WHERE DRESS.DCODE=MATERIAL.MCODE;
5) 1450
6) DESCRIPTION TYPE
PENCIL SKIRT SILK
FORMAL SKIRT TERELINE
INFORMAL COTTON
FORMAL SHIRT TERELENE
FROCK POLYESTER
INFORMAL SHIRT COTTON
EVENING GOWN SILK
TULIP SKIRT COTTON
7) M001,M002
8) 10
Q.NO.2) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE:PRODUCT
ii) To display the details of products whose price is in the range of 50 to 100 (Both values
included)
iii) To display the client name, city from table client, and product name and price from table
product, with their corresponding matching P_ID.
ANSWERS
i. SELECT *
FROM CLIENT
WHERE CITY = “DELHI”;
ii. SELECT*
FROM PRODUCT
WHERE PRICE BETWEEN 50 TO 100 ;
v. DELHI
MUMBAI
BANGALORE
vi. LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2
Q.NO.3) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE:SENDER
TABLE : RECIPIENT
Q.NO.4) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
TABLE : DOCTOR
TABLE : SALARY
IV) DISPLAY THE HIGHEST CONSULTATION FEE AMONG ALL MALE DOCTORS.
VI) SELECT NAME, DEPT,BASIC FROM DOCTOR, SALARY WHERE DEPT =”ENT”
AND DOCTOR.ID=SALARY.ID
ANSWER
v) 4
Q.NO.5) Consider the following tables. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii) 6
EMPLOYEES
EMPID FIRSTNAME LASTNAME ADDRESS CITY
010 GEORGE SMITH 83 FIRST STREET HOWARD
105 MERRY JONES 842 VINE AVE. LOSANTIVILLE
152 SAM TONES 33ELM ST. PARIS
215 SARAH ACKERMAN 440US110 UPTON
244 MANILA SENGUPTA 24FRIENDST. NEW DELHI
300 ROBERT SAMUEL 95TH CROSS WASHINGTON
335 HENRY WILLIAMS 12 MORE ST. BOSTON
400 RACHEL LEE 121HARRISONST. NEW YORK
441 PETER THOMSON 11 RED ROAD PARIS
EMPSALARY
v) RACHEL 32000
PETER 28000
vi) 4
viii) 32000