3.cpp&dbms record
TRANSCRIPT
-
8/10/2019 3.Cpp&Dbms Record
1/110
C++
PROGRAMMING
1
-
8/10/2019 3.Cpp&Dbms Record
2/110
PROGRAM NO: 1
DATE: 13/05/2014
STUDENT SURVEY
Students in a college were surveyed about how many days a week they eat fast-food. Write
a program to help analyze the result of the survey. Initially the program prompts how many input
values there are, it then reads in the specified number of values, and counts how many answers are
day a week, 1 day a week, etc. !inally the result is displayed in a table, each row showing the
number of days, the number of students that eat fast-food that many days a week, and what
percentage they constitute of the total number of students surveyed. "n e#ample running session
might look like follows $you don%t have to align the table columns&'
(ow many input values are there' )
*nter number of days' +
*nter number of days'
*nter number of days'
*nter number of days'
*nter number of days'
ays Students /ercentage$0&
1 +
1
+ 1 +
+
)
2
1 +
CLASS DIAGRAM
+
-
8/10/2019 3.Cpp&Dbms Record
3/110
PROGRAM
3include4iostream5
using namespace std6
class survey
7
private'
int n,count89:6
public'
survey$&
7
n;6
for$int i;6i496i6
cin55ch6
switch$ch&
7
case ' count8:
-
8/10/2019 3.Cpp&Dbms Record
4/110
case +' count8+:Invalid choice?n>6
break6
=
i6
for$int i;6i496i44i44>?t>44count8i:44>?t?t>44t6
=
cout44>?n>6
=
=6
int main$&
7
survey s16
-
8/10/2019 3.Cpp&Dbms Record
5/110
s1.find$&6
s1.display$&6
return 6
=
OUTPUT
)
-
8/10/2019 3.Cpp&Dbms Record
6/110
PROGRAM NO: 2
DATE: 13/05/2014
PASSING ARRAY OF OBJECTS
Ereate a class student with rollno, name and marks of subects. Dead the student details,
find total and percentage and display the details
CLASS DIAGRAM
PROGRAM
3include4iostream5
using namespace std6
class student
7
private'
int m1,m+,m,roll,total6
char name8+:6
float per6public'
void read$&
7
cout44>?n*nter the roll no' >6
cin55roll6
cout44>?n*nter the name' >6
cin55name6
2
-
8/10/2019 3.Cpp&Dbms Record
7/110
cout44>?n*nter mark1,mark+ and mark' >6
cin55m155m+55m6
total;m144total6
cout44>?n/ercentage' >44per44>?n>6
=
int percentage$student s8:,int n&
7int sid6
float ma#6
for$int i;6i4n6i
-
8/10/2019 3.Cpp&Dbms Record
8/110
return sid6
=
=6
int main$&
7
student S181:6
int n,r6
cout44>?n*nter the no'of students' >6
cin55n6
for$int i;6i4n6i
-
8/10/2019 3.Cpp&Dbms Record
9/110
OUTPUT
J
-
8/10/2019 3.Cpp&Dbms Record
10/110
PROGRAM NO: 3
DATE: 13/05/2014
INLINE FUNCTION
Ereate a inline function to find the sum of first n odd numbers
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4math.h5
using namespace std6
class sum
7
private'
int n6
public'
void getdata$&
7
cout44>*nter the limit' >6
cin55n6
=
inline int oddsum$&
7
int s6
s;pow$n,+&6
cout44>SBK; >44s6
cout44>?n>6
=
1
-
8/10/2019 3.Cpp&Dbms Record
11/110
=6
int main$&
7
sum s16
s1.getdata$&6
s1.oddsum$&6
return 6
=
OUTPUT
11
-
8/10/2019 3.Cpp&Dbms Record
12/110
PROGRAM NO: 4
DATE: 20/05/2014
CONSTRUCTOR
Bsing constructor find sum of + integers $use default, parameterized constructor&
CLASS DIAGRAM
PROGRAM
3include4iostream5
using namespace std6
class constructor
7
int a,b,sum6
public'
constructor$&
7
a;6
b;6
cout44>Lalue of a' >44a44>?n>6
cout44>Lalue of b' >44b6
sum;6
=
constructor$int i,int &
7
a;i6
b;6
cout44>Lalue of a' >44a44>?n>6
cout44>Lalue of b' >44b6
1+
-
8/10/2019 3.Cpp&Dbms Record
13/110
=
int add$&
7
return a?nefault constructor called?n>6
constructor c16
cout44>?nSum' >44c1.add$&6
cout44>?n?n/arameterised constructor called?n>6constructor c+$),)&6
cout44>?nSum' >44c+.add$&44>?n>6
return 6
=
OUTPUT
1
-
8/10/2019 3.Cpp&Dbms Record
14/110
PROGRAM NO: 5
DATE: 20/05/2014
TOLL BOOTH
Implement the toll booth . When a car is a paycar, increment count by one and increment
money by 1. If car is not a paycar,increment count by one. Eount will represent number of cars
passed by.
CLASS DIAGRAM
PROGRAM
3include4iostream5
using namespace std6
class tollbooth
7
int totMcar6
int amt6
public'
tollbooth$&'totMcar$&,amt$&
7=
void display$&
7
cout44>?nAotal car passed' >44totMcar6
cout44>?nAotal "mount '>44amt44>?n>6
=
void payingcar$&
7
totMcar;totMcar
-
8/10/2019 3.Cpp&Dbms Record
15/110
amt;amt6
1)
-
8/10/2019 3.Cpp&Dbms Record
16/110
cin55ch6
=
return 6
=
OUTPUT
12
-
8/10/2019 3.Cpp&Dbms Record
17/110
-
8/10/2019 3.Cpp&Dbms Record
18/110
else
consonantMcount44consonantMcount44>?n>6
=
=6
char count''str81:6
int count''vowelMcount;6
int count''consonantMcount;6
int main$&
7count c6
c.getdata$&6
count''putdata$&6
return 6
=
OUTPUT
19
-
8/10/2019 3.Cpp&Dbms Record
19/110
PROGRAM NO: !
DATE: 03/0/2014
BAN" ACCOUNT
efine a class bank"ccountT. Include the following members. Write a program in E
-
8/10/2019 3.Cpp&Dbms Record
20/110
private'
string name6
int accno6
unsigned long int bal6
public'
bankaccount$&
7
cout44>?n*nter the name' >6
cin55name6
cout44>*nter the account number' >6
cin55accno6
bal;6=
int get$&
7
return accno6
=
void display$&
7
cout44>?nCame' >44name44>?n>6
cout44>Ualance' >44bal44>?n>6
=
void deposit$&
7
int amt6
cout44>?n*nter amount to deposit' >6
cin55amt6
bal;bal"mount depositedPPP?n>6
=
void withdraw$&
7
int amt6
+
-
8/10/2019 3.Cpp&Dbms Record
21/110
cout44>?n*nter the amount to be withdrawn' >6
cin55amt6
if$bal4; RR bal4amt&
cout44>?nCo sufficient balancePPP?nWithdrawing not possible?n>6
else
7
bal;bal-amt6
cout44>"mount withdrawnPPP?n>6
=
=
bankaccount transfer$bankaccount b1&
7int amt6
cout44>?n*nter the amount you want to transfer' >6
cin55amt6
if$amt5b1.bal&
cout44>Co sufficient amount to transfer?n>6
else
7
bal;bal"mount successfully transferredPPP?n>6
=
return b16
=
=6
int main$&
7
bankaccount b1,b+6
int a;1,ch,ac1,ac+6
while$a;;1&
7
cout44>?nNptions?n1.eposit?n+.Withdraw?n.Aransfer?n.isplay?n*nter the
+1
-
8/10/2019 3.Cpp&Dbms Record
22/110
choice' >6
cin55ch6
switch$ch&
7
case 1'
cout44>*nter the account number' >6
cin55ac16
if$b1.get$&;;ac1&
b1.deposit$&6
else if$b+.get$&;;ac1&
b+.deposit$&6
elsecout44>?n"ccount doesnQt e#ist?n>6
break6
case +'
cout44>*nter the account number'>6
cin55ac16
if$b1.get$&;;ac1&
b1.withdraw$&6
else if$b+.get$&;;ac1&
b+.withdraw$&6
else
cout44>?n"ccount doesnQt e#ist?n>6
break6
case '
cout44>*nter the account number from which you want to transfer' >6
cin55ac16
cout44>*nter the account number to which u want to deposit' >6
cin55ac+6
if$b1.get$&;;ac1 VV b+.get$&;;ac+&
b1;b+.transfer$b1&6
else if$b+.get$&;;ac1 VV b1.get$&;;ac+&
b+;b1.transfer$b+&6
++
-
8/10/2019 3.Cpp&Dbms Record
23/110
else
cout44>?n"ccount doesnQt e#ist?n>6
break6
case 'b1.display$&6
b+.display$&6
break6
case )' e#it$&6
break6
default' cout44>?nInvalid choice?n>6
=
cout44>/ress 1 to continue else press ' >6
cin55a6=
return 6
=
OUTPUT
+
-
8/10/2019 3.Cpp&Dbms Record
24/110
+
-
8/10/2019 3.Cpp&Dbms Record
25/110
+)
-
8/10/2019 3.Cpp&Dbms Record
26/110
PROGRAM NO: #
DATE: 03/0/2014
COMPLE$ NUMBER ADDITIONEomple# number addition using friend function
CLASS DIAGRAM
PROGRAM
3include4iostream5
using namespace std6
class comple#
7
float real,image6
public'
void get$&
7
cout44>*nter real and imaginary part' >6
cin55real55image6
=
void display$&
7
cout44real44>44image44>?n>6
=
friend comple# sum$comple#,comple#&6
=6
comple# sum$comple# c1,comple# c+&
7
comple# c6
+2
-
8/10/2019 3.Cpp&Dbms Record
27/110
c.real;c1.real6
a.get$&6
cout44>?nSecond comple# number?n>6
b.get$&6
c;sum$a,b&6cout44>Sum of comple# numbers'>6
c.display$&6
return 6
=
OUTPUT
+
-
8/10/2019 3.Cpp&Dbms Record
28/110
PROGRAM NO: %
DATE: 10/0/2014
TRANSLATE THE GIVEN SENTENCE TO PIG LATIN
Write an interactive program that prompts the user to input a valid sentence containing at
least two letters and ending in a period. Bse getline$cin,sentence&6 to read the sentence. Bse string
functions. Aranslate the given sentence to /ig atin and display it.
CNA*' Bse functions to make your code as efficient and as organized as possible. Eorrectness is
the most important element, however, points will be given for the Xuality of your code.
Ahe /ig atin system works as follows'
Y Words that start with a vowel $", *, I, N, B& simply have >W"@> appended to the end of the
word.
Y Words that start with a consonant have the first consonant letter moved to the end of the word and
>"@> is appended.
Incorporate the following features and special case functionality'
Y Eorrect upper case and lower case formatting.
Y "ssume Words consist of alphabetic characters only $"-Z and a-z&.
Y "ll punctuation, numerals, symbols and whitespace should not be modified.!or e#ample'
Input'
Nutput'
Ahese awful french fries are getting cold.
(esetay awfulway renchfay riesfay areway ettinggay oldcay.
CLASS DIAGRAM
+9
-
8/10/2019 3.Cpp&Dbms Record
29/110
PROGRAM
3include 4string.h5
3include 4iostream5
using namespace std6
class convert
7
int worden6
char lowMcase,ch6
string word,first,newWord6
public'
bool isLowels$char #&
7
lowMcase ; tolower $#&6
if $lowMcase ;; QaQ &
return true6
else if $lowMcase ;; QeQ &
return true6
else if $ lowMcase;; QiQ &
return true6
else if $lowMcase ;; QoQ &
return true6
else if $lowMcase ;; QuQ &
return true6
else
return false6=
void changeine $string line&
7
while $line.length$& P;&
7
worden ; line.find$Q Q&6
if $worden 5&
+J
-
8/10/2019 3.Cpp&Dbms Record
30/110
-
8/10/2019 3.Cpp&Dbms Record
31/110
void nonLowel$char begin, string end&
7
newWord;end6
cout44newWord44> >6
=
=6
int main$&
7
convert c6
char ch6
string word, first, line6
cout 44endl6cout 44 >*nter a string or, blank to e#it.?n>6
cout 44 >Ahis program will output the words in /ig atin.?n>6
cout 44endl6
getline$cin,line&6
cout 44endl6
while $line.length$&P; &
7
c.changeine$line&6
cout44endl6
cout44endl6
cout 44 >*nter a string or, blank to e#it.?n>6
cout 44 >Ahis program will output the words in /ig atin.?n?n>6
cout 44endl6
getline$cin,line&6
=
return 6
=
1
-
8/10/2019 3.Cpp&Dbms Record
32/110
OUTPUT
+
-
8/10/2019 3.Cpp&Dbms Record
33/110
PROGRAM NO: 10
DATE: 10/0/2014
ALLOCATING MEMORY DYNAMICALLY
"llocate memory for students dynamically and search for a particular student using rollno.
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4stdlib.h5
using namespace std6
class student
7
int rolno6
char name8+:6
char grade6
public'
void read$&
7
cout44>?n*nter roll number' >6
cin55rolno6
cout44>*nter name' >6
cin55name6
cout44>*nter Frade' >6
cin55grade6
=
void display$&
7
-
8/10/2019 3.Cpp&Dbms Record
34/110
cout44>?nDN Co ' >44rolno6
cout44>?nC"K* ' >44name6
cout44>?nFD"* ' >44grade6
=
int search$int r&
7
if$rolno;;r&
return 16
else
return 6
=
=6main$&
7
int r,f,n,ch;16
cout44>*nter number of students>6
cin55n6
student Hs8n:6
do
7
cout44>?nNptions?n1.D*"?n+.S*"DE(?n.IS/"@ ?n.*[IA?n*nter your
choice' >6
cin55ch6
switch$ch&
7
case 1'for$int i;6i4n6i44i6
-
8/10/2019 3.Cpp&Dbms Record
35/110
cin55r6
f;6
for$int i;6i4n6i6
cout44>etails of student?n>6
s8i:-5display$&6
break6
= =
if$f;;&
7
cout44>?n DN CN CNA !NBC>6
=
break6
case 'for$int i;6i4n6i44$i
-
8/10/2019 3.Cpp&Dbms Record
36/110
OUTPUT
2
-
8/10/2019 3.Cpp&Dbms Record
37/110
-
8/10/2019 3.Cpp&Dbms Record
38/110
PROGRAM NO: 11
DATE: 1!/0/2014
OPERATOR OVERLOADING&STRING
Ereate a class string class which contains + strings as its data members .Nverload Q6cin55s16
cout44>*nter the second string' >6
cin55s+6
=
void operator;;$int a&
7
if$strcmp$s1,s+&;;&
9
-
8/10/2019 3.Cpp&Dbms Record
39/110
cout44>?nStrings are eXual?n>6
else
cout44>?nStrings are not eXual?n>6
=
void operator?nStrings after concatination' >44str6
=
void operator4$int a&7
if$strcmp$s1,s+&4&
cout44>?n!irst string is smaller?n>6
else
cout44>?nSecond string is smaller?n>6
=
void operator5$int a&
7
if$strcmp$s1,s+&5&
cout44>?n!irst string is greater?n>6
else
cout44>?nSecond string is greater?n>6
=
=6
int main$&
7
string1 ob6
int n;16
ob.getdata$&6
ob;;n6
ob
-
8/10/2019 3.Cpp&Dbms Record
40/110
ob4n6
ob5n6
cout44>?n>6
return 6
=
OUTPUT
-
8/10/2019 3.Cpp&Dbms Record
41/110
PROGRAM NO: 12
DATE: 1!/0/2014
OPERATOR OVERLOADING & DISTANCE
Ereate a class istance with feet and inches as data members. Nverload Q feet and >44inches44> inches?n>6
=
istance operator
-
8/10/2019 3.Cpp&Dbms Record
42/110
istance temp6
temp.inches;inches
-
8/10/2019 3.Cpp&Dbms Record
43/110
inches;i6
=
istance operator,$istance d1&
7
istance temp6
temp.feet;d1.feet6
temp.inches;d1.inches6
return temp6
=
=6
main$&
7float f,i6
cout44>?n*nter first distance' >6
cin55f55i6
istance d1$f,i&6
cout44>*nter second distance' >6
cin55f55i6
istance d+$f,i&6
istance d;d1!irst distance' >6
d1.display$&6
cout44>?nSecond distance' >6
d+.display$&6
cout44>?nd16
d.display$&6
if$d1;;d+&
cout44>?nd1 is eXual to d+>6
else
cout44>?nd1 is not eXual to d+>6
d1?nd16
d1.display$&6
-
8/10/2019 3.Cpp&Dbms Record
44/110
d1$1,+&6
cout44>?nd1$1,+&; >6
d1.display$&6
d;$d1,d+&6
cout44endl44>d;$d1,d+& ' >6
d.display$&6
=
OUTPUT
-
8/10/2019 3.Cpp&Dbms Record
45/110
PROGRAM NO: 13
DATE: 01/0!/2014
INHERITANCE
Ereate a class counter with a count variable initialized to zero and a function to increment
the counter and another function to display it.create another class which inherits class counter and
it contains a function which decrements the count. When an employee enters into office, count is
incremented and when employee goes out, count is decremented. Write a program to implement
this functionality.
CLASS DIAGRAM
PROGRAM
3include4stdlib.h5
3include4iostream5
using namespace std6
class base
7
protected'
int count6
public'
base$&'count$&
7=
void increment$&
)
-
8/10/2019 3.Cpp&Dbms Record
46/110
7
count6
cin55c6
switch$c&
7
case 1'
d1.increment$&6
d1.display$&6
break6
case +'
d1.dercement$&6
2
-
8/10/2019 3.Cpp&Dbms Record
47/110
d1.display$&6
break6
case '
e#it$&6
=
cout44>?n/ress 1 to continue else press ' >6
cin55ch6
=
while$chP;&6
return 6
=
OUTPUT
-
8/10/2019 3.Cpp&Dbms Record
48/110
PROGRAM NO: 14
DATE: 01/0!/2014
VIRTUAL FUNCTIONS& SHAPE CLASS
Ereate a base class shape. Aake two data members of double types to compute the area of
different shapes. erive two classes% triangle and rectangle from the base shape. Include
constructors in every class to initialize the obects. Include one pure virtual function
computeMarea$& to compute area. Bsing these classes, write a c
-
8/10/2019 3.Cpp&Dbms Record
49/110
y;6
=
shape$double a,double b&
7
#;a6
y;b6
=
virtual double computeMarea$&;6
=6
class triangle'public shape
7
public'triangle$double a,double b&'shape$a,b&7=
double computeMarea$&
7
return $$#Hy&G+&6
=
=6
class rectangle'public shape
7
public'
rectangle$double a,double b&'shape$a,b&7=
double computeMarea$&
7
return #Hy6
=
=6
int main$&
7
int op,ch;16
double a,b6
shape Hs6
cout44>?n*nter base and height of a triangle' >6
J
-
8/10/2019 3.Cpp&Dbms Record
50/110
cin55a6
cin55b6
triangle t$a,b&6
s;Vt6
cout44>?n"rea of triangle' >44s-5computeMarea$&44>?n>6
cout44>?n*nter length and breadth of rectangle' >6
cin55a6
cin55b6
rectangle r$a,b&6
s;Vr6
cout44>?n"rea of rectangle' >44s-5computeMarea$&44>?n>6
return 6=
OUTPUT
)
-
8/10/2019 3.Cpp&Dbms Record
51/110
PROGRAM NO: 15
DATE: 0#/0!/2014
TRY&CATCH
Write a program that will read the denominator and numerator and if denominator is zero
throw an e#ception with message denominator cannot be zeroT
CLASS DIAGRAM
PROGRAM
3include4iostream5
using namespace std6
class *#ception
7
float a,b,c6
public'
void read$&
7
cout44>*nter two numbers' >6
cin55a55b6
=
void divide$&7
try
7
if$b;;&
throw$b&6
else
7
)1
-
8/10/2019 3.Cpp&Dbms Record
52/110
c;aGb6
cout44>Desult' >44c44>?n>6
=
=
catch$float&
7
cout44>enominator cannot be zeroPPP?n>6
=
=
=6
int main$&
7*#ception e6
e.read$&6
e.divide$&6
return 6
=
OUTPUT
)+
-
8/10/2019 3.Cpp&Dbms Record
53/110
PROGRAM NO: 1
DATE: 0#/0!/2014
BUBBLE SORT USING FUNCTION TEMPLATEImplement bubble sort using function template
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4stdio.h5
3include4stdlib.h5
using namespace std6
template 4class t5
class bubble
7
t a8+):6
public'
void get$int&6
void sort$int&6void display$int&6
=6
template 4class t5
void bubble 4t5''get$int n&
7
int i6
cout44>*nter the array elements'>6
)
-
8/10/2019 3.Cpp&Dbms Record
54/110
for$i;6 i4n6i6
for$i;6i4n6i6
=
template 4class t5void bubble 4t5''sort$int n&
7
int i,6
t temp6
for$i;6i4n6i
-
8/10/2019 3.Cpp&Dbms Record
55/110
7
cout44>?nUubble sort?n>6
cout44>?nNptions?n1.Integer?n+.!loating /oint?n.Eharacter?n.*#it?n*nter your
choice' >6
cin55ch6
switch$ch&
7
case 1'
7
cout44>?nInteger Sort?n>6
bubble4int5 b16
cout44>*nter the size of array' >6cin55n6
b1.get$n&6
b1.sort$n&6
b1.display$n&6
break6
=6
case +'
7
cout44>?n!loating /oint Sort?n>6
bubble4float5 b+6
cout44>*nter the size of array' >6
cin55n6
b+.get$n&6
b+.sort$n&6
b+.display$n&6
break6
=6
case '
7
cout44>?nEharacter Sort?n>6
bubble4char5 b6
))
-
8/10/2019 3.Cpp&Dbms Record
56/110
cout44>*nter the size of array' >6
cin55n6
b.get$n&6
b.sort$n&6
b.display$n&6
break6
=6
case '
e#it$&6
default'
cout44>Invalid Ehoice?n>6return 6
=
=
=
)2
-
8/10/2019 3.Cpp&Dbms Record
57/110
OUTPUT
)
-
8/10/2019 3.Cpp&Dbms Record
58/110
PROGRAM NO: 1!
DATE: 14/0!/2014
CLASS TEMPLATE
Write a class template to represent a generic array. Include member functions to perform
the following tasks'
1. Ao initialize the array
+. Ao modify the value at a given position in the array.
. Ao multiply by an element in a given location with a scalar value
. Ao display the elements in the array.
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4stdlib.h5
using namespace std6
template4class A5class myarray
7
A arr8+:6int n,pos6
public'
void read$&
7
cout44>?n*nter the size of array' >6
cin55n6
cout44>?n*nter the elements' >6
)9
-
8/10/2019 3.Cpp&Dbms Record
59/110
for$int i;6i4n6i6
cin55b6
arr8pos-1:;b6
cout44>?nKodified "rray>6
=
=
void multiply$&
7
cout44>?n*nter the position' >6
cin55pos6
if$pos5n&
cout44>?nCo such position?n>6
else
7
int b6
cout44>?n*nter the element to be multiplied' >6
cin55b6
arr8pos-1:;bHarr8pos-1:6
cout44>?nKultiplication done?n>6
=
=
)J
-
8/10/2019 3.Cpp&Dbms Record
60/110
void display$&
7
for$int i;6i4n6i6
=
=6
int main$&
7
int ch,c,a6
myarray4int5m16
myarray4double5m+6
do7
cout44>?nNptions?n1.Integer?n+.ouble?n.*#it?n*nter your choice' >6
cin55c6
switch$c&
7
case 1'
do
7
cout44>?nInteger?n>6
cout44>?nNptions?n1.Initialize?n+.Kodify?n.Kultiply with a
value?n.isplay?n).*#it?n*nter your choice' >6
cin55ch6
switch$ch&
7
case 1'm1.read$&6
break6
case +'m1.modify$&6
break6
case 'm1.multiply$&6
break6
case 'm1.display$&6
2
-
8/10/2019 3.Cpp&Dbms Record
61/110
break6
=
=
while$chP;)&6
break6
case +'
cout44>?nouble?n>6
do
7
cout44>?nNptions?n1.Initialize?n+.Kodify?n.Kultiply with a
value?n.isplay?n).*#it?n*nter your choice' >6
cin55ch6switch$ch&
7
case 1'm+.read$&6
break6
case +'m+.modify$&6
break6
case 'm+.multiply$&6
break6
case 'm+.display$&6
break6
=
=
while$chP;)&6
break6
case ' e#it$&6
=
cout44>/ress 1 to continue else press ' >6
cin55c6
=
while$cP;&6
=
21
-
8/10/2019 3.Cpp&Dbms Record
62/110
OUTPUT
2+
-
8/10/2019 3.Cpp&Dbms Record
63/110
2
-
8/10/2019 3.Cpp&Dbms Record
64/110
2
-
8/10/2019 3.Cpp&Dbms Record
65/110
2)
-
8/10/2019 3.Cpp&Dbms Record
66/110
PROGRAM NO: 1#
DATE: 14/0!/2014
FILE PROGRAM
E
-
8/10/2019 3.Cpp&Dbms Record
67/110
if$ch;;Q Q&
c
-
8/10/2019 3.Cpp&Dbms Record
68/110
PROGRAM NO: 1%
DATE: 15/0!/2014
EMPLOYEE DB
Implement *mployee db. Ahe db should hold details of *mplyee$I,name,address,phno&.
1. "dd a *mployee
+. Bpdate a employee records.
. Search a employee.
. elete a employee.
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4fstream5
3include4string.h5
using namespace std6
class employee7
int id6
char phnno8+:6
char name8+:6
char addr8+:6
public'
void add$&6
29
-
8/10/2019 3.Cpp&Dbms Record
69/110
void display$&6
void update$&6
void del$&6
void search$&6
int menu$&6
=6
main$&
7
int n6
employee e6
n;e.menu$&6
switch$n&7
case 1 ' e.add$&6 break6
case + ' e.del$&6 break6
case ' e.update$&6 break6
case ' e.display$&6 break6
default' cout44>Ahankyou?n>6
=
=
int employee''menu$&
7
int a6
cout44>?nKain Kenu?n>6
cout44>?n1."dd?n+.elete?n.Bpdate?n.isplay?n).*[IA?n>6
cout44>*nter your choice' >6
cin55a6
return$a&6
=
void employee''add$&
7
ofstream f6
employee t6
2J
-
8/10/2019 3.Cpp&Dbms Record
70/110
int #;16
f.open$>empdb>,ios''appRios''binary&6
while$#;;1&
7
cout44>*nter the id' >6
cin55t.id6
cout44>*nter the name' >6
cin55t.name6
cout44>*nter the phone number' >6
cin55t.phnno6
cout44>*nter the address' >6
cin55t.addr6f.write$$char H&Vt,sizeof$t&&6
cout44>?nDecord Successfully "dded PP>6
f.close$&6
cout44>?n/ress 1 to add more record' >6
cin55#6
=
main$&6
=
void employee''del$&
7
int #;1,flag;,eid6
employee t6
ofstream f16
ifstream f+6
while$#;;1&
7
flag;6
cout44>*nter the id to be deleted' >6
cin55eid6
f1.open$>temp>,ios''appRios''binary&6
-
8/10/2019 3.Cpp&Dbms Record
71/110
f+.open$>empdb>,ios''appRios''binary&6
while$f+.read$$char H&Vt,sizeof$t&&&
7
if$eidP;t.id&
f1.write$$char H&Vt,sizeof$t&&6
else
flag;16
=
f1.close$&6
f+.close$&6
remove$>empdb>&6
rename$>temp>,>empdb>&6if$flag;;1&
cout44>Decord is successfully deleted?n>6
else
cout44>Decord not found?n>6
cout44>?n/ress 1 to delete another record else /ress ' >6
cin55#6
=
main$&6
=
void employee''update$&
7
int #;1,eid6
int flag;6
ofstream f16
ifstream f+6
employee t6
while$#;;1&
7
flag;6
f1.open$>temp>,ios''appRios''binary&6
f+.open$>empdb>,ios''inRios''binary&6
1
-
8/10/2019 3.Cpp&Dbms Record
72/110
cout44>*nter the id to be modified' >6
cin55eid6
while$f+.read$$char H&Vt,sizeof$t&&&
7
if$eidP;t.id&
f1.write$$char H&Vt,sizeof$t&&6
else
7
cout44>*nter the new name' >6
cin55t.name6
cout44>*nter the new place' >6
cin55t.addr6cout44>*nter the new phone no' >6
cin55t.phnno6
f1.write$$char H&Vt,sizeof$t&&6
flag;16
=
=
f1.close$&6
f+.close$&6
remove$>empdb>&6
rename$>temp>,>empdb>&6
if$flag;;1&
cout44>Decord is successfully updated?n>6
else
cout44>Decord is not found?n>6
cout44>/ress 1 to update another record *lse press ' >6
cin55#6
=
main$&6
=
void employee''search$&
7
+
-
8/10/2019 3.Cpp&Dbms Record
73/110
ifstream f6
int flag;,s6
employee t6
cout44>?n*nter id ' >6
cin55s6
f.open$>empdb>,ios''inRios''binary&6
f.seekg$&6
while$f.read$$char H&Vt,sizeof$t&&&
7
if$s;;t.id&
7
flag;16t.display$&6
break6
=
=
if$flag;;&
cout44>*ntry Cot !ound PPP?n>6
f.close$&6
=
void employee''display$&
7
ifstream f6
int flag;6
employee t6
cout44>*A"IS "D*PPP?n>6
f.open$>empdb>,ios''inRios''binary&6
f.seekg$&6
while$f.read$$char H&Vt,sizeof$t&&&
7
flag;16
cout44>?n------------------------------?n>6
cout44>Id '>44t.id6
-
8/10/2019 3.Cpp&Dbms Record
74/110
cout44>?nCame '>44t.name6
cout44>?n/hone number '>44t.phnno6
cout44>?n"ddress '>44t.addr44>?n>6
=
if$flag;;&
cout44>?n !I* IS *K/A@?n>6
f.close$&6
main$&6
=
-
8/10/2019 3.Cpp&Dbms Record
75/110
OUTPUT
)
-
8/10/2019 3.Cpp&Dbms Record
76/110
2
-
8/10/2019 3.Cpp&Dbms Record
77/110
PROGRAM NO: 20
DATE: 15/0!/2014
PASSING FILE NAME AS ARGUMENTS
/assing file name as arguments, put even numbers in one file and odd numbers in another
file.
CLASS DIAGRAM
PROGRAM
3include4iostream5
3include4fstream5
3include4string5
using namespace std6
class evenodd7
public'
void find$char Hfn1,charHfn+&
7
int i,n,a8+:6
char ch6
cout44>?n*nter the limit' >6cin55n6
cout44>?n*nter the elements' >6
for$i;6i4n6i
-
8/10/2019 3.Cpp&Dbms Record
78/110
for$i;6i4n6i6
else
f+44a8i:44> >6
=
f1.close$&6
f+.close$&6
f1.open$fn1,ios''in&6
f+.open$fn+,ios''in&6
f1.close$&6f+.close$&6
=
=6
int main$int argc,char Hargv8:&
7
evenodd ev6
ev.find$argv81:,argv8+:&6
cout44>?n>6
return 6
=
OUTPUT
9
-
8/10/2019 3.Cpp&Dbms Record
79/110
DATABASE MANAGEMENT
SYSTEM
J
-
8/10/2019 3.Cpp&Dbms Record
80/110
'UESTION 1
DATE: 13/05/2014
C()*) ,) -.. *) * ***6) 7*) 6)*8 * *6)( ,)
-.. 9)()6;
9
-
8/10/2019 3.Cpp&Dbms Record
81/110
E&R DIAGRAM
CREATING DATABASE
database1;5 create database sea6
ED*"A* "A"U"S*
database1;5 ?c sea
SS connection $cipher' (*-DS"-"*S+)2-S(", bits' +)2&
@ou are now connected to database >sea> as user >user1>.
TABLE DESCRIPTION
B.*:
91
-
8/10/2019 3.Cpp&Dbms Record
82/110
6)* -(.? .*@
S*.(6:
6)* -(.? 6*.(6@
9+
-
8/10/2019 3.Cpp&Dbms Record
83/110
R)6)()6:
6)* -(.? ()6)()6@
'UERIES
1. ist sid, sname of all Sailors
6)*
-
8/10/2019 3.Cpp&Dbms Record
84/110
+.ist sailors whose rating is less than )
6)*
-
8/10/2019 3.Cpp&Dbms Record
85/110
2. ist the name of sailors who reserve a red boat
6)*
-
8/10/2019 3.Cpp&Dbms Record
86/110
'UESTION 2
DATE: 20/05/2014
A 7.)) *?66. ***6) ,*6 ,) -.. *)6:
C.(6)*?)8 8 (*.8 . .- 6)*6 8 . .- 6)68 F))/S)?8 )*(?)
D)*(?)N.8 N*?)8 . .- 7.(6)
S) 8 *?)8 7.(6)8 S)?)6)(8 A()66
H.6)7.(6)8 . .- (..?68 .77)8 F))/?.,
F))R)?68 7.(6)8 6)?)6)(8 *)
E&R DIAGRAM
92
-
8/10/2019 3.Cpp&Dbms Record
87/110
CREATING DATEBASE
database1;5 create database college6
ED*"A* "A"U"S*
database1;5 ?c college
SS connection $cipher' (*-DS"-"*S+)2-S(", bits' +)2&
@ou are now connected to database >college> as user >user1>.
TABLE DESCRIPTION
C.)):
7.)) -(.? 7.(6)@
9
-
8/10/2019 3.Cpp&Dbms Record
88/110
D)*(?):
7.)) -(.? )*(?)@
S):
7.)) -(.? 6)@
99
-
8/10/2019 3.Cpp&Dbms Record
89/110
H.6):
7.)) -(.? ,.6)@
F))R)?:
7.)) -(.? -))R)?@
9J
-
8/10/2019 3.Cpp&Dbms Record
90/110
'UERIES
1. !ind the course with id +.
7.))
-
8/10/2019 3.Cpp&Dbms Record
91/110
). Write a function that accepts the course name and displays the no of seats available.
7.))
-
8/10/2019 3.Cpp&Dbms Record
92/110
. Ereate a trigger to restrict the entry to the hostel if rooms are all filled.
7.))
-
8/10/2019 3.Cpp&Dbms Record
93/110
'UESTION 3
DATE: 03/02/2014
M.) ?ID8 )8 K)*(8 ()7.( - Ahe movie with id mI has a title, a release year and
a director
R)))( (ID8 *?) - Ahe reviewer with id rI has a name
R* (ID8 ?ID8 6*(68 (*D*) - Ahe reviewer rI gave the movie mI a number
of stars rating $1-)& on a certain ratingate.
E&R DIAGRAM
CREATING DATABASE
database1;5 create database movies6
ED*"A* "A"U"S*
database1;5 ?c movies
SS connection $cipher' (*-DS"-"*S+)2-S(", bits' +)2&
@ou are now connected to database >movies> as user >user1>.
J
-
8/10/2019 3.Cpp&Dbms Record
94/110
TABLE DESCRIPTION
M.)6:
?.)6 -(.? ?.)@
R)))(:
J
-
8/10/2019 3.Cpp&Dbms Record
95/110
?.)6 -(.? ()))(@
R*:
?.)6 -(.? (*@
J)
-
8/10/2019 3.Cpp&Dbms Record
96/110
-
8/10/2019 3.Cpp&Dbms Record
97/110
-
8/10/2019 3.Cpp&Dbms Record
98/110
. Write a trigger which will display error message when you are deleting a row from
movie table.
?.)6
-
8/10/2019 3.Cpp&Dbms Record
99/110
'UESTION 4
DATE: 10/0/2014
S)(66: ))(8 6*?): 6(8 *()66: 6(
P*(6: ))(8 *?): 6(8 7..(: 6(
C**.6: ))(8 : ))(8 7.6: ()*
E&R DIAGRAM
CREATING DATABASE
database1;5 create database shop6
ED*"A* "A"U"S*
database1;5 ?c shop
SS connection $cipher' (*-DS"-"*S+)2-S(", bits' +)2&
@ou are now connected to database >shop> as user >user1>.
JJ
-
8/10/2019 3.Cpp&Dbms Record
100/110
TABLE DESCRIPTION
S)(6:
6,. -(.? 6)(6@
P*(6:
1
-
8/10/2019 3.Cpp&Dbms Record
101/110
6,. -(.? *(6@
C**.:
6,. -(.? 7**.@
11
-
8/10/2019 3.Cpp&Dbms Record
102/110
'UERIES
1. !ind the names of suppliers who supply some red part.
6,.
-
8/10/2019 3.Cpp&Dbms Record
103/110
). !ind the pids of parts supplied by every supplier at less than \+
6,.
-
8/10/2019 3.Cpp&Dbms Record
104/110
6,.= )@
6,.= **) 69@
CREATE FUNCTION
6,.
-
8/10/2019 3.Cpp&Dbms Record
105/110
'UESTION 5
DATE: 1!/0/2014
F,6$flno' integer, from' string, to' string, distance' integer, departs'
time, arrives' time&
A(7(*-$aid' integer, aname' string, cruisingrange' integer&
C)(-)$eid' integer, aid' integer&
E?.K))6$eid' integer, ename' string, salary' integer&
$Ahe ma#imum distance from a base that the fuel capacity of a ship or aircraft
will allow it to travel and then return safely at cruising speed' a fuel capacity of ++gallons should give a cruising range of around + miles&
E&R DIAGRAM
1)
-
8/10/2019 3.Cpp&Dbms Record
106/110
CREATING DATABASE
database1;5 create database airport6
ED*"A* "A"U"S*
database1;5 ?c airport
SS connection $cipher' (*-DS"-"*S+)2-S(", bits' +)2&
@ou are now connected to database >airport> as user >user1>.
TABLE DECRIPTION
F,6:
*(.( -(.? -,6@
12
-
8/10/2019 3.Cpp&Dbms Record
107/110
A(7(*-6:
*(.( -(.? *(7(*-@
E?.K))6:
*(.( -(.? )?.K))6@
1
-
8/10/2019 3.Cpp&Dbms Record
108/110
C)(-):
*(.( -(.? 7)(-)@
'UERIES:
1. !ind the eids of pilots certified for some Uoeing aircraft.
*(.(
-
8/10/2019 3.Cpp&Dbms Record
109/110
. !ind the details of all the aircraft.
*(.( -(.? *(7(*-@
. Identify the flights that can be piloted by every pilot whose salary is more than \1,. $(int'
Ahe pilot must be certified for at least one plane with a sufficiently large cruising range.&
*(.(
-
8/10/2019 3.Cpp&Dbms Record
110/110
*(.(