You are on page 1of 6

LAB-3

Question 1: Run and analyze output of the following programs a) #include<iostream> using namespace std; int main() { int x = 10; int &y = x; int &z = y; z = 30; cout<<x; cout<<y; cout<<z; return 0;

!) #include<iostream> using namespace std; int &"un() { static int a = 10; return a;

int main() { int &y = "un(); y = y #30;

cout<<"un(); return 0;

c) #include<iostream> using namespace std; int &"un() { static int a = 10; return a;

int main() { int y = "un(); y = y #30; cout<<"un(); return 0;

d) #include<iostream> using namespace std; $oid s%ap(c&ar 'str1( c&ar 'str)) { c&ar 'temp = str1; str1 = str); str) = temp;

int main() { c&ar 'str1 = *+,,-*; c&ar 'str) = *./,01*; s%ap(str1( str)); cout<<*str1 is *<<str1<<endl; cout<<*str) is *<<str)<<endl; return 0;

e) #include<iostream> using namespace std; $oid s%ap(c&ar ' &str1( c&ar ' &str)) { c&ar 'temp = str1; str1 = str); str) = temp;

int main() { c&ar 'str1 = *+,,-*; c&ar 'str) = *./,01*; s%ap(str1( str)); cout<<*str1 is *<<str1<<endl; cout<<*str) is *<<str)<<endl; return 0;

") #include<iostream>

using namespace std; 2' 3%aps strings !y s%apping pointers '2 $oid s%ap1(c&ar ''str14ptr( c&ar ''str)4ptr) { c&ar 'temp = 'str14ptr; 'str14ptr = 'str)4ptr; 'str)4ptr = temp;

int main() { c&ar 'str1 = *+,,-*; c&ar 'str) = *./,01*; s%ap1(&str1( &str)); cout<<*str1 is *<<str1<<endl; cout<<*str) is *<<str)<<endl; return 0;

g) #include<iostream> using namespace std; class 5oint { pri$ate6 int x; int y; pu!lic6 5oint(int i = 0( int 7 = 0); 22 .ormal 8onstructor 5oint(const 5oint &t); 22 8opy 8onstructor ; 5oint665oint(int i( int 7) { x = i; y = 7; cout << *.ormal 8unstroctor called9n*;

5oint665oint(const 5oint &t) { y = t:y; cout << *8opy constructor called9n*;

int main() { 5oint 't1( 't); t1 = ne% 5oint(10( 1;); t) = ne% 5oint('t1); 5oint t3 = 't1; 5oint t<; t< = t3; return 0;

Question 2: 5oint out i" t&ere is any error in !elo% program: ," yes( t&en &o% %ould you "ix t&e error=

#include<iostream> using namespace std; class -est { int $alue; -est(int $) { $alue = $; ; int main() { -est t>100?; getc&ar(); return 0;

Question 36 1 @ooA 3&op ,n$entory uses a personal computer to maintain t&e in$entory o" !ooAs: -&e list includes details suc& as aut&or( title( price( pu!lis&er( stocA position etc: B&ene$er a customer %ants a !ooA( t&e s&op Ceeper inputs t&e title and aut&or o" t&e !ooA and t&e system replies %&et&er it is in list or not: ," it is not( an appropriate message is displayed: ," !ooA is in t&e list( t&en t&e system displays t&e !ooA details and asAs "or t&e no: o" copies: ," t&e reDuested copies are a$aila!le( t&e total cost o" !ooAs displayed( and ot&er%ise t&e message EreDuired

copies not in stocAF is displayed: Gse appropriate 0ata structure o" your c&oice to minimize searc& time and implement t&e system:

You might also like