Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1.

Each node of a linked queue contains the following information in addition to required pointer
field
i) Item Code ii) Item name
Give the structure of a node for the linked queue. Write a C++ program to insert a code, delete
a node and display the elements of the linked queue.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>

struct item void display()


{ {
int itemcode; if(f==NULL)
char itemname[30]; cout<<"\n\n\tEmpty List...";
item *next; else
}*f,*r,*x,*p; {
cout<<"\n\n\tThe elements
void insert_q() are:\n";
{ p=f;
x=new item; while(p!=NULL)
cout<<"\nEnter item code: "; {
cin>>x->itemcode; cout<<p->itemcode
cout<<"\nEnter item name: "; <<" "<<p-
gets(x->itemname); >itemname<<endl;
x->next=NULL; p=p->next;
if(f==NULL) }
f=r=x; }
else }
{
r->next=x;
r=x; void main()
} {
} clrscr();
int ch;
void delete_q() f=r=NULL;
{ do
if(f==NULL) {
cout<<"\n\n\tQueue is empty..."; cout<<"\n\n\t1. Insert a code";
else cout<<"\n\t2. Delete a node";
{ cout<<"\n\t3. Display the
p=f; Queue elements";
f=f->next; cout<<"\n\t4. Exit";
p->next=NULL; cout<<"\n\tEnter your
cout<<"\n\n\t"<<p- choice(1-4): ";
>itemname<<"is deleted from the queue"; cin>>ch;
delete p; switch(ch)
} {
} case 1: insert_q();
break;
case 2: delete_q();
break; }
case 3: display(); }while(ch<4);
break; }
2. Write SQL commands Based on the following table.
Table:Teacher
Sl No. Name Age Dept Date of Salary Sex
Join
1 Rupkatha 34 Computer Sc 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Sandeep 32 Mathematics 12/12/96 30000 M
4 Sangeeta 35 History 01/07/95 40000 F
5 Rakesh 42 Mathematics 05/09/97 25000 M
6 Shyam 50 History 27/02/97 30000 M
7 Shivam 44 Computer Sc 25/02/97 21000 M
8 Anup 33 Mathematics 31/01/97 20000 M

a) To list the names of female teachers who are in Mathematics


department.
SELECT *
FROM Teacher
WHERE Sex=’F’ AND Dept=”Mathematics”;

b) To count the number of teachers of each department.


SELECT Dept, COUNT (*)
FROM Teacher
GROUP BY Dept;

c) To insert a new row in the Teacher table with the following data:
9,”Raja”, 26,”Computer”, 13/05/95, 2300,”M”.
INSERT INTO Teacher
VALUES (9,”Raja”,26,”Computer”,13/05/95,2300,”M”);

d) Add a new column named “Address”.


ALTER TABLE Teacher ADD Address CHAR(50);
e) Display the age, salary and sex of the teachers whose name end with
“a”.
SELECT Age, Salary, Sex
FROM Teacher
WHERE Name LIKE “%a”;

You might also like