0% found this document useful (0 votes)
55 views6 pages

Run and Analyze Output of The Following Programs

The document discusses several C++ programs and questions: 1. Program a assigns a value to a reference variable which updates the original variable. Programs b and c demonstrate passing a static reference returns the same variable. Program d swaps the values of two strings by passing them to a function by reference. Program e is the same but passes by reference-to-reference. Program f swaps strings by swapping the pointers. 2. There is no error in the given class program. 3. For a bookshop inventory system, an appropriate data structure like map or multimap should be used to store book details and minimize search time when looking up books by title and author.

Uploaded by

vivek patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views6 pages

Run and Analyze Output of The Following Programs

The document discusses several C++ programs and questions: 1. Program a assigns a value to a reference variable which updates the original variable. Programs b and c demonstrate passing a static reference returns the same variable. Program d swaps the values of two strings by passing them to a function by reference. Program e is the same but passes by reference-to-reference. Program f swaps strings by swapping the pointers. 2. There is no error in the given class program. 3. For a bookshop inventory system, an appropriate data structure like map or multimap should be used to store book details and minimize search time when looking up books by title and author.

Uploaded by

vivek patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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