Vous êtes sur la page 1sur 68

PRAC1ICAL LIS1 - CLASS XII

C++
Pk4c1lc4L
-
4lM
1 Cuery on Lable PCSl1AL
2 Cuery on Lable 1LACPL8
3 Cuery on Lable S1uuLn1
4 Cuery on Lable MCvlL
3 Cuery on Lable lu8nl1u8L
6 rogram Lo perform sLrlng operaLlon
61 rogram Lo check wheLher Lhe glven characLer ls LCWL8 CASL or uL8 CASL
62 rogram Lo converL uL8CASL sLrlng Lo LCWL8CASL and vlceversa
63
rogram Lo read Lwo sLrlngs and append Lhe flrsL sLrlng Lo second
64 rogram Lo read a password and prlnL 'ok' lf correcL password else 'sorry' Lhe user
should be glven Lhree chances
63 rogram Lo check wheLher Lhe glven characLer ls ulCl1 or ALPA8L1lC or SLClAL
CPA8AC1L8
7 rogram Lo perform Lhe operaLlons on maLrlces uslng 2u arrays
71 rogram Lo Lake 2 MA18lx and prlnL Lhelr SuM ulllL8LnCL
72
rogram Lo Lake 2 MA18lx and prlnL Lhelr 8CuuC1
73 rogram Lo make 18AnSCSL of Lhe MA18lx
74 rogram Lo flnd Lhe sum of uL8 ulACCnAL LCWL8 ulACCnAL MAln ulACCnAL
LLLMLn1S
8

rogram Lo lllusLraLe passlng of a sLrucLure Lo a funcLlon CALL 8? vALuL ML1PCu
9 ueclare a class Lo represenL Lhe bank accounLs of 10 cusLomers
10 ueflne a class Lo represenL a book ln a llbrary
11 ueflne a class Lravel plan
12 rogram Lo explaln Lhe concepL of vlrLual base class
13 LlnLA8 search
14 8lnA8? search
13 lnSL81lCn ln sorLed and unsorLed array
16 uLLL1lCn ln array
17 SLLLC1lCn sorL
18 8u88LL sorL
19 lnSL81lCn sorL
20 ML8ClnC Lwo sorLed arrays lnLo 3
rd
sorLed array
21 rogram Lo creaLe Lwo arrays Lo sLore roll number and marks of some sLudenLs whose
number would be known aL run Llme
22 rogram Lo exchange poslLlon of sLrlngs uslng polnLer
23 rogram Lo show Lhe worklng of 1PlS polnLer
24 Llked llsL operaLlons
241
rogram Lo lnserL nCuLS from Lhe 8LClnnlnC of LlnkLu LlS1
242
rogram Lo lnserL nCuLS aL Lhe Lnu of LlnkLu LlS1
243 rogram Lo deleLe nCuLS from Lhe 8LClnnlnC of LlnkLu LlS1
23 SLack operaLlons
231 rogram Lo lnserL nCuLS ln Lhe LlnkLu S1ACk
232 rogram Lo deleLe nCuLS from LlnkLu S1ACk
26 Cueue operaLlons
261 rogram Lo lnserL nCuLS ln Lhe LlnkLu CuLuL
262 rogram Lo deleLe nCuLS from LlnkLu CuLuL
27 rogram for readlng and wrlLlng class ob[ecLs
28 rogram Lo deleLe a record from a flle
29 rogram Lo modlfy daLa ln a glven flle
30 Clven a flle sLudaLadaL LhaL sLores Lhe deLalls of some sLudenLs uslng deLalls of Lhls flle
creaLe anoLher flle called resulLdaL whlch should sLore flelds roll no percenLage and
grade Also dlsplay Lhe conLenLs of flle





























PRACTICAL NO.- 01

AIM
Write SQL commands on the basis oI table HOSPITAL.

Table: HOSPITAL
No. Name Age Department DateoIadm Charges Sex
1. Sandeep 65 Surgery 23/02/98 300 M
2. Ravina 24 Orthopedic 20/01/98 200 F
3. Karan 45 Orthopedic 19/02/98 200 M
4. Tarun 12 Surgery 01/01/98 300 M
5. Zubin 36 ENT 12/01/98 250 M
6. Ketaki 16 ENT 24/02/98 300 F
7. Ankita 29 Cardiology 20/02/98 800 F
8. Zareen 45 Gynaecology 22/02/98 300 F
9. Kush 19 Cardiology 13/01/98 800 M
10. Shaila 31 Nuclear machine 19/02/98 400 F



(a) To show all inIormation about the patients oI cardiology department.

Ans: SELECT *
FROM Hospital
WHERE Department 'Cardiology;


(b)To list the names oI Iemale patients who are in orthopaedic department.

Ans: SELECT Name
FROM Hospital
WHERE Department 'Orthopedic AND Sex 'F;


(c) To list names oI all patients with their date oI admission in ascending order.

Ans: SELECT Name
FROM Hospital
ORDER BY DateoIadm;


(d)To display Patient`s Name, Charges, Age Ior only male patients only.

Ans: SELECT Name, Charges, Age
FROM Hospital
WHERE Sex M;




(e) To count the number oI patients with Age ~ 30.

Ans: SELECT COUNT (*)
FROM Hospital
WHERE Age 30;


(I) To insert new row in the HOSPITAL table with the Iollowing data :
11, 'MustaIa, 37, 'ENT, 25/02/98}, 250. 'M;

Ans: INSERT INTO Hospital
VALUES (11, 'MustaIa, 37, 'ENT, 25/02/98}, 250, 'M);






































PRACTICAL NO.- 02

AIM
Write SQL commands on the basis oI TEACHER relation given below.

Table: TEACHER
No. Name Age Department Date oI
join
Salary Sex
1 Jugal 34 Computer 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Sandeep 32 Maths 12/12/96 30000 M
4 Sangeeta 35 History 01/07/99 40000 F
5 Rakesh 42 Maths 05/09/97 25000 M
6 Shyam 50 History 27/06/98 30000 M
7 Shiv Om 44 Computer 25/02/97 21000 M
8 Shalaka 33 Maths 31/07/97 20000 F


(a) To show all inIormation about the teacher oI history department.

Ans: SELECT * FROM Teacher
WHERE Department History;


(b)To list the names oI Iemale teachers who are in Hindi Department.

Ans: SELECT Name FROM Teacher
WHERE Department Hindi and SexF;


(c) To list names oI all teachers with their date oI joining in ascending order.

Ans: SELECT Name, Date oI join
FROM Teacher
ORDER BY Date oI join;


(d)To display teacher`s Name, Salary, Age Ior male teacher only

Ans: SELECT Name, Salary, Age
FROM Teacher
WHERE Age ~ 23 AND Sex 'M;


(e) To count the number oI teachers with Age ~23.

Ans: SELECT COUNT (*)
FROM Teacher
WHERE Age~23;

(I) To insert a new row in the TEACHER table with the Iollowing data:
9,Raja, 26, 'Computer, 13/05/95}, 2300, 'M

Ans: INSERT INTO Teacher
VALUES (9,Raja, 26, 'Computer, 13/05/95}, 2300, 'M)














































PRACTICAL NO.- 03

AIM
Write SQL commands on the basis oI table STUDENT.


Table: STUDENT
No. Name Age Department Date oI Adm. Fee Sex
1. Pankaj 24 Computer 10/01/97 120 M
2. Shalini 21 History 24/03/98 200 F
3. Sanjay 22 Hindi 12/12/96 300 M
4. Sudha 25 History 01/07/99 400 F
5. Rakesh 22 Hindi 05/09/97 250 M
6. Shakeel 30 History 27/06/98/ 300 M
7. Surya 34 Computer 25/02/97 210 M
8. Shikha 23 Hindi 31/07/97 200 F



(a) To show all inIormation about the students oI History department.

Ans: SELECT * FROM student
WHERE Department 'History;


(b)To list the names oI Iemale students who are in Hindi department.

Ans: SELECT Name FROM Student
WHERE sex 'F and
Department 'Hindi;

(c) To list the names oI all students with their date oI admission in ascending order.

Ans: SELECT name FROM Student
ORDER BY DateoIadm;

(d)To display student`s Name, Fee, Age, Ior male Students only.

Ans: SELECT Name, Fee, Age
FROM Student
WHERE sex 'M;


(e) To count the number oI student with Age23.

Ans: SELECT COUNT (*) FROM Student
WHERE Age~23;
(I) To insert new row in the STUDENT table with the Iollowing data:
9, 'Zaheer, 36, 'Computer, 12/03/97}, 230, 'M

Ans: INSERT INTO Student
VALUES (9, 'Zaheer, 'Computer, 12/03/97}, 230, 'M);














































PRACTICAL NO.- 04

AIM
Write SQL commands on the basis oI table MOVIE.


Table: MOVIE
No. Title Type Rating Stars Qty. Price
1 Gone with the wind Drama G Gable 4 39.95
2 Friday the 13
th
Horror R Jason 2 69.95
3 Top Gun Drama PG Cruise 7 49.95
4 Splash Comedy PG13 Hanks 3 29.95
5 Independence Day Drama R Turner 3 19.95
6 Risky Business Comedy R Cruise 2 44.95
7 Cocoon SciIi PG Ameche 2 31.95
8 Crocodile Dundee Comedy PG13 Harris 2 69.95
9 101 Dalmatians Comedy G 3 59.95
10 Tootsie Comedy PG HoIIman 1 29.95


(a) Find the total value oI the movie cassettes available in the library.

Ans: SELECT sum(Qty*Price)Total value
FROM movie;

(b)Display a list oI all movies with Price over 20 and sorted by Price.

Ans: SELECT title
FROM movie
WHERE price~20
ORDER by price;

(c) Display all the movies sorted by QTY in decreasing order.

Ans: SELECT title
FROM movie
ORDER by qty desc;

(d)Display a report listing a movie number, current value and replacement value Ior each movie in
the above table. Calculate the replacement value Ior all movies as
QTY*Price * 1.15

Ans: SELECT movie no., price `current value`, qty*price*1.15`repl value`
FROM movie;

(e) Count the number oI movies where Rating is not 'G.

Ans: SELECT Count(*)
FROM movie
WHERE rating ~`G`;
(I) Insert a new movie in the MOVIE table. Fill all the columns with values.

Ans: SELECT into movie
VALUES(11,` predator`,`sciIi`,`R`, arnold schwarzenegger`,5,50.79);















































PRACTICAL NO.- 05

AIM
Write SQL commands on the basis oI table FURNITURE.

Table: FURNITURE
No. Item name Type Date oI
stock
Price Discount
1 White lotus Double Bed 23/02/02 30000 25
2 Pink Ieather Baby cot 20/01/02 7000 20
3 Dolphin Baby cot 19/02/02 9500 20
4 Decent OIIice Table 01/01/02 25000 30
5 ComIort zone Double Bed 12/01/02 25000 25
6 Donald Baby cot 24/02/02 6500 15
7 Royal Finish OIIice Table 20/02/02 18000 30
8 Royal tiger SoIa 22/02/02 31000 30
9 Econo sitting SoIa 13/12/01 9500 25
10 Eating paradise Dining Table 19/02/02 11500 25


Table: ARRIVALS
No. Item name Type Date oI
stock
Price Discount
1 Wood comIort Double Bed 23/03/03 25000 25
2 Old Fox SoIa 20/02/03 17000 20
3 Micky Baby cot 21/02/03 7500 15



(a) To show all inIormation about the Baby cots Irom the FURNITURE table.

Ans: SELECT *
From FURNITURE
WHERE TYPE 'Baby cot;

(b)To list the ITEMNAME which are priced at more than 15000 Irom the FURNITURE table.

Ans: SELECT ITEMNAME
From FURNITURE
WHERE PRICE ~ 15000;

(c) To list the ITEMNAME and TYPE oI those items in which DATEOFSTOCK is beIore 22/01/02
Irom the FURNITURE table in descending order oI ITEMNAME.

Ans: SELECT ITEMNAME, TYPE
From FURNITURE
WHERE DATEOFSTOCK 22/01/02}
ORDER BY ITEMNAME;

(d)To display ITEMNAME and DATEOFSTOCK oI those items, in which the DISCOUNT
percentage is more than 25 Irom FURNITURE table.

Ans: SELECT ITEMNAME, DATEOFSTOCK
From FURNITURE
WHERE DISCOUNT ~ 25;

(e) To count the number oI items, whose TYPE is 'SoIa Irom FURNITURE table.

Ans: SELECT COUNT (*)
FROM FURNITURE
WHERE TYPE 'SoIa;

(I) To insert new row in the ARRIVALS table with the Iollowing data.
14, 'Velvet touch, 'Double Bed, 25/03/03}, 25000, 30

Ans: INSERT INTO ARRIVALS
VALUES (14, 'Velvet touch, 'Double Bed, 25/03/03}, 25000, 30);

























PRACTICAL NJ.- 6.1

AIM-
PRJGRAM TJ CHECK WHETHER THE GIVEN CHARACTER IS LJWER CASE JR UPPER CASE .

CJDING-
#include<iostream.h
#include<conio.h
#include<ctype.h
void main()
,
clrscr();
char ch;
cout<<"\n Enter a character \n ";
cinch;
if(isalpha(ch))
,
if(isupper(ch))
,
cout<<"\n\n Upper case!!!!!\n";
,
else if(islower)
,
cout<<"\n\n Lower case!!!!!\n";
,
,
else
,
cout<<"\n\n Not an alphabet!!!!!!\n";
,
getch();
,

JUTPUT-


PRACTICAL NJ.- 6.2

AIM-
PRJGRAM TJ CJNVERT UPPERCASE STRING TJ LJWERCASE AND VICE-VERSA .

CJDING-
#include<iostream.h
#include<conio.h
#include<ctype.h
#include<string.h
void main()
,
clrscr();
char str25,;
int flag=1;
cout<<"\n\n Enter a string MAX 25 CHARACTER,\n ";
cin.getline(str,25);
for(int i=0;stri,!='\0';i++)
,
if(isupper(stri,))
,
flag=0;
stri,=tolower(stri,);
,
else if(islower(stri,))
,
flag=1;
stri,=toupper(stri,);
,
,
if(flag==0)
,
int x2=strlen(str);
cout<<" lowercase string is :\n "<<str;
,
else if(flag==1)
,
int x1=strlen(str);
cout<<" uppercase string is :\n "<<str;
,
getch();
,

JUTPUT-




PRACTICAL NJ.- 6.3

AIM-
PRJGRAM TJ READ TWJ STRINGS AND APPEND THE FIRST STRING TJ SECJND .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
void main()
,
clrscr();
char str125,,str250,;
cout<<"\n\n Enter string 1 (max 25 character ) \n ";
cin.getline(str1,25);
cout<<"\n Enter string 2 (max 25 character) \n ";
cin.getline(str2,25);
strcat(str2,str1);
int len=strlen(str2);
cout<<str2;
getch();
,

JUTPUT-


PRACTICAL NJ.- 6.4

AIM-
PRJGRAM TJ READ A PASSWJRD AND PRINT `ok' IF CJRRECT PASSWJRD ELSE `sorry',
THE USER SHJULD BE GIVEN THREE CHANCES .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
void main()
,
clrscr();
char pass20,;
for(int i=0;i<3;i++)
,
cout<<"\n\n Enter password passwords are case sensitive, \n ";
cin.getline(pass,20);
if(strcmp(pass,"PACE"))
cout<<"\n Sorry incorrect password....ACCESS DENIED, \n ";
else
,
cout<<"\n\n\n\t\t\tJK........ACCESS GRANTED, \n";
break;
,
,
getch();
,

JUTPUT-





PRACTICAL NJ.- 6.5

AIM-
PRJGRAM TJ CHECK WHETHER THE GIVEN CHARACTER IS DIGIT JR ALPHABETIC JR
SPECIAL CHARACTER .


CJDING-
#include<iostream.h
#include<conio.h
#include<ctype.h
#include<stdlib.h
#include<string.h
void main()
, clrscr();
char ch;
int a;
cout<<"\n\n Enter a character - ";
cinch;
a=ch;
if(isdigit(a))
,
cout<<"\n Digit character!!!!!!\n";
,
else
if(isalpha(a))
,
cout<<"\n Alphabetic character!!!!!!\n";
,
else
,
cout<<"\n Special character!!!!!!!\n";
,
getch();
,

JUTPUT-








PRACTICAL NJ.- 7.1

AIM-
PRJGRAM TJ TAKE 2 MATRIX AND PRINT THEIR SUM & DIFFERENCE .

CJDING-
#include<iostream.h
#include<conio.h
void main()
, clrscr();
int a3,3,,b3,3,,c3,3,;
cout<<"Enter the first matrix\n\n";
for(int i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cinai,j,;
cout<<"\n";
,
cout<<"Enter the 2nd matrix\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cinbi,j,;
cout<<"\n";
,
cout<<"1st marix is\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<ai,j,<<" \t";
cout<<"\n";
,
cout<<"2nd matrix is\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<bi,j,<<"\t";
cout<<"\n";
,
cout<<"Sum of two matrix is\n\n";
,
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
ci,j,=ai,j,+bi,j,;
,
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<ci,j,<<" \t";
cout<<"\n";
,
,
cout<<"Difference of two matrix is\n\n";
,
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
ci,j,=ai,j,-bi,j,;
,

for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<ci,j,<<" \t";
cout<<"\n";
,
,
getch();
,

JUTPUT-






























PRACTICAL NJ.- 7.2

AIM-
PRJGRAM TJ TAKE 2 MATRIX AND PRINT THEIR PRJDUCT .

CJDING-
#include<iostream.h
#include<conio.h
void main()
, clrscr();
int a3,3,,b3,3,,c3,3,;
cout<<"Enter the first matrix\n\n";
for(int i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cinai,j,;
cout<<"\n";
,
cout<<"Enter the 2nd matrix\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cinbi,j,;
cout<<"\n";
,
cout<<"1st marix is\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<ai,j,<<" \t";
cout<<"\n";
,
cout<<"2nd matrix is\n\n";
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<bi,j,<<"\t";
cout<<"\n";
,
cout<<"Product of two matrix is\n\n";
,
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
ci,j,=ai,j,bi,j,;
,
for(i=0;i<3;i++)
,
for(int j=0;j<3;j++)
cout<<ci,j,<<" \t";
cout<<"\n";
,
,
getch();
,





JUTPUT-


































PRACTICAL NJ.- 7.3

AIM-
PRJGRAM TJ MAKE THE TRANSPJSE JF THE MATRIX .

CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int i,j,a3,3,,temp;
cout<<"Enter the matrix :\n";
for (i=0;i<3;i++)
, for(j=0;j<3;j++)
, cinai,j,;
cout<<"\n";
,
,
for (i=0;i<3;i++)
, for(j=0;j<3;j++)
, if(i<j)
, temp=ai,j,;
ai,j,=aj,i,;
aj,i,=temp;
,
,
,
cout<<"\nTranspose of a matrix is: \n";
for (i=0;i<3;i++)
, for(j=0;j<3;j++)
, cout<<ai,j,<<"\t\t";
,
cout<<"\n";
,
getch();
,

JUTPUT-









PRACTICAL NJ.- 7.4

AIM-
PRJGRAM TJ FIND THE SUM JF UPPER DIAGJNAL, LJWER DIAGJNAL & MAIN DIAGJNAL
ELEMENTS .

CJDING-
#include<iostream.h
#include<conio.h
void main()
, clrscr();
int a3,3,,i,j,s1=0,s2=0,s3=0;
cout<<" Enter the matrix: \n";
for(i=0;i<3;i++)
, for(j=0;j<3;j++)
cinai,j,;
cout<<"\n";
,
for(i=0;i<3;i++)
, for(j=0;j<3;j++)
, if(i<j)
, s1=s1+ai,j,;
,
else
if(i==j)
,s2=s2+ai,j,;
,
else
,s3=s3+ai,j,;
,
,
,
cout<<" The Matrix is ... \n";
for(i=0;i<3;i++)
, for(j=0;j<3;j++)
cout<<ai,j,<<" ";
cout<<"\n";
,
cout<<"\nSum of upper diagonal elements is: "<<s1<<"\n";
cout<<"\nSum of lower diagonal elements is: "<<s3<<"\n";
cout<<"\nSum of main diagonal is: "<<s2;
getch();
,

JUTPUT-


PRACTICAL NJ.- 8

AIM-
To illustrate passing of a structure to a function by call by value method .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
struct distance
, int feet;
int inches;
,;
void main()
, clrscr();
distance length1,length2;
void prnsum(distance l1,distance l2);
cout<<"\n\n Enter lenght1 ...";
cout<<"\n Feet - ";
cinlength1.feet;
cout<<"\n Inches - ";
cinlength1.inches;
cout<<"\n\n Enter length2 ...";
cout<<"\n Feet - ";
cinlength2.feet;
cout<<"\n Inches - ";
cinlength2.inches;
prnsum(length1,length2);
getch();
,
void prnsum(distance l1,distance l2)
, distance l3;
l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;
l3.inches=(l1.inches+l2.inches)%12;
cout<<"\n\n Total Feet - "<<l3.feet;
cout<<"\n Total Inches - "<<l3.inches;
getch();
,

JUTPUT-






PRACTICAL NJ.- 9

AIM-
Declare a class to represent the bank accounts of 10 customers.

CJDING-
#include<ctype.h
#include<iostream.h
#include<string.h
#include<conio.h
class account
,
char name31,;
int acc_no;
char act;
float balance;
public:
void initial()
,
cout<<"\n\n NAME - ";
cin.getline(name,31);
cout<<"\n ACCJUNT NUMBER - ";
cinacc_no;
int cc=1;
while(cc)
,
cout<<"\n ACCJUNT TYPE SAVING/CURRENT(S/C) - ";
cinact;
if((toupper(act)=='S'||toupper(act)=='C'))
break;
else
cout<<"\n ENTER S JR C JNLY!! ";
,;
act=toupper(act);
cout<<"\n BALANCE - ";
cinbalance;
cout<<endl;
getch();
,
void deposit();
void withdraw();
void display();
float getbal()
,
return balance;
,
int getacno()
,
return acc_no;
,
,;
void account::deposit()
,
float amt;
cout<<" AMJUNT TJ BE DEPJSITED"<<endl;
cinamt;
balance+=amt;
cout<<" AMJUNT DEPJSITED - "<<endl;
cout<<amt;
getch();
,
void account::withdraw()
, clrscr();
float amt;
cout<<"\n\n ENTER AMJUNT TJ BE WITHDRAWN"<<endl;
cinamt;
if((balance-amt=1000))
,
balance-=amt;
cout<<"\n AMJUNT WITHDRAWN-";
cout<<amt;
getch();
,
else
,
cout<<"\n MINIMUM BALANCE HAS TJ BE Rs. 1000/- "<<endl;
cout<<"\n YJU CAN WITHDRAW JNLY - Rs."<<balance-1000<<endl;
cout<<"\n PRESS A KEY TJ CJNTINUE... ";
getch();
,
,
void account::display()
,
cout<<" ACCJUNT NUMBER - "<<acc_no<<endl;
cout<<" ACCJUNT HJLDER - "<<name<<endl;
cout<<" ACCJUNT TYPE - "<<act<<endl;
cout<<" BALANCE - Rs."<<balance<<endl;
getch();
,
void main()
,
clrscr();
account bk_acc;
bk_acc.initial();
bk_acc.deposit();
bk_acc.withdraw();
bk_acc.display();
,

JUTPUT-





PRACTICAL NJ.- 10

AIM-
Define a class to represent a book in a library .

CJDING-
#include<iostream.h
#include<conio.h
#include<stdio.h
class library
, int bno;
char name20,;
char author20,;
char publisher20,;
float price;
int ncop;
int ncopiss;
int ncopdeposit;
public:
void initialise();
void issue();
void deposit();
void display();
,;
void library::initialise()
, cout<<"\n Book no - ";cinbno;
cout<<"\n Name of author - ";gets(author);
cout<<"\n Name of publisher - ";gets(publisher);
cout<<"\n Price of 1 book - ";cinprice;
cout<<"\n No. of same books in library - ";cinncop;
cout<<"\n No. of books issued - ";cinncopiss;
cout<<"\n No. of books diposited - ";cinncopdeposit;
,
void library::issue()
, ncop-=ncopiss;
,
void library::deposit()
, ncop+=ncopdeposit;
,
void library::display()
, clrscr();
cout<<"!!!!!!!!LIBRARY!!!!!!";
cout<<"\n Book no - ";cout<<bno;
cout<<"\n Name of author - ";puts(author);
cout<<"\n Name of publisher - ";puts(publisher);
cout<<"\n Price of 1 book - Rs.";cout<<price;
cout<<"\n No. of books in library - ";cout<<ncop;
cout<<"\n No. of books issued - ";cout<<ncopiss;
cout<<"\n No. of books diposited - ";cinncopdeposit;
getch();
,
void main()
, clrscr();
library b1;
cout<<"\n Enter details of book...\n";
b1. initialise();
b1. issue();
b1. display();
b1. deposit();
b1. display();
,

JUTPUT-







































PRACTICAL NJ.- 11

AIM-
Define a class travel plan .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
class travelplan
,
char t_code5,;
int no_of_adults;
int no_of_children;
int distance;
float totalfare;
public:
travelplan()
,
strcpy(t_code,"NULL");
no_of_adults=0;
no_of_children=0;
distance=0;
totalfare=0;
,
void assignfare()
,
float fare=0;
if(distance=1000)
,
fare=no_of_adults500 + no_of_children250;
,
else
if(distance=500)
,
fare=no_of_adults500 + no_of_children250;
,
else
,
fare=no_of_adults500 + no_of_children250;
,
totalfare=fare;
,
void entertravel()
,
cout<<"\n\n ENTER VALUE JF TRAVEL CJDE - ";
cint_code;
cout<<"\n ENTER NUMBER JF ADULTS - ";
cinno_of_adults;
cout<<"\n ENTER NUMBER JF CHILDREN - ";
cinno_of_children;
cout<< "\n ENTER DISTANCE - ";
cindistance;
assignfare();
,
void showtravel()
,
cout<<"\n\n TRAVEL CJDE - "<<t_code<<endl;
cout<<"\n NUMBER JF ADULTS - "<<no_of_adults<<endl;
cout<<"\n NUMBER JF CHILDREN - "<<no_of_children<<endl;
cout<<"\n DISTANCE - "<<distance<<" Kms"<<endl;
cout<<"\n TJTAL FARE - "<<totalfare<<endl;
,
,;
void main()
,
clrscr();
travelplan tlp;
tlp.entertravel();
tlp.showtravel();
getch();
,

JUTPUT-

































PRACTICAL NJ.- 12

AIM-
PRJGRAM TJ SHJW WJRKING JF VIRTUAL BASE CLASS .

CJDING-
#include<iostream.h
#include<conio.h
class base
, public:
int a;
,;
class d1: virtual public base
, public:
int b;
,;
class d2: virtual public base
, public:
int c;
,;
class d3: public d1,public d2
, public:
int total;
,;
int main()
,
clrscr();
d3 ob;
ob.a=25;
ob.b=50;
ob.c=75;
ob.total=ob.a+ob.b+ob.c;
cout<<"\n\n"<<ob.a<<"\t"<<ob.b<<"\t"<<ob.c<<"\t"<<ob.total<<endl;
getch();
,

JUTPUT-
















PRACTICAL NJ.- 13

AIM-
PRJGRAM TJ FIND A NUMBER IN THE ARRAY USING LINEAR SEARCH .


CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int ch,l,u,mid,c=0,i,n,e,a50,;
cout<<"\n\n Enter the size of array MAX 50,..."<<endl;
cinn;
cout<<endl<<"\n Enter the elements..."<<endl;
for(i=0;i<n;i++)
,
cinai,;
,
cout<<"\n\n Enter the element to be searched for...."<<endl;
cine;
for(i=0;i<n;i++)
,
if(ai,==e)
,
cout<<endl<<" Element is at "<<i+1<<" Position \n";
c=c++;
break;
,
,
if(c==0)
,
cout<<" Element Not Present \n";
,
getch();
,

JUTPUT-



PRACTICAL NJ.- 14

AIM-
PRJGRAM TJ FIND A NUMBER IN THE ARRAY USING BINARY SEARCH .

CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int beg,mid,last,no,i,a10,;
cout<<"\n ENTER ANY 10 NJ.'S - ";
for(i=0;i<10;i++)
,
cinai,;
,
cout<<"\n ENTER NJ. WHICH YJU WANT TJ FIND - ";
cinno;
beg=0; last=9;
while(beg<=last)
,
mid=(beg+last)/2;
if(no==amid,)
,
cout<<"\n NJ. FJUND AT PJSITIJN - "<<mid+1;
break;
,
else
if(no<amid,)
,
last=mid-1;
,
else
if(noamid,)
,
beg=mid+1;
,
,
if(beglast)
,
cout<<"\n NJ. NJT FJUND . . . ....";
,
getch();
,















JUTPUT-





PRACTICAL NJ.- 15

AIM-
Insertion in sorted array .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
int findpos(int,,int,int);
void main()
,
clrscr();
int ar50,,item,n,index;
cout<<"\n\n How many elements do u want to create array with. MAX 50,... ";
cinn;
cout<<"\n Enter array elements MUST BE SJRTED IN ASCENDING JRDER,..\n ";
for(int i=0;i<n;i++)
cinari,;
char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n Enter element to be inserted...";
cinitem;
if(n==50)
,
cout<<" Jverflow!!\n";
exit(1);
,
index=findpos(ar,n,item);
for(i=n;iindex;i--)
,
ari,=ari-1,;
,
arindex,=item;
n+=1;
cout<<"\n Want to insert more elements. (y/n).. ";
cinch;
,
cout<<"\n Result..\n ";
for(i=0;i<n;i++)
cout<<ari,<<" ";
cout<<endl;
getch();
,
int findpos(int ar,,int size,int item)
, int pos;
if(item<ar0,)
pos=0;
else
, for(int i=0;i<size-1;i++)
,
if(ari,<=item&&item<ari+1,)
, pos=i+1;
break;
,
,
if(i==size-1)pos=size;
,
return pos;
,
JUTPUT-






































PRACTICAL NJ.- 16

AIM-
Deletion in array .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
int lsearch(int,,int,int);
void main()
, clrscr();
int ar50,,item,n,index;
cout<<"\n\n How many elements do u want to create array with. MAX 50,....
";
cinn;
cout<<"\n Enter elements... ";
for(int i=0;i<n;i++)
cinari,;
char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n Enter element to be deleted .... : ";
cinitem;
if(n==0)
,
cout<<" Underflow!!\n";
exit(1);
,
index=lsearch(ar,n,item);
if(index!=-1)
,
arindex,=0;
,
else
cout<<"\n Element not found !!!!!";
cout<<"\n\n Result : \n";
cout<<" Zero (0) signifies deleted element \n ";
for(i=0;i<n;i++)
cout<<ari,<<" ";
endl;
cout<<"\n\n After this empty space will be shifted to the end of array
\n";
for(i=index;i<n;i++)
,
ari,=ari+1,;
,
n-=1;
cout<<" Want to delete more elements. (y/n)..... ";
cinch;
,
cout<<"\n\n Result : \n ";
for(i=0;i<n;i++)
cout<<ari,<<" ";
cout<<endl;
getch();
,
int lsearch(int ar,,int size,int item)
,
for(int i=0;i<size;i++)
,
if(ari,==item)
return i;
,
return -1;
,

JUTPUT-







































PRACTICAL NJ.- 17

AIM-
PRJGRAM TJ JRGANISE THE NUMBERS IN THE ARRAY USING SELECTIJN SJRT .

CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int i,j,min,temp,pos,a10,;
cout<<"ENTER AN ARRAY JF 10 ELEMENTS - ";
for(i=0;i<10;i++)
,
cinai,;
,
for(i=0;i<=9;i++)
,
min=ai,; pos=i;
for(j=i+1;j<=9;j++)
,
if(aj,<min)
,
min=aj,;
pos=j;
,
,
temp=ai,;
ai,=apos,;
apos,=temp;
,
cout<<"\n RESULT - ";
for(i=0;i<10;i++)
,
cout<<ai,<<" ";
,
getch();
,

JUTPUT-











PRACTICAL NJ.- 18

AIM-
PRJGRAM TJ JRGANISE THE NUMBERS IN THE ARRAY USING BUBBLE SJRT .

CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int i,j,temp,a10,;
cout<<"ENTER AN ARRAY JF 10 ELEMENTS - ";
for(i=0;i<=9;i++)
,
cinai,;
,
for(i=0;i<10-1;i++)
,
for(j=0;j<=(9-i)-1;j++)
,
if(aj,aj+1,)
,
temp=aj,;
aj,=aj+1,;
aj+1,=temp;
,
,
,
cout<<"\n RESULT - ";
for(i=0;i<10;i++)
,
cout<<ai,<<" ";
,
getch();
,
JUTPUT-















PRACTICAL NJ.- 19

AIM-
PRJGRAM TJ JRGANISE THE NUMBERS IN THE ARRAY USING INSERTIJN SJRT .

CJDING-
#include<iostream.h
#include<conio.h
void main()
,
clrscr();
int i,j,k,a10,,no,pos;
cout<<"\n ENTER ANY 10 ELEMENT'S - ";
for(i=0;i<10;i++)
,
cinai,;
,
for(i=1;i<10;i++)
,
no=ai,;
pos=i;
for(j=0;j<i;j++)
,
if(aj,=no)
,
pos=j;
break;
,
,
for(k=i;kpos;k--)
,
ak,=ak-1,;
,
apos,=no;
,
cout<<"\n RESULT";
for(i=0;i<10;i++)
,
cout<<ai,<<" ";
,
getch();
,

JUTPUT-










PRACTICAL NJ.- 20

AIM-
PRJGRAM TJ ASSIGN THE SIZE JF 2 ARRAYS AND CJMBINE THEM USING MERGING .

CJDING-
#include<iostream.h
#include<conio.h
void main()
, clrscr();
int i,j,k,m,n,a10,,b10,,c20,;
cout<<"\n ENTER THE TWJ VALUES - ";
cinmn;
cout<<"\n ENTER AN ARRAY JF "<<m<<" ELEMENTS - ";
for(i=0;i<m;i++)
, cinai,;
,
cout<<"\n ENTER AN ARRAY JF "<<n<<" ELEMENTS - ";
for(j=0;j<n;j++)
, cinbj,;
,
i=0; j=0; k=0;
while(i<m && j<n)
, if(ai,<=bj,)
, ck,=ai,;
k++; i++;
,
else
, ck,=bj,;
k++; j++;
,
,
while(i<m)
, ck,=ai,;
k++; i++;
,
while(j<n)
, ck,=bj,;
k++; j++;
,
cout<<"\n RESULT - ";
for(i=0;i<m+n;i++)
, cout<<ci,<<" ";
,
getch();
,

JUTPUT-



PRACTICAL NJ.- 21

AIM-
Program to create two arrays to store roll number and marks of some students
whose number would be known at run time .

CJDING-
#include<iostream.h
#include<conio.h
introllno;
floatmarks;
void main()
,
clrscr();
int size;
cout<<"\n\n How many elements are there in the array . \n";
cinsize;
rollno=new intsize,;
marks=new floatsize,;
if((!rollno)||(!marks))
,
cout<<" Jut of memory ! Aborting";
getch();
,
for(int i=0;i<size;i++)
,
cout<<"\n Enter Roll number & marks for student"<<(i+1)<<"\n\t";
cinrollnoi,marksi,;
,
cout<<"\n\troll number\tmarks\n";
for(i=0;i<size;i++)
,
cout<<"\t"<<rollnoi,<<"\t\t"<<marksi,<<"\n";

,
delete,rollno;
delete,marks;
getch();
,

JUTPUT-





PRACTICAL NJ.- 22

AIM-
Program to exchange position of strings using pointer .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
void main()
,
clrscr();
charnames,=,"Sachin","Kapil","Ajay","Sunil","Anil",;
int len=0;
len=strlen(names1,);
cout<<"\n\n Jriginaly string 2 is ";
cout.write(names1,,len).put('\n');
cout<<"\n and string 4 is ";
cout.write(names3,,len).put('\n');
chart;
t=names1,;
names1,=names3,;
names3,=t;
len=strlen(names1,);
cout<<"\n Exchange string 2 is ";
cout.write(names1,,len).put('\n');
cout<<"\n and string 4 is ";
cout.write(names3,,len).put('\n');
getch();
,

JUTPUT-













PRACTICAL NJ.- 23

AIM-
Program to show the working of THIS pointer .

CJDING-
#include<iostream.h
#include<conio.h
#include<string.h
class salesman
,
char name10,;
float total_sales;
public:
salesman(chars,float f)
,
strcpy(name,"");
strcpy(name,s);
total_sales=f;
,
void prnobject(void)
,
cout.write(this-name,9);
cout<<"\thas invokedprnobject().\n";
,
,;
void main()
,
clrscr();
salesman Raman("\n\n Raman",21450),Sita("\n Sita",23190),Vedant("\n
Vedant",19142);
Raman.prnobject();
Vedant.prnobject();
Sita.prnobject();
getch();
,

JUTPUT-









PRACTICAL NJ.- 24.1

AIM-
PRJGRAM TJ INSERT NJDES FRJM BEGINNING JF THE LINKED LIST .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node,
int info;
Nodenext;
, start,newptr,save,ptr;
NodeCreate_New_Node(int);
void Insert_Beg(Node);
void Display(Node);
void main()
,
start=NULL;
int inf; char ch='y';
while (ch=='y'||ch=='Y')
,
clrscr();
cout<<"\n\n ENTER INFJRMATIJN FJR THE NEW NJDE...";
cininf;
cout<<"\n\n CREATING NEW NJDE!! PRESS ENTER TJ CJNTINUE...";
getch();
newptr=Create_New_Node(inf);
if(newptr!=NULL)
,
cout<<"\n\n NEW NJDE CREATED SUCCESSFULLY. PRESS ENTER TJ
CJNTINUE...";
getch();
,
else
,
cout<<"\n CANNJT CREATED NEW NJDE!!! ABJRTING!!\n";
getch();
exit(1);
,
cout<<"\n\n NJW INSERTING THIS NJDE IN THE BEGINNING JF THE
LIST...\n";
cout<<" PRESS ENTER TJ CJNTINUE...\n";
getch();
Insert_Beg(newptr);
cout<<"\n NJW THE LIST IS : \n";
Display(start);
cout<<"\n PRESS Y TJ ENTER MJRE NJDES, N TJ EXIT...\n";
cinch;
,
,
NodeCreate_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Insert_Beg(Nodenp)
,
if(start==NULL)
start=np;
else
,
save=start;
start=np;
np-next=save;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<" - ";
np=np-next;
,
cout<<" !!! \n";
,

JUTPUT-















PRACTICAL NJ.- 24.2

AIM-
PRJGRAM TJ INSERT NJDES AT THE END JF LINKED LIST .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node
, int info;
Node next;
, start,newptr,save,ptr,rear;
Node Create_New_Node(int);
void Insert_End(Node);
void Display(Node);
void main()
,
start=rear=NULL;
int inf; char ch='y';
while(ch=='y'||ch=='Y')
,
clrscr();
cout<<"\n\n Enter Information for the new node - ";
cininf;
cout<<"\n Creating New node!! Press enter to continue...";
getch();
newptr=Create_New_Node(inf);
if(newptr!=NULL)
,
cout<<"\n\n New node created successfully.\n";
cout<<" Press enter to continue...";
getch();
,
else
,
cout<<"\n Connot create a new node!!...\n";
getch();
exit(1);
,
cout<<"\n\n Now inserting this node in the end of the list...\n";
cout<<" Press enter to continue...\n";
getch();
Insert_End(newptr);
cout<<"\n Now the list is :\n";
Display(start);
cout<<"\n Press Y to enter more nodes,N to exit..\n";
cinch;
,
,
Node Create_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Insert_End( Node np)
,
if (start==NULL)
start=rear=np;
else
,
rear-next=np;
rear=np;
,
,
void Display(Node np)
,
while(np!=NULL)
,
cout<<np-info<<"-";
np=np-next;
,
cout<<"!!!\n";
,

JUTPUT-





PRACTICAL NJ.- 24.3

AIM-
PRJGRAM TJ DELETE NJDES FRJM BEGINNING JF THE LINKED LIST .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node
, int info;
Node next;
, start,newptr,save,ptr,rear;
Node Create_New_Node(int);
void Insert(Node);
void Display(Node);
void DelNode();
void main()
,
clrscr();
start=rear=NULL;
int inf; char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n\n Enter Information for the new node - ";
cininf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
,
cout<<"\n Connot create a new node!!! Aborting!!...\n";
getch();
exit(1);
,
Insert(newptr);
cout<<"\n Press Y to enter more nodes,N to exit..\n";
cinch;
,
clrscr();
do
,
cout<<"\n The list now is : \n";
Display(start);
getch();
cout<<" Want to delete the first node.(y/n)...";
cinch;
if(ch=='y'||ch=='Y')DelNode();
,
while(ch=='y'||ch=='Y');
,
Node Create_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Insert(Nodenp)
,
if (start==NULL)
start=rear=np;
else
,
rear-next=np;
rear=np;
,
,
void DelNode()
,
if (start==NULL)
cout<<" UNDERFLJW!!! \n";
else
,
ptr=start;
start=start-next;
delete ptr;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<"-";
np=np-next;
,
cout<<"!!!\n";
,

JUTPUT-







PRACTICAL NJ.- 25.1

AIM-
PRJGRAM TJ INSERT NJDES IN LINKED STACK .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node,
int info;
Nodenext;
, top,newptr,save,ptr;
NodeCreate_New_Node(int);
void Push(Node);
void Display(Node);
void main()
,
clrscr();
int inf; char ch='y';
top=NULL;
while (ch=='y'||ch=='Y')
,
clrscr();
cout<<"\n\n ENTER INFJRMATIJN FJR THE NEW NJDE...";
cininf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
,
cout<<"\n CANNJT CREATED NEW NJDE!!! ABJRTING!!\n";
exit(1);
,
Push(newptr);
cout<<"\n NJW THE LINKED-STACK IS : \n";
Display(top);
cout<<"\n PRESS Y TJ ENTER MJRE NJDES, N TJ EXIT...\n";
cinch;
,
,
NodeCreate_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Push(Nodenp)
,
if(top==NULL)
top=np;
else
,
save=top;
top=np;
np-next=save;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<" - ";
np=np-next;
,
cout<<" !!! \n";
,

JUTPUT-





PRACTICAL NJ.- 25.2

AIM-
PRJGRAM TJ DELETE NJDES FRJM THE LINKED STACK .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node
, int info;
Node next;
, top,newptr,save,ptr;
NodeCreate_New_Node(int);
void Push(Node);
void Display(Node);
void Pop();
void main()
,
clrscr();
top=NULL;
int inf; char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n\n Enter Information for the new node - ";
cininf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
,
cout<<"\n Connot create a new node!!! Aborting!!...\n";
getch();
exit(1);
,
Push(newptr);
cout<<"\n Press Y to enter more nodes,N to exit..\n";
cinch;
,
clrscr();
do
,
cout<<"\n The list now is : \n";
Display(top);
getch();
cout<<" Want to pop an element.(y/n)...";
cinch;
if(ch=='y'||ch=='Y')Pop();
,
while(ch=='y'||ch=='Y');
,
NodeCreate_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Push(Nodenp)
,
if (top==NULL)
top=np;
else
,
save=top;
top=np;
np-next=save;
,
,
void Pop()
,
if (top==NULL)
cout<<" UNDERFLJW!!! \n";
else
,
ptr=top;
top=top-next;
delete ptr;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<"-";
np=np-next;
,
cout<<"!!!\n";
,

JUTPUT-




PRACTICAL NJ.- 26.1

AIM-
PRJGRAM TJ INSERT NJDES IN LINKED QUEUE .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node
,
int info;
Nodenext;
,front, newptr, save, ptr, rear;
NodeCreate_New_Node(int);
void Insert_End(Node);
void Display(Node);
void main()
,
clrscr();
front=rear=NULL;
int inf; char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n\n Enter information for the new node... ";
cininf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
,
cout<<" Cannot create new node!!! Aborting!! \n";
exit(1);
,
Insert_End(newptr);
cout<<" Now the QUEUE(Front...to...Rear) is - \n ";
Display(front);
cout<<"\n Press Y to enter more nodes, N to exit... ";
cinch;
,
getch();
,
NodeCreate_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Insert_End(Nodenp)
,
if(front==NULL)
,
front=rear=np;
,
else
,
rear-next=np;
rear=np;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<" - ";
np=np-next;
,
cout<<"!!!\n";
,

JUTPUT-



PRACTICAL NJ.- 26.2

AIM-
PRJGRAM TJ DELETE NJDES FRJM LINKED QUEUE .

CJDING-
#include<iostream.h
#include<conio.h
#include<process.h
struct Node
,
int info;
Nodenext;
,front, newptr, save, ptr, rear;
NodeCreate_New_Node(int);
void Insert(Node);
void Display(Node);
void DelNode_Q();
void main()
,
clrscr();
front=rear=NULL;
int inf; char ch='y';
while(ch=='y'||ch=='Y')
,
cout<<"\n\n Enter information for the new node... ";
cininf;
newptr=Create_New_Node(inf);
if(newptr==NULL)
,
cout<<" Cannot create new node!!! Aborting!! \n";
exit(1);
,
Insert(newptr);
cout<<"\n Press Y to enter more nodes, N to exit... ";
cinch;
,
clrscr();
do
,
cout<<"\n The LINKED-QUEUE now is(Front...to...Rear) - \n ";
Display(front);
cout<<"\n Want to delete first node. (y/n)...";
cinch;
if(ch=='y'||ch=='Y')
,
DelNode_Q();
,
,
while(ch=='y'||ch=='Y');
getch();
,
NodeCreate_New_Node(int n)
,
ptr=new Node;
ptr-info=n;
ptr-next=NULL;
return ptr;
,
void Insert(Nodenp)
,
if(front==NULL)
,
front=rear=np;
,
else
,
rear-next=np;
rear=np;
,
,
void DelNode_Q()
,
if(front==NULL)
,
cout<<" UNDERFLJW !!! \n";
,
else
,
ptr=front;
front=front-next;
delete ptr;
,
,
void Display(Nodenp)
,
while(np!=NULL)
,
cout<<np-info<<" - ";
np=np-next;
,
cout<<"!!!\n";
,

JUTPUT-




PRACTICAL NJ.- 27

AIM-
PRJGRAM FJR READING AND WRITING CLASS JBJECTS .

CJDING-
#include<fstream.h
#include<conio.h
class student
,
char name40,;
char grade;
float marks;
public:
void getdata(void);
void display(void);
,;
void student::getdata(void)
,
char ch;
cin.get(ch);
cout<<"\n Enter name - \n";
cin.getline(name,40);
cout<<"\n Enter grade - \n";
cingrade;
cout<<"\n Enter marks - \n";
cinmarks;
cout<<"\n";
,
void student::display(void)
,
cout<<" Name - "<<name<<"\n";
cout<<" Grade - "<<grade<<"\n";
cout<<" Marks - "<<marks<<"\n";
,
void main()
,
clrscr();
student arts3,;
fstream filin;
filin.open("stu.dat",ios::in|ios::out);
if (!filin)
,
cout<<"cannot open file !!\n";
getch();
,
cout<<"\n\n Enter details for students \n";
for(int i=0;i<3;i++)
,
artsi,.getdata();
filin.write((char)&artsi,,sizeof(artsi,));
,
filin.seekg(0);
cout<<" The contents of stu.dat are shown below. \n";
for(i=0;i<3;i++)
,
filin.read((char)&arts,sizeof(artsi,));
artsi,.display();
getch();
,
filin.close();
,

JUTPUT-



PRACTICAL NJ.- 28

AIM-
PRJGRAM TJ DELETE A RECJRD FRJM A FILE .

CJDING-
#include<fstream.h
#include<stdio.h
#include<string.h
#include<conio.h
class stu
,
int rollno;
char name25,;
float marks;
char grade;
public:
void getdata()
,
cout<<"\n Roll no. - ";
cinrollno;
cout<<" Name - ";
cinname;
cout<<" Marks - ";
cinmarks;
if(marks=75)
,
grade='A';
,
else
if(marks=60)
,
grade='B';
,
else
if(marks=50)
,
grade='C';
,
else
if(marks=40)
,
grade='D';
,
else
,
grade='F';
,
,
void putdata()
,
cout<<"\n Roll no. "<<rollno<<" Name "<<name
<<"\n Marks "<<marks<<" Grade "<<grade<<endl;
,
int getrno()
,
return rollno;
,
,s1,stud;
void main()
,
clrscr();
stu arts4,;
fstream filin;
filin.open("stu.dat",ios::in|ios::out);
if (!filin)
,
cout<<"cannot open file !!\n";
getch();
,
cout<<"\n\n Enter details for students \n";
for(int i=0;i<4;i++)
,
artsi,.getdata();
filin.write((char)&artsi,,sizeof(artsi,));
,
filin.seekg(0);
cout<<" The contents of stu.dat are shown below. \n";
for(i=0;i<4;i++)
,
filin.read((char)&arts,sizeof(artsi,));
artsi,.putdata();
getch();
,
filin.close();
clrscr();
ifstream fio("stu.dat",ios::in);
ofstream file("temp.dat",ios::out);
int rno; char found='f',confirm='n';
cout<<"\n\n Enter rollno of student whose record is to be deleted \n ";
cinrno;
while(!fio.eof())
,
fio.read((char)&s1,sizeof(s1));
if(s1.getrno()==rno)
,
s1.putdata();
found='t';
cout<<" Are you sure, you want to delete this record. (y/n)..";
cinconfirm;
if(confirm=='n')
,
file.write((char)&s1,sizeof(s1));
,
,
else
,
file.write((char)&s1,sizeof(s1));
,
,
if(found=='f')
,
cout<<" Record not found !!!";
,
fio.close();
file.close();
remove("stu.dat");
rename("temp.dat","stu.dat");
fio.open("stu.dat",ios::in);
cout<<" Now the file contains \n ";
while(!fio.eof())
,
fio.read((char)&stud,sizeof(stud));
if(fio.eof())
break;
stud.putdata();
,
fio.close();
getch();
,

JUTPUT-




PRACTICAL NJ.- 29

AIM-
PRJGRAM TJ MJDIFY DATA IN A GIVEN FILE .

CJDING-
#include<fstream.h
#include<conio.h
#include<stdio.h
#include<string.h
class stu
,
int rollno;
char name25,;
char clas4,;
char grade;
float marks;
public:
void getdata()
,
cout<<"\n Enter Roll no. - ";
cinrollno;
cout<<" Enter name - ";
cinname;
cout<<" Enter class - ";
cinclas;
cout<<" Enter marks - ";
cinmarks;
if(marks=75)
,
grade='A';
,
else
if(marks=60)
,
grade='B';
,
else
if(marks=50)
,
grade='C';
,
else
if(marks=40)
,
grade='D';
,
else
,
grade='F';
,
,
void putdata()
,
cout<<"\n Roll no. - "<<rollno<<"\n";
cout<<" Name - "<<name<<"\n";
cout<<" Marks - "<<marks<<"\n";
cout<<" Grade - "<<grade<<"\n";
,
int getrno()
,
return rollno;
,
void modify();
,s1,stud;
void stu::modify()
,
cout<<" Roll no. - "<<rollno<<endl;
cout<<" Name - "<<name<<" Class - "<<clas
<<" Marks - "<<marks<<endl;
cout<<" Enter new details. "<<endl;
char nm20,=" ",cl4,=" ";
float mks;
cout<<" New Name - (Enter '.' to retain old one)";
cinnm;
cout<<" New Class - (Enter '.' to retain old one)";
cincl;
cout<<" New marks - (Press -1 to retain old one)";
cinmks;
if(strcmp(nm,".")!=0)
,
strcmp(name,nm);
,
if(strcmp(cl,".")!=0)
,
strcmp(clas,cl);
,
if(mks!=-1)
,
marks=mks;
if(marks=75)
,
grade='A';
,
else
if(marks=60)
,
grade='B';
,
else
if(marks=50)
,
grade='C';
,
else
if(marks=40)
,
grade='D';
,
else
,
grade='F';
,
,
,
void main()
,
clrscr();
stu arts3,;
fstream filin;
filin.open("stu.dat",ios::in|ios::out);
if (!filin)
,
cout<<" cannot open file !!\n";
getch();
,
cout<<"\n\n Enter details for students \n";
for(int i=0;i<3;i++)
,
artsi,.getdata();
filin.write((char)&artsi,,sizeof(artsi,));
,
filin.seekg(0);
cout<<"\n The contents of stu.dat are shown below. \n";
for(i=0;i<3;i++)
,
filin.read((char)&arts,sizeof(artsi,));
artsi,.putdata();
getch();
,
filin.close();
clrscr();
fstream fio("stu.dat",ios::in|ios::out|ios::binary);
int rno; long pos; char found='f';
cout<<"\n\n Enter roll no. of the student whose record is to be
modified...\n ";
cinrno;
while(!fio.eof())
,
pos=fio.tellg();
fio.read((char)&s1,sizeof(s1));
if(s1.getrno()==rno)
,
s1.modify();
fio.seekg(pos);
fio.write((char)&s1,sizeof(s1));
found='t';
break;
,
,
if(found=='f')
cout<<" Record not found!!! \n";
fio.seekg(0);
cout<<"\n Now the file contains...\n";
while(!fio.eof())
,
fio.read((char)&stud,sizeof(stud));
stud.putdata();
,
fio.close();
getch();
,














JUTPUT-

Vous aimerez peut-être aussi