Professional Documents
Culture Documents
MADE BY
Name: Jack
Class: XII
Board Enrolment No.: 1023
1
LEARNING OBJECTIVES
To develop logic for Problem Solving.
2
PRACTICAL SYLLABUS
Duration: 3 hours Total Marks: 30
1. Programming in C++ 12
Logic : 7 Marks
Documentation/Indentation : 2 Marks
Output presentation : 3 Marks
3
Binary File operations (creation, displaying, searching and
modification)
Text File operations (creation, displaying and modification)
2. SQL Commands 05
Five Query based questions on a particular Table / Relation to be
tested practically on computer during the examination. The
command along with the result must be written in the answer
sheet.
4. Project Work 05
The project has to be developed in C++ language with Object
Oriented Technology and also should have use of Data files. (The
project is required to be developed in a group of 2-4 students)
Presentation on the computer
Project report (Listing, Sample, Output, Documentation)
Viva
4
* 1 mark is for innovation while writing program.
6. Viva Voce 02
Viva will be asked from syllabus covered in class XII and the
project developed by student.
5
INDEX
1. Program to generate Fibonacci series recursively.
2. Implement concept of function overloading for calculating
area of circle, rectangle and triangle.
3. Define a class student with the following specifications
4. Write a program display lower half and upper half of a 2D
matrix
5. Program to implement Linear Search.
6. Program to implement Binary Search.
7. Program to create a base class Building that stores the
number of floors and the number of rooms
8. Show the use of virtual classes with the help of following
program
9. Program to implement Bubble Sort technique.
10. Program to implement Selection Sort technique.
11. Program to implement Insertion Sort technique.
12. Program to implement Merge Sort technique.
13. Program to find the length of a string and print the reversed
string using pointer.
6
14. Program to create count the number of characters, lines,
spaces and digits present in a text file data.txt.
15. Program create a binary file and write objects to it and
display them on screen after reading from the file.
16. Program to implement stack as an array.
17. Program to implement queue as an array.
18. Program to implement dynamic stack/stack as a linked list.
19. Program to implement dynamic queue as a linked list.
20. Program to implement linked list.
21. Program to implement circular queue.
SQL Queries:
7
4. Write SQL queries for (a) and write the outputs for the SQL
queries mentioned shown in (b) part on the basis of tables
PRODUCTS and SUPPLIERS.
6. Viva Voce
8
Index^
9
Index^
Solution:
#include<iostream.h>
#include<conio.h>
long fibo(int n)
{
if(n<=1)
return n;
else
return fibo(n-1)+fibo(n-2);
}
void main()
{clrscr();
int n;
long f;
10
Index^
OUTPUT
11
Index^
Solution:
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
void area(int a)
{
cout<<"Area of Circle:"<<pi*a*a;
}
12
void main()
{ int ch;
int a,b,r;
clrscr();
switch(ch)
{
case 1: cout<<"\nEnter Radious of the Circle:";
cin>>r;
area(r);
break;
case 2: cout<<"\nEnter Sides of the Rectangle:";
cin>>a>>b;
area(a,b);
break;
case 3: cout<<"Enter Sides of the Triangle:";
cin>>a>>b;
area(0.5,a,b);
break;
case 4: exit(0);
}
getch();
}
13
Index^
OUTPUT
14
Index^
Private members:
admno : integer
phy : integer
chem : integer
maths : integer
eng :integer
csc : integer
total : float
avg : total
grade : character
ctotal() : A function that return the value for total variable as sum
of the marks:
phy+chem+maths+eng +csc
Public members:
15
Avg grade
80-100 A
60-79 B
40-59 C
- D
Solution:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
private:
int admno;
char sname[20];
float phy, chem,maths,eng,csc;
16
float total;
float avg;
char grade;
float ctotal()
{
return phy+chem+maths+eng+csc;
}
public:
void Takedata()
{
cout<<"Enter admission number: ";
cin>>admno;
17
cout<<"\nEnter marks in computer science: ";
cin>>csc;
total=ctotal();
}
void Grade()
{
avg=total/5;
else
grade='D';
void Showdata()
{
cout<<endl<<"..........Student
information...."<<endl;
cout<<"Admission number "<<admno;
cout<<"\nStudent name "<<sname;
18
cout<<"\nPhysics "<<phy;
cout<<"\nChemistry "<<chem;
cout<<"\nMath "<<maths;
cout<<"\nEnglish "<<eng;
cout<<"\nComputer Science "<<csc;
cout<<"\nTotal "<<total;
cout<<"\nAverage "<<avg;
cout<<"\nGrade "<<grade;
}
};
int main()
{
clrscr();
student obj ;
obj.Takedata();
obj.Grade();
obj.Showdata();
getch();
return 0;
}
19
Index^
OUTPUT
20
Index^
781
501
915
Lower half-
7
50
915
Upper half-
781
01
5
Solution:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j;
int a[3][3];
21
cout<<"\nEnter values for matrix: ";
for(i=0; i<3; i++)
{
clrscr();
cout<<"\n";
cout<<"\n\n";
22
cout<<"\nThe upper half of the matrix is...";
cout<<"\n";
for(i=0; i<3; i++)
{
else if(i>j)
cout<<" ";
}
cout<<"\n\n";
}
getch();
}
23
Index^
OUTPUT
24
Index^
Solution:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int flag=1;
25
int pos;
for(i=0;i<n;i++)
{
if(a[i]==ele)
{
pos=i+1;
flag=1;
break;
}
else
flag=1;
}
if(flag==1)
cout<<"\nElement found at position. "<<pos;
else
cout<<"\nElement not present. ";
getch();
}
26
Index^
OUTPUT
27
Index^
Solution:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int AR[20],n,val;
int found;
for(int i=0;i<n;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>AR[i];
}
28
found=bsearch(AR,n,val);
if(found==1)
cout<<"\nItem found";
else
cout<<"\nItem not found";
getch();
while(Lbound<=Ubound)
{
Mid=(Lbound+Ubound)/2;
if(ele>AR[Mid])
Lbound=Mid+1;
else if(ele<AR[Mid])
Ubound=Mid-1;
else
return 1;
}
return 0;
}
29
Index^
OUTPUT
30
Index^
Solution:
#include <iostream.h>
#include<conio.h>
class Building
{
int floors;
int rooms;
public :
void getd()
{
cout<<"\nNo. of Floors = ";
cin>>floors;
cout<<"\nNo. of Rooms = ";
cin>>rooms;
}
void dispd()
{
cout<<"\nNo. of Floors = "<<floors;
31
cout<<"\nNo. of Rooms = "<<rooms;
}
};
public :
void getdat()
{
getd();
cout<<"\nNo. of Bathrooms = ";
cin>>baths;
cout<<"\nNo. of Terraces = ";
cin>>terraces;
}
void dispdat()
{
dispd();
cout<<"\nNo. of Bathrooms = "<<baths;
cout<<"\nNo. of Terraces = "<<terraces;
}
};
32
public:
void getdata()
{
getd();
cout<<"\nNo. of Fire Exits = ";
cin>>firexits;
}
void dispdata()
{
dispd();
cout<<"\nNo. of Fire Exits = "<<firexits;
}
};
void main()
{
clrscr();
Flats of;
Offices oo;
of.getdat();
of.dispdat();
oo.getdata();
oo.dispdata();
getch();
}
33
Index^
OUTPUT
34
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class publication
{ int item_no;
char title[20];
public:
void input()
{
cout<<"\nEnter item no: ";
cin>>item_no;
cout<<"\nEnter title: ";
cin>>title;
}
35
void print()
{
cout<<"\nItem No: "<<item_no;
cout<<"\nItem title: "<<title;
}
};
void getbook()
{
cout<<"Enter number of pages: ";
cin>>pages;
}
void showbook()
{
cout<<"\nPages: "<<pages;
}
};
public:
36
void gettape()
{
cout<<"\nEnter playng time: ";
cin>>ptime;
}
void showtape()
{
cout<<"\nPlaying time: "<<ptime;
};
public:
void getdata()
{
cout<<"\nEnter price: ";
cin>>price;
}
void display()
{
cout<<"\nPrice: "<<price;
}
};
37
void main()
{
clrscr();
record rec;
getch();
}
38
Index^
OUTPUT
39
Index^
Solution:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[30],size,i,j,temp;
for(i=0;i<size;i++)
cin>>a[i];
for(i=0;i<size-1;i++)
{
for(j=i+1;j<size;j++)
{
if(a[i]>a[j])
{
40
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<size;i++)
cout<<a[i]<<",\t";
getch();
}
41
Index^
OUTPUT
42
Index^
Solution:
#include<iostream.h>
#include<conio.h>
//Selection Sort
void selsort (int ar[], int size)
{
int min,temp,loc;
loc = i;
temp=ar[i];
ar[i]=ar[loc];
ar[loc]=temp;
43
}
}
void main ()
{
clrscr();
int n,i,min;
int ar[20];
selsort(ar,n);
44
Index^
OUTPUT
45
Index^
Solution:
#include<iostream.h>
#include<conio.h>
//Insertion Sort
for(int i=1;i<n;i++)
{
temp = ar[i];
void main ()
{
clrscr();
46
int n,i,min;
int ar[20];
InsertionSort(ar,n);
47
Index^
OUTPUT
48
Index^
Solution:
#include<iostream.h>
#include<conio.h>
int a[20];
void merge(int,int,int);
int mid;
if(low<high)
{
mid=(low+high)/2;
merge_sort(low,mid);
merge_sort(mid+1,high);
merge(low,mid,high);
}
}
49
h=low;
i=low;
j=mid+1;
while((h<=mid)&&(j<=high))
{
if(a[h]<=a[j])
{
b[i]=a[h];
h++;
}
else
{
b[i]=a[j];
j++;
}
i++;
}
if(h>mid)
{
for(k=j;k<=high;k++)
{
b[i]=a[k];
i++;
}
}
else
{
50
for(k=h;k<=mid;k++)
{
b[i]=a[k];
i++;
}
}
for(k=low;k<=high;k++)
a[k]=b[k];
}
void main()
{
clrscr();
int num,i;
merge_sort(1,num);
getch();
}
51
Index^
OUTPUT
52
Index^
13. Program to find the length of a string and print the reversed
string using pointer.
Solution:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int string_length(char*);
void reverse(char*);
void main()
{
clrscr();
char string[100];
reverse(string);
getch();
}
53
int length, c;
char *begin, *end, temp;
length = string_length(string);
begin = string;
end = string;
begin++;
end--;
}
}
return c;
}
54
Index^
OUTPUT
55
Index^
Solution:
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
ifstream fin("sam.txt");
char ch;
int i,line=0,chars=0,space=0,nos=0;
while(fin)
{
fin.get(ch);
i=ch;
if(i>63&&i<91||i>96&&i<123)
chars++;
else if(i>47&&i<58)
nos++;
56
else if(ch==' ')
space++;
else if(ch=='\n')
line++;
else
cout<<"No data found";
}
cout<<"\nNumber of alphabates:"<<chars;
cout<<"\nNumber of digits:"<<nos;
cout<<"\nNumber of Spaces:"<<space;
cout<<"\nNumber of lines: "<<line;
getch();
}
57
Index^
OUTPUT
58
Index^
Solution:
#include<fstream.h>
#include<conio.h>
class Employee
int empcode;
char empname[20];
char depart[20];
public:
void getdat()
59
cin>>empcode;
char c=cin.get();
cin.getline(empname,20);
cout<<"\nDepartment : ";
cin.getline(depart,20);
void dispdat()
cout<<"\nDepartment : "<<depart;
};
void main()
clrscr();
Employee e;
60
int num=0;
char fname[13];
cin>>fname;
ofstream ofl;
ofl.open(fname, ios::app|ios::binary);
if(!ofl)
return;
cin>>num;
for(int i=1;i<=num;i++)
e.getdat();
61
ofl.write((char*)&e,sizeof(Employee));
ofl.close();
ifstream ifl;
ifl.open(fname, ios::app|ios::binary);
if(!ofl)
return;
else
while(ifl.read((char*)&e,sizeof(Employee)))
{ e.dispdat();
getch();
62
Index^
OUTPUT
63
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<process.h>
class stack
private:
int ar[SIZE];
public:
void pop();
64
void display();
};
if(top==SIZE-1)
cout<<"\nStack is Full!!";
else
ar[++top]=item;
cout<<"\nElement inserted.";
void stack::pop()
if(top==-1)
cout<<"\nStack Underflow!!";
65
else
top--;
void stack::display()
if(top==-1)
cout<<"\nStack is Empty...";
else
for(int i=top;i>=0;i--)
cout<<ar[i]<<" ";
66
void main()
clrscr();
char choice;
int ch,num;
stack ob;
do
cout<<"\n\n1.Push";
cout<<"\n2.Pop";
cout<<"\n3.Display";
cout<<"\n4.EXIT";
cin>>ch;
67
switch(ch)
cin>>num;
ob.push(num);
break;
case 2: ob.pop();
break;
case 3: ob.display();
break;
case 4: exit(0);
cin>>choice;
}while(choice=='y' || choice=='Y');
getch();
68
Index^
OUTPUT
69
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<process.h>
class queue
int a[SIZE];
int front;
int rear;
public:
queue();
~queue();
void insert();
void remove();
70
void display();
};
queue::queue()
front=-1;
rear=-1;
queue::~queue()
delete []a;
void queue::insert()
int i;
if(rear==SIZE-1)
else
71
cout<<"\nEnter element: ";
cin>>i;
rear++;
a[rear] = i;
if(front==-1)
front++;
void queue::remove()
if(front==-1)
cout<<"Queue Empty!!";
else
front++;
72
if(front==rear+1)
front=rear=-1;
void queue::display()
if(front==-1)
cout<<"\nNo elements.";
else
for(int i=front;i<=rear;i++)
cout<<a[i]<<" ,";
void main()
clrscr();
queue q;
73
char choice;
int ch;
do
cout<<"\n1.Insert";
cout<<"\n2.Remove";
cout<<"\n3.Display";
cout<<"\n4.Exit";
cin>>ch;
switch(ch)
case 1: q.insert();
break;
case 2: q.remove();
break;
case 3: q.display();
break;
case 4: exit(0);
74
default:cout<<"\nInvalid choice.";
cin>>choice;
}while(choice=='y' || choice=='Y');
getch();
75
Index^
OUTPUT
76
Index^
Solution:
#include<iostream.h>
#include<conio.h>
class stack
struct node
{ int data;
node *link;
}*top;
public:
stack()
{ top=NULL; }
void push();
void pop();
void display();
};
77
void stack::push()
node *temp;
int ele;
temp=new node;
if(temp==NULL)
cout<<"\nStack is Full";
else
cin>>ele;
temp->data=ele;
temp->link=top;
top=temp;
void stack::pop()
int ele;
node *temp;
78
if(top==NULL)
cout<<"\nStack is Empty";
else
temp=top;
ele=temp->data;
temp=temp->link;
top=temp;
void stack::display()
node *temp;
if(top==NULL)
cout<<"\nStack is Empty";
else
{ temp=top;
79
while(temp!=NULL)
{ cout<<"\n"<<temp->data;
temp=temp->link;
void main()
int ch;
clrscr();
stack st;
st.push();
st.push();
st.push();
st.display();
st.pop();
st.display();
getch();
80
Index^
OUTPUT
81
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<process.h>
class LQueue
struct node
int data;
node *next;
}*front,*rear,*temp;
public:
LQueue()
82
front=NULL;
rear=NULL;
void add();
void del();
void display();
};
void LQueue::add()
temp=new node();
cin>>temp->data;
if(front==NULL)
front=temp;
83
rear=temp;
else
temp->next=NULL;
rear->next=temp;
rear=temp;
void LQueue::del()
temp=new node();
temp=front;
if(front==NULL)
else
front=front->next;
84
delete temp;
void LQueue::display()
temp=new node();
temp=front;
while(temp!=NULL)
cout<<temp->data<<" , ";
temp=temp->next;
void main()
clrscr();
85
LQueue d;
int ch;
char choice;
do
cout<<"\nOperations on Queue-";
cout<<"\n1.Insert\n2.Delete\n3.Display\n4.Exit\t";
cin>>ch;
switch(ch)
case 1:d.add();
break;
case 2:d.del();
break;
86
case 3:d.display();
break;
case 4: exit(0);
cin>>choice;
}while((choice=='y')||(choice=='Y'));
getch();
87
Index^
OUTPUT
88
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class list
struct node
int data;
node *link;
}*p;
public:
void inslast(int);
void insbeg(int);
void insnext(int,int);
89
void delelement(int);
void disp();
list(){p=NULL;}
~list();
};
void list::inslast(int x)
node *q,*t;
if(p==NULL)
p=new node;
p->data=x;
p->link=NULL;
else
q=p;
while(q->link!=NULL)
90
q=q->link;
t=new node;
t->data=x;
t->link=NULL;
q->link=t;
node *q;
q=p;
p=new node;
p->data=x;
p->link=q;
91
}
void list::delelement(int x)
node *q,*r;
if(p==NULL)
cout<<"\nEmpty list.";
else
q=p;
if(q->data==x)
p=q->link;
delete q;
cout<<"\nElement deleted...";
92
return;
r=q;
while(q!=NULL)
if(q->data==x)
r->link=q->link;
delete q;
cout<<"\nElement deleted...";
return;
r=q;
q=q->link;
93
list::~list()
node *q;
if(p==NULL) return;
while(p!=NULL)
q=p->link;
delete p;
p=q;
void list::disp()
node *q;
q=p;
if(q==NULL)
94
cout<<" No data is in the list.. ";
return;
while(q!=NULL)
cout<<" "<<q->data;
q=q->link;
node *temp,*temp1;
temp=p;
for(int i=0;i<position;i++)
if((temp==NULL)&&(position>1))
95
{
break;
else
if((temp==NULL)&&(position==1))
temp1->data=value;
temp1->link=NULL;
p=temp1;
cout<<"\nNode inserted.";
return;
else if(i==(position-1))
96
{
temp1->data= value;
temp1->link=temp->link;
temp->link=temp1;
cout<<"\nNode inserted.";
return;
temp=temp->link;
void main()
list l;
char choice;
int ch,v,p;
97
clrscr();
do
cout<<"\nOperations on List..";
cin>>ch;
switch(ch)
cin>>v;
l.insbeg(v);
break;
98
case 2: cout<<"\nEnter the value to insert:";
cin>>v;
l.inslast(v);
break;
cin>>v;
cin>>p;
l.insnext(v,p);
break;
cin>>v;
l.delelement(v);
break;
99
case 5: l.disp();
break;
case 6: exit(1);
cin>>choice;
}while(choice=='Y'||choice=='y');
getch();
100
Index^
OUTPUT
101
Index^
Solution:
#include<iostream.h>
#include<conio.h>
#include<process.h>
class cqueue
int a[MAX],front,rear;
public :
cqueue()
front=rear=-1;
void insert(int);
void deletion();
102
void display();
};
else
if(rear==MAX-1)
rear=0;
else
rear++;
a[rear]=val;
if(front==-1)
front=0;
103
{
if(front==-1)
else
if(front==rear)
front=rear=-1;
else
if(front==MAX-1)
front=0;
else
front++;
104
int i;
if(front==-1)
else
for(i=front;i<=MAX-1;i++)
cout<<a[i]<<" ";
for(i=0;i<=rear;i++)
cout<<a[i]<<" ";
else
for(i=front;i<=rear;i++)
cout<<a[i]<<" ";
cout<<endl;
105
}
void main()
{ cqueue c1;
int ch,val;
char op;
clrscr();
do
cin>>ch;
switch(ch)
cin>>val;
c1.insert(val);
break;
106
case 2 : c1.deletion();
break;
case 3 : c1.display();
break;
case 4: exit(0);
cin>>op;
}while(op=='Y' || op=='y');
getch();
107
Index^
OUTPUT
108
109
Index^
Table: CARDEN
Table: CUSTOMER
110
(a) Write SQL commands for the following:
Ans (a)
111
ii. SELECT CarName, Make, Capacity FROM CARDEN ORDER BY
Capacity desc;
iii. SELECT MAX(Charges) AS Highest Charges FROM CARDEN
iv. SELECT CName, CarName FROM CUSTOMER, CARDEN
WHERE CUSTOMER.CCode = CARDEN.Ccode
(b)
112
113
Index^
Table: ITEMS
114
Table: TRADERS
T01 2
T02 2
115
T01 1
iv. To display the price, item name and quantity (i.e., qty) of
those items that have quantity more than 150.
v. To display the names of those traders, who are either from
DELHI or MUMBAI.
vi. To display the names of the companies and the names of
the items in the descending order of the company names.
Ans 2. (a)
116
i. SELECT * FROM ITEMS ORDER BY INAME ASC;
ii. SELECT INAME, PRICE FROM ITEMS WHERE PRICE
BETWEEN 10000 AND 22000;
iii. SELECT ITEMS.TCODE, COUNT (TCODE) FROM ITEMS,
TRADERS GROUP BY ITEMS.TCODE HAVING
TEMS.TCODE=TRADER.TCODE;
iv. SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY>150;
v. SELECT INAME FROM ITEMS I, TRADERS T WHERE
I.TCODE=T.TCODE AND CITY IN (DELHI, MUMBAI);
vi. SELECT COMPANY, INAME FROM ITEMS ORDER BY
COMPANY DESC;
(b)
i.
MAX MIN(PRICE)
(PRICE)
38000 1200
ii.
AMOUNT
1075000
117
iii.
TCODE
T01
T02
T03
iv.
INAME TNAME
118
Index^
Table: STORE
ABC GK II
S01 Computronics
ALL Infotech CP
S01 Media
Tech Shoppe Nehru Place
S02
Geeks Tecno Nehru Place
S04 Soft
Hitech Tech CP
S05 Store
Table: ITEM
119
Mother Board 400 S03
T05
Key Board 400 S03
T06
LCD 6000 S04
T07
LCD 5500 S05
T08
Mouse 350 S05
T09
Hard Disk 4500 S03
T10
120
iii. SELECT COUNT(DISTINCT AREA) FROM STORE;
iv. SELECT INAME, PRICE*0.05 DISCOUNT FROM ITEM WHERE
SNO IN (S02,S03);
Ans.(a)
i. Select IName, Price From Item Order By Price Asc;
ii. Select SNo, SName From Store Where Area=CP;
iii. Select IName, Max(Price), Min(Price) From Item;
iv. Select IName, Price From Store, Item Where
Store.SNo=Item.INo;
(b)
i.
IName
Hard Disk
LCD
Mother Board
121
ii.
Area Count
2
CP
1
GK II
2
Nehru Place
iii.
Count
iv.
IName Price
25
Keyboard
650
Motherbaord
20
Key Board
225
Hard Disk
122
Index^
4. Write SQL queries for (a) and write the outputs for the SQL
queries mentioned shown in (b) part on the basis of tables
PRODUCTS and SUPPLIERS.
Table: PRODUCTS
DIGITAL
CAMERA 120 12000 RENIX S01
101
14X
DIGITAL S02
102 100 2200 DIGI POP
PAD 11i
LED S02
106 70 28000 DISPEXPERTS
SCREEN 32
123
Table: SUPPLIERS
SNAME CITY
SUPCODE
GET ALL INC KOLKATA
S01
EASY MARKET DELHI
S03 CORP
DIGI BUSY CHENNAI
S02 GROUP
124
iv. To display the price, product name and quantity (i.e., qty)
of those products which have quantity more than 100.
v. To display the names of those suppliers, who are either
from DELHI or from CHENNAI.
vi. To display the names of the companies and the names of
the products in descending order of company names.
Ans (a).
i. SELECT * FROM PRODUCTS ORDER BY PNAME ASC;
125
ii. SELECT PNAME, PRICE FROM PRODUCTS WHERE PRICE
BETWEEN 10000 AND 15000;
iii. SELECT PRODUCTS.SUPCODE, COUNT (SUPCODE) FROM
PRODUCTS, SUPPLIERS GROUP BY PRODUCT.SUPCODE;
HAVING PRODUCTS.SUPCODE=SUPPLIERS.SUPCODE;
iv. SELECT PRICE, PNAME, QTY FROM PRODUCTS WHERE
QTY>100;
v. SELECT PNAMES FROM PRODUCTS P, SUPPLIERS S WHERE
P.SUPCODE=S.SUPCODE AND CITY IN (DELHI, CHENNAI);
vi. SELECT COMPANY, PNAME FROM PRODUCTS ORDER BY
COMPANY DESC;
(b)
i.
SUPCODE
S01
S02
126
S03
ii.
MAX(PRICE) MIN(PRICE)
28000 1100
iii.
AMOUNT
550000
iv.
PNAME SNAME
127
Index^
Table: PRODUCT
LAK 40
TP01 TalcomPowder
ABC 45
FW05 Face Wash
ABC 55
BS01 Bath Soap
XYZ 120
SH06 Shampoo
XYZ 95
FW12 Face Wash
Table: CLIENT
128
Mumbai BS01
06 Face Wash
Delhi SH06
12 Bath Soap
Delhi FW12
15 Shampoo
Banglore TP01
16 Face Wash
129
iii. SELECT ClientName, ManufacturerName FROM Product,
Client WHERE Client.Prod_Id=Product.P_Id;
iv. SELECT ProductName, Price * 4 FROM Product;
Ans. (a)
i. Select all from Client where City=Delhi
ii. Select all from product where Price between 50 and 100
iii. Select ClientName,City,ProductName, Price from
Product,Client where Product.P_ID=Client.P_ID
iv. Update Product Set Price=Price +10
(b)
i.
City
Delhi
Mumbai
Bangalore
130
ii.
ABC 55 45 2
XYZ 120 95 2
iii.
ClientName ManufacturerName
Dreams LAK
131
iv.
ProductName Price*4
Talcom Poweder 160
Shampoo 480
132
Index^
VIVA VOCE
Ans1: Static data members are class variables. Only one copy
of the static data member is maintained and this is shared by all
the objects. They are visible only within the class but their
lifetime is the entire program. They can be used in all member
function.
133
Ans3: Members of a class are private by default while
members of a structure are public by default.
134
Q7. How are public members different from private
members of a class?
135
entities very effectively Person can be inherited by Employee
as well as Student.
136
specifiers in the derived class depending on the visibility mode
and its own access specifier.
137
Q15. How are text files different from binary files?
Ans15: Text files are also called ASCII files. They stores
information in the form of ASCII characters. There are 128
different ASCII codes. Also, text files contain lines of text and
each of these has an end-of-line (EOL) marker automatically
appended whenever you indicate that you have reached the end
of a line. When a file is opened in text mode, various character
translations take place. In case of binary files, information is
stored in the same format in which it is stored in the memory.
No character translation takes place when a binary file is
opened, because of which binary files can be read and written
faster by the computer.
Q17. Describe the streams used for input and output with
a file.
138
Ans17: There are 3 kinds of streams input, output and
input-output.
If we want to use the file for input i.e. reading, we must create
an input stream, using class ifstream. For example, ifstream ifl;
If we want to use the file for output i.e. writing, we must create
an output stream, using class ofstream. For example, ofstream
ofl; If we want to use the file for input as well as output, we
must create a stream performing both input and output, using
class fstream. For example, fstream iofl;
Ans18: Both get() and getline() can read characters from the
input stream into an array till the specified number of characters
are entered or till the delimiting character is encountered( \n by
default). The difference is that, in case of getline() this
character is removed from the input stream but get() leaves it in
the input stream.
139
Q19. How is the file mode ios::ate different from ios::app?
Q21. Which classes are used for file input and output
operations?
140
Q22. Name any two functions used in file input-output
error handling.
Ans22: int bad() and int fail() are used for error handling.
ifstream read_file(Names.Dat);
141
b) Using the function open() - this method is useful when
we want to use different files in the stream. If two or more
files are to be processed simultaneously, separate streams
must be declared for each.
Example -
struct Emp{
int code;
char name[20];
Emp *next; // pointer to type Emp
};
142
Here, structure Emp is a self-referential structure. It has a
member, next, which stores the address of Emp type.
143
Q27. How a Singly linked list is different from a doubly
linked list?
144
Ans29: Stack is a LIFO (Last In First Out) structure. This
means that the element that comes in last is the first to go out.
It can be visualized as a stack of trays where a fresh tray is put
on top of the existing stack and the one picked up is the tray on
top. Thus, insert and delete are from the same side. This is
called the top of the stack. Inserting into a stack is called
push and deleting from a stack is called pop. A stack can be
implemented using an array or a linked list.
145
Q31. What is the difference between an array and a stack
implemented as an array?
146
In the output restricted deque, deletions are allowed at only one
end but insertions can be done from both the ends.
STUDENT( )
147
{
rno=0;
class ABC
{ a=x; b=y; }
};
148
Q37. State the important characteristics of constructors?
149
The compiler creates default constructor and copy
constructor wherever needed.
If the class has a constructor, the objects are initialized
before use.
Normally the constructor is called implicitly but it can be
called explicitly too.
Example:
class A{
:
A ( ) {a=0; b=0;} //default constructor
150
A( int x, int y){a=x;b=y;} //constructor with 2
arguments
A(int x){a=x; b=2*x;} //constructor with 1
arguments
};
151
Q41. What is meant by dynamic initialization of objects?
152
Q42. What are destructors?
153
They have the same name as the class, preceded by the ~
character (tilde).
They are invoked automatically when objects are
destroyed.
No return type is specified for destructors.
Destructors obey the access rules.
They cannot be static.
They cannot be inherited.
Arguments cannot be passed to a destructor.
It is not possible to take the address of a destructor.
An object cannot be member of a union if the class has a
destructor.
Member functions can be called from inside the destructor.
The compiler creates default destructors wherever needed.
If the class has a destructor, the objects are de-initialized
before they go out of scope.
154
Ans45: Wireless communication does not use a medium, like
cables, for transmission. There are advantages and
disadvantages of this mode.
Advantages
Disadvantages
155
Q47. What is Cyberlaw?
156
portal will have a login facility and will provide information based
on who you are.
The URL has two parts the first part, http:// gives the protocol
used to locate the file on the Web.
157