0% found this document useful (0 votes)
12 views

C++ Qans - 1 - To - 28

Uploaded by

Sourav Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

C++ Qans - 1 - To - 28

Uploaded by

Sourav Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

CHAPTER-1

C++ REVISION TOUR


VERY SHORT/ SHORT ANSWER QUESTIONS
1. Find out the errors, if any, in the following C++ statement:
(i) cout<<"="a;
(ii) m=5, n=12; o=15
(iii) cout<<"x";<<x;
(iv) cin>>y;>>j;
(v) cin>>"\n">>y;
(vi) cout>>"\n "abc";
(vii)a = b + c
(viii) break = x*y;
Ans. (i) cout<<"="a;
(ii) m=5, n=12; o=15
(iii) cout<<"x";<<x;
(iv) cin>>y;>>j;
(v) cin>>"\n">>y;
(vi) cout>>"\n "abc";
(vii) a = b + c
(viii) break = x*y;
2. What is the difference between fundamental data types and derived data types? Explain with examples.
Ans. Fundamental data types Derived data types
These are the data types that are not composed of These are tha data types that are composed of
any other data type. fundamental data types.
There are five fundamental data types: char, int, These are: array, function, pointer, reference, constant,
float, double and void. class, structure, union and enumeration.
Example: int a=10; float b; Example: float marks[50]; Const int a=5;

3. What is the purpose of a header file in a program?


Ans. Header files provide function prototypes, definitions of library functions, declaration of data types and constants used
with the library functions.
4. What main integer types are offered by C++?
Ans. C++ offered three types of integers : short, int and long. Each comes in both signed and unsigned versions.
5. Explain the usage of following with the help of an example:
(i) constant (ii) reference
(iii) variable (iv) union
Ans. (i) constant: The keyword const can be added to the declaration of an object to make that object a constant rather
than a variable. Thus, the value of the named constant cannot be altered during the program run. The general form of
constant declaration is as follows: const type name = value. Example: const int a=10;
(ii) reference: A reference is an alternative name for an object. A reference variable provides an alias for a previously
defined variable. The general form of declaring a reference variable is: Type &ref-var = var-name;
where type is any valid c++ data type, ref-var is the name of reference variable that will point to variable denoted by
var-name.
Example:
int total;
int &sum=total;
total=100;
cout<<"Sum="<<sum<<"\n";
cout<<"Total="<<total<<"\n";
In above code both the variables refer to the same data object in the memory, thus, print the same value.
(iii) variable: Variables represent named storage locations whose value can be manipulated during program run.
Variables are generally declared as: type name; where type is any C++ data type and name is the variable name. A
variable can be initialized either by a separate assignment statement following its declaration as shown below:
int age; age = 10;
(iv) union: A union is a memory location that is shared by two or more different variables, generally of different types
at different times. Defining a union is similar to defining a structure. Following of declaration declares a union share
having two variables and creates a union object cnvt of union type share:
union share{
int i;
char ch;
};
union share cnvt;
union can referred to the data stored in cnvt as either an integer or character. To assign the integer 20 to element i of
cnvt, write - cnvt.i = 20; To print the value of element ch of cnvt, write - cout<<cnvt.ch;
6. How many ways can a variable be initialized into? Give examples for each type of initialization.
Ans. A variable can be initialized into two ways as following:
(i) By separate assignment statement: Example: int age;
age = 10;
(ii) At the time of declaration: Example: int age = 10;
(iii) Dynamic initialization: Example: float avg = sum/count;
7. How are the following two statements different?
char pcode = 75;
char pcode = ‘K’;
Ans. The first statement treats 75 as ascii value and converts it into its relative character ‘K’ whereas second statement
stores character ‘K’ and does not make any conversion.
8. How are the following two statements different?
char pcode = 75; short pcode = 75;
Ans. The first statement treats 75 as ascii value and converts it into its relative character ‘K’ whereas second statement
treats 75 as number.
9. If value is an identifier of int type and is holding value 200, is the following statement correct?
char code = value
Ans. VALID Statement
10. The data type double is another floating-point type. Then why is it treated as a distinct data type?
Ans. The data type double is treated as a distinct data type because it occupies twice as much memory as type float, and
stores floating-point numbers with much larger range and precision. It stands for double precision floating-point. It is
used when type float is too small or insufficiently precise.
11. Explain the impact of access modifier const over variables. Support your answer with examples.
Ans. The access modifier const can be added to the declaration of an object to make that object a constant rather than a
variable. Thus, the value of the named constant cannot be altered during the program run whereas the value of the
variable can be changed during the program run.
Example: void main(){
const int a=10;
int b=20;
a++;
cout<<"a="<<a;
b++;
cout<<"b="<<b;
}
12. What are arithmetic operators in C++? Distinguish between unary and binary arithmetic operators. Give examples
for each of them.
Ans. Following are the arithmetic operators in C++:
addition(+), subtraction(-), multiplication(*), division(/) and reminder(%).
Unary arithmetic operators Binary arithmetic operators
Unary Operators has only one operand Binary operators (”bi” as in “two”) have two operands
The Unary Operators are ++,--,&,*,+, - etc. The +, -, &&, <<, ==, >> etc. are binary operators.
Example: short x = 987; Example: int x, y = 5, z;
x = -x; z = 10;
x = y + z;

13. What is the function of increment/decrement operators? How many varieties do they come in? How are these two
varieties different from one another?
Ans. The increment operator, ++ adds 1 to its operand and the decrement operator -- subtract 1 from its operands.
The increment/decrement operator comes in two varieties as following:
(i) Prefix version and (ii) Postfix version:
Prefix version Postfix version
Performs the increment or decrement operation First uses the value of the operand in evaluating the
before using the value of the operand. expression before incrementing or decrementing the
operand’s value.
Example: sum = 10; Example: sum = 10;
ctr = 5; ctr = 5;
sum = sum + (++ctr); sum = sum + (ctr++);

14. State why are following expression invalid?


(i) asm = 5100 || val < 35
(ii) age > 70 && < 90
(iii) income >= 500 ||&& val < 500
(iv) res !> 20 ||! X > 20
Ans. (i) In this expression single ‘=’ operator is used for comparison which is not valid.
(ii) In this expression variable’s name is not mentioned after the ‘&&’ operator which is not valid.
(iii) In this expression both ‘||’ and ‘&&’ operators are written together which is not valid.
(iv) In this expression use of ‘!>’ is invalid and !x>20 should be written in parenthesis like (!x>20).
15. What is the difference between Type Casting and Automatic Type conversion? Also, give a suitable C++ code to
illustrate both.
Ans. Type Casting Automatic Type conversion
It is an explicit process of conversion of a data from It is an implicit process of conversion of a data from one
one type to another. type to another.
It is performed with the help of casting operator(). It is performed by compiler its own.
Example: Example:
int A=1, B=2; int N = 65;
float C = (float)A/B;//Type Casting char C = N; //Automatic type conversion
cout<<C; cout<<C;
Output: 0.5 Output: A
16. Determine the data type of the expression
( − ) + )/

( + ) ( )( + )
If p is int, r is a float, q is a long and s is double.
Ans. The data type of the expression is double as double is the larger data type.
17. What are the outputs of following two codes fragments? Justify your answer.
//version 1 //version 2
int f = 1, i =2; int f = 1, i = 2;
while(++i < 5) do{
f * = i; f * = i;
cout<<f; }while (++i < 5);
: cout<< f;
: :
Ans. The output of the first code fragment is 12.
The output of the first code fragment is 24.
18 Will the following program execute successfully? If not, state the reason(s):
(i)#include<stdio.h> (ii) #include<stdio.h>
void main(){ void main(){
int s1,s2,num; int x,sum=0;
s1=s2=0; cin<<n;
for(x=0;x<11;x++) for(x=1;x<100;x+=2)
{ if x%2==0
cin<<num; sum+=x;
if(num>0)s1+=num; cout<<"SUM=">>sum;
else s2=/num; }
}
cout<<s1<<s2;
}

Ans.
(i) Will encounter a compile time error for following (ii) Will encounter a compile time error for following
reasons: reasons:
 The variable ‘x’ is not declared.  The variable ‘n’ is not declared.
 With cin statement ‘<<’ symbol is used instead of ‘>>’.  There should be a parenthesis in if statement.
 Invalid semicolon at the end of if statement.  ‘>>’ is used with cout statement instead of ‘<<’.
19 Find the syntax error(s), if any, in the following program:
Ans. (i) #include<iostream.h>
main(){
int x[5],*y,z[5]
for(i=0;i<=5;i++)
{
x[i]=i;
z[i]=i+3;
y=z;
x=y;
}
}
(ii) #include<iostream.h>
void main(){
int x,y;
cin>>x;
for(x=0;x<5;++x)
cout y else cout<<x<<y;
}
(iii) #include<iostream.h>
void main(){
int R;W=90;
while W>60
{ R=W-50;
switch(W)
{ 20:cout<<"Lower Range"<<endl;
30:cout<<"Middel Range"<<endl;
20:cout<<"Higher Range"<<endl;
}
}
}
(iv) Rewrite the following program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int X[]={60, 50, 30, 40},Y;Count=4;
cin>>Y;
for(I=Count-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout<<Y*X[I]<<endl;break;
case1:
case 3:cout>>Y+X[I];
}
}
(v) Rewrite the following program after removing all the syntax error(s), if any.
#include<iostream.h>
void main(){
int P[]={90, 10, 24, 15},Q;Number=4;
Q=9;
for(int I=Number-1;I>=0,I--)
switch(I)
{ case 0:
case 2:cout>>P[I]*Q<<endl;
break;
case1:
case 3:cout<<P[I]+Q;
}
}
Ans. (i) Will encounter a following syntax error(s):
 The variable ‘i’ is not declared.
 There should be semicolon after the declaration statement if int x[5].
(ii) There is a syntax error in cout statement.
(iii) Will encounter a following syntax error(s):
 There should be a ‘,’ between R and W instead of ‘;’ in declaration statement.
 There should be a parenthesis in ‘while’ statement.
 There is missing a use of ‘case’ keyword in switch statement.
(iv) #include<iostream.h>
void main(){
int X[]={60, 50, 30, 40},Y,Count=4;
cin>>Y;
for(int I=Count-1;I>=0;I--)
switch(I)
{ case 0:
case 1:
case 2:cout<<Y*X[I]<<endl;break;

case 3:cout<<Y+X[I];break;
}
}
(v) #include<iostream.h>
void main(){
int P[]={90, 10, 24, 15},Q,Number=4;
Q=9;
for(int I=Number-1;I>=0;I--)
switch(I)
{ case 0:
case 1:
case 2:cout<<P[I]*Q<<endl;
break;
case 3:cout<<P[I]+Q;
break;
}
}
20 Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
void main(){
Present=25,Past=35;
Assign(Present;Past);
Assign(Past);
}
void Assign(int Default1,Default2=30)
{
Default1=Default1+Default2;
cout<<Default1>>Default2;
}
Ans. #include<iostream.h>
void Assign(int Default1,int Default2=30);
void main(){
clrscr();
int Present=25,Past=35;
Assign(Present,Past);
Assign(Present);
getch();
}
void Assign(int Default1,int Default2)
{
Default1=Default1+Default2;
cout<<Default1<<Default2;
}
21 Given the following code fragment:
if(a==0)
cout<<"Zero";
if(a==1)
cout<<"One";
if(a==2)
cout<<"Two";
if(a==3)
cout<<"Three";
Write an alternative code (using if) that saves on number on compressions.
Ans. #include<iostream.h>
void main(){
int a;
cout<<"enter a:";
cin>>a;
if(a==0)
cout<<"Zero";
else if(a==1)
cout<<"One";
else if(a==2)
cout<<"Two";
else if(a==3)
cout<<"Three";
else
cout<<"other than 0,1,2,3";
}
22 Write the names of the header files, which is/are essentially required to run/execute the following C++ code:
#include<iostream.h>
void main(){
char CH,Text[]="+ve Attitude";
for(int I=0;Text[I]!='\0';I++)
if(Text[I]=='')
cout<<endl;
else
{
CH=toupper(Text[I]);
cout<<CH;
}
}
Ans. 1. ctype.h
23 Find the output of the following program:
#include<iostream.h>
void main(){
int A=5,B=10;
for(int I=1;I<=2;I++)
{
cout<<"Line1"<<A++
<<"&"<<B-2<<endl;
cout<<"Line2"<<++B
<<"&"<<A+3<<endl;
}
}
Ans. Output:
Line15&8
Line211&9
Line1679
Line212&10
24 Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
void main(){
One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2=20)
{
Arg1=Arg1+Arg2
cout<<Arg1>>Arg2;
}
Ans. #include<iostream.h>
void Callme(int Arg1,int Arg2=20);
void main(){
int One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2=20)
{
Arg1=Arg1+Arg2
cout<<Arg1<<Arg2;
}
25 Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.
#include<iostream.h>
typedef char[80];
void main(){
String S="Peace";
int L=strlen(S);
cout<<S<<'has'<<L
<<'characters'<<endl;
}
Ans. #include<iostream.h>
#include<string.h>
typedef char String[80];
void main(){
String S="Peace";
int L=strlen(S);
cout<<S<<"has"<<L
<<"characters"<<endl;
}
26 Find the output of the following program:
#include<iostream.h>
void SwitchOver(int A[],int N,int split)
{
for(int K=0;K<N;K++)
if(K<Split)
A[K]+=K;
else
A[K]*=K;
}
void Display(it A[],int N)
{ for(int K=0;K<N;K++)
(K%2==0)?cout<<A[K]
<<"%":cout<<A[K]<<endl;
}
void main(){
int H[]={30,40,50,20,10,5};
SwitchOver(H,6,3);
Display(H,6);
}
Ans. Output:
30%41
52%60
40%25
27(a The following code is from a game, which generates a set of 4 random numbers. Praful is playing this game, help
) him to identify the correct option(s) out of the four choices given below as the possible set of such numbers
generated from the program code so that he wins the game. Justify your answer.
#include<iostream.h>
#include<stdlib.h>
const int LOW=25;
void main(){
randomize();
int POINT=5,Number;
for(int I=1;I<=4;I--)
{
Number=LOW+random(POINT);
cout<<Number<<":";
POINT--;
}
}
(i) 29:26:25:28: (ii) 24:28:25:26: (iii) 29:26:24:28: (iv) 29:26:25:26:
Ans. (iv) 29: 26: 25: 26: is correct
Justification:
The only option that satisfied the values as per the code is option (iv) because when:
Number
I POINT
Minimum Maximum
1 5 25 29
2 4 25 28
3 3 25 27
4 2 25 26
27(b Study the following program and select the possible output from it:
) #include<iostream.h>
#include<stdlib.h>
const int LIMIT=4;
void main(){
randomize();
int Points;
points=100+random(LIMIT);
for(int P=Pints;P>=100;P--)
cout<<P<<"#";
cout<<endl;
}
(i) 103#102#101#100# (ii) 100#101#102#103#
(iii) 100#101#102#103#104# (iv)104#103#102#101#100#
Ans. (i) 103#102#101#100# is correct answer.
28 Go through C++ code show below, and find out the possible output or outputs from the suggested Output Options
(i) to (iv0. Also, write the least value and highest value, which can be assigned to the variable MyNum.
#include<iostream.h>
#include<stdlib.h>
void main(){
randomize();
int MyNum,Max=5;
MyNum=20+random(Max);
for(int N=Mynum;N<=25;N++)
cout<<C<<"*";
}
(i) 20*21*22*23*24*25 (ii) 22*23*24*25
(iii) 23*24* (iv) 21*22*23*24*25
Ans. (ii) 22*23*24*25 is correct answer. Minimum possible value = 20, Maximum possible value = 24
29(a Find the output of the following program:
) #include<iostream.h>
#include<ctype.h>
void main(){
char Line[]="Good@LOGIC";
for(int I=0;Line(I)!='\0';I++)
{
if(!isalpha(Line[I]))
Line[I]='$';
else if(islower(Line[I]))
Line[I]=Line[I]+1;
else
Line(I)=Line[I+1];
}
cout<<Line;
}
Ans. Output: Oppe$0GIC
29(b Find the output of the following program:
) #include<iostream.h>
void main(){
int First=25,Sec=30;
for(int I=1;I<=2;I++0
{ cout<<"Output1="<<First++
<<"&"<<Sec+5<<endl;
cout<<"Output2="<<-Sec
<<"&"<<First-5<<endl;
}
}
Ans. Output:
Output1=25&35
Output2=-30&21
Output1=26&35
Output2=-30&22
29(c Find the output of the following program:
) #include<iostream.h>
#include<ctype.h>
void Encode<char Info[],int N);
void main(){
char Memo[]="Justnow";
Encode(Memo,2);
cout<<Memo<<endl;
}
void Encode<char Info[],int N)
{
for(int I=0;Info[I]!='\0';I++)
if(I%2==0)
Info[I]=Info[I]-N;
else if(islower(Info[I]))
Info[I]=toupper(Info[I]);
else
Info[I]=Info[I]+N;
}
Ans. Output: HUqT10u
29(d Find the output of the following program:
) #include<iostream.h>
struct THREE_D
{
int X,Y,Z; };
void MoveIn(THREE_D &T,int Step=1)
{
T.X+=Step;
T.Y-=Step;
T.Z+=Step;
}
void MoveOut(THREE_D &T,it Step=1)
{
T.X-=Step;
T.Y+=Step;
T.Z-=Step;
}
void main(){
THREE_D T1={10,20,5}, T2={30,10,40};
MoveIn(T1);
MoveOut(T2,5);
cout<<T1.X<<","<<T1.Y<<","
<<T1.Z<<endl;
cout<<T2.X<<","<<T2.Y<<","
<<T2.Z<<endl;
MoveIn(T2,10);
cout<<T2.X<<","<<T2.Y<<","
<<T2.Z<<endl;
}
Ans. Output:
11,19,6
25,15,35
35,5,45
30 Give the output of the following program:
(i) void main(){
char *p="Difficult";
char c;
c=++*p++;
printf("%c",c);
}
(ii) #include<iostream.h>
static int i=100;
void abc()
{
static int i=8;
cout<<"first="<<i;
}
main(){
static int i=2;
abc();
cout<<"second="<<i<<endl;
}

(iii) #include<iostream.h>
void Print(char *p)
{
p="Pass";
cout<<"Value is:"<<p<<endl;
}
void main(){
char *q="Best of Luck";
Printf(q);
cout<<"New value is:"<<q;
}
Ans. (i) Output: (ii) Output: (iii) Output:
E first=8second=2 Value is: Pass
New value is: Best of Luck
31 Give the output of the following:
(i) #include<iostream.h> (ii) #include<iostream.h>
void Execute(int &X,int Y=200) void Execute(int &B,int C=200)
{ {
int TEMP=X+Y; int TEMP=B+C;
X+=TEMP; B+=TEMP;
if(Y!=200) if(C==100)
cout<<TEMP<<X<<Y<<endl; cout<<TEMP<<B<<C<<endl;
} }
void main(){ void main(){
int A=50,B=20; int M=90,N=10;
Exwcute(B); Exwcute(M);
cout<<a<<B<<endl; cout<<M<<N<<endl;
Exwcute(A,B); Exwcute(M,N);
cout<<A<<B<<endl; cout<<m<<N<<endl;
} }

Ans. (i) Output: (ii) Output:


50240 38010
290340240 77010
340240
32 Find the output of the following program:
#include<iostream.h>
#include<ctype.h>
void MyCode(char Msg[],char CH)
{
for(int Cnt=0;Msg[cnt]!='\0';Cnt++)
{
if(Msg[Cnt]>='B' && Msg[Cnt]<='G')
Msg[Cnt]=tolower(Msg[Cnt]);
else
if(Msg[Cnt]>='A' && Msg[Cnt]<='a')
Msg[Cnt]=CH;
else
if(Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt-1];
}
}
void main(){
char MyText[]="ApEACeDriVE";
MyCode(MyText,'@');
cout<<"NEW TEXT:"<<MyText<<endl;
}
Ans. (i) Output: NEW TEXT:@@e@ccddI@e
33 Find the output of the following program:
#include<iostream.h>
struct Package
{
int Length,Breadth,Height;
};
void Occupies(Package M)
{
cout<<M.Length<<"x"
<<M.Breadth<<"x";
cout<<M.Height<endl;
}
void main()
{
Package P1={100,150,50},P2,P3;
++P1.Length;
Occupies(P1);
P3=P1;
++P3.Breadth;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Breadth+=50;
P2.Height--;
Occupies(P2);
}
Ans. Output:
101x150x50
101x152x50
101x202x49
34 What values will be assigned to the variables ua, ub, uc and fail after the execution of the following program
segment:
void main(){
int i=0,ua=0,ub=0,uc=0,fail=0;
while(i<=5)
{
switch(i++)
{ case 1:
case 2: ++ua;
case 3:
case 4: ++ub;
case 5: ++uc;
default: ++fai;
} //switch
} //while
cout<<ua<<endl;
cout<<ub<<endl;
cout<<uc<<endl;
cout<<fail<<endl;
}
Ans. Values assigned to the variables ua, ub, uc and fail after the execution are as following:
ua = 2
ub = 4
uc = 5
fail = 6
35 What is wrong with this code:
cout<<" " Enter n:";
cin>>n;
if(n<0)
cout<<"That is negative."
<<"Please enter again"<<endl;
cin>>n;
else
cout<<"O.K. n="<<n<<endl;
Ans. There are following errors in above code:
(i) Imbalance Double quotes are in first statement.
(ii) There are more than one statement in ‘if’ statement without braces which is not valid.
36 Identify the possible error(s) in the following code fragment. Discuss the reason(s) of error(s) and correct the code:
cin>>i>>j;
while(i<j)
cout<,i*j;
i++;
Ans. Correct code:
cin>>i>>j;
while(i<j)
{
cout<<i*j;
i++;
}
Reasons of errors:
(i) There is a use of ‘<,’ in cout statement instead of ‘<<’ which is not valid.
(ii) while statement should be in curly braces otherwise it will not work properly.
37 Given the following code fragment:
i=2;
start:
cout<<i;
i+=2;
if(i<51) goto start;
cout<<"\nThank You";
Rewrite the above code using a while loop.
Ans. int i=2;
while(i<51)
{
cout<<i;
i+=2;
}
cout<<"\nThank You";
38 Is it necessary to include a header file in a program? If it is not done, what happens?
Ans. No, it is not necessary to include header file in a C++ program at all.
A header file is included if only the program intends to use the functions or macros etc. defined in that particular
header file.
39 Name the header files that shall be needed for the following code:
void main(){
char Text[]="Computer";
cout<<setw(15)<<Text;
}
Ans. (i) iomanip.h for setw()
(ii) iostream.h for cout
40 Briefly describe the importance of iostream.h file.
Ans. iostream.h is most important header file for basic input and output operations. iostream.h contain built-in functions
cout and cin for input-output. So, every C++ program should include iostream.h header file for performing input and
output operations.
41 How do the following two statements differ in operation?
cin>>ch;
cin.get(ch);
Ans. The difference between cin>>ch and cin.get(ch) is that when >> operator is used, the white spaces (e.g., tabs), spaces
etc. and new-line characters are ignored whereas it is not so with cin.get(ch).
42 What is an array? What is the need for array?
Ans. Array: An array is a collection of variables of the same type that are referenced by a common name.
Need for array: Arrays are very much useful in a case where many variables of the same (data) types need to be
stored and processed.
For example, suppose we have to write a program in which can accept salary of 50 employees. If we solve this
problem by making use of variables, we need 50 variables to store employee’s salary. Remembering and managing
these 50 variables is not an easy task and it will make the program a complex and lengthy program. This problem can
be solved by declaring 1 array having 50 elements; one for employee’s salary. Now we only have to remember the
name of that 1 array.
43 What do you understand by two-dimensional arrays? State some situation that can be easily represented by two-
dimensional arrays.
Ans. Two-dimensional array: A two-dimensional array is an array in which each element is itself an array. For instance, an
array A[m][n] is an M by N table with M rows and N columns containing M x N elements. Two-dimensional arrays are
used to represent tables, matrices, etc.
For example, below marks table can be represented easily by 2D array :
Maths Physics Chemistry CS Englisg Toal
Amit 60 64 64 82 79 349
Chandar 84 70 82 79 69 349
Lalit 79 68 86 87 85 698
44 Can you think of a difference between an array of strings and other two-dimensional arrays? What is it? Support
your answer with examples.
Ans. Array of strings Two-dimensional array
Array of string is used to store string value. Two-dimensional array is used to store numeric value.
The first index determines the number of strings and The first index determines the number of rows and the
the second index determines maximum length of second index determines maximum columns of each string.
each string.
Example: Example:
int a[2][3]; char string[3][31];
int i,j; int i;
for(i=0;i<2;i++) cout<<"Enter 3 strings:";
{ for(i=0;i<3;i++)
for(j=0;j<3;++j) cin.getline(string[i],31);
{
cout<<"Enter element:";
cin>>a[i][j];
}
}
45 If an array is initialized at the time of declaration, what thing one must bear in mind?
Ans. The general form of array initialization is as shown below:
type array-name[size N] = {value-list};
If an array is initialized at the time of declaration, following thing one must bear in mind:
 The element values in the value-list must have the same data type as that of type, the base type of the array.
 In character array, you must make sure that the array you declare is long enough to include the null.
46 What is meant by unsized array initialization in C++? What are its benefits?
Ans. Unsized array initialization means skip the size of the array I an initialization statement. The C++, then automatically
creates an array big enough to hold all the initializers present and calculates the dimensions of unsized arrays.
Example: char S1[] = “First String”;
Advantages:
 Less tedious.
 Allow to change any of the values without fear of using incorrect array dimensions.
 We may lengthen or shorten the value-list without changing the array dimensions.
47 What do you meant by function prototyping? Write down the advantages of function prototypes in C++.
Ans. A function prototype is a declaration of the function that tells the program about the type of value return by the
function the number and type of arguments.
Example: int sum(int a, int b);
Advantages:
 Enables a compiler to carefully compare each use of the function with the prototype to determine whether
the function is invoked properly i.e., the number and type of arguments are compared and any wrong number
or type of the arguments is reported.
 Tells the program about the return type
 Tells the program the number and type of arguments.
48 What are actual and formal parameters of a function?
Ans. The arguments passed to the functions while the function is called is known as the actual arguments, whereas the
arguments declared in the function header is called as formal arguments.
Ex. Suppose sum() is a function.
int sum(int x, int y) /*Here x and y are called formal arguments*/
{...}
void main() {
int ans;
....
ans = sum(3,5); /*Here the arguments 3 and 5 are called actual arguments*/
...
getch();
}
49 Construct function prototype for descriptions given below:
test() takes no arguments and has no return value.
convert() takes a float argument and returns an int.
promote() takes two double arguments and returns a double.
sum() takes an int array and an int value and returns a long result.
check() takes a string argument and returns an int.

Ans. (i) void test();


(ii) int convert(float a);
(iii) double promote(double a, double b);
(iv) long sum(int a[], int b);
(v) int check(string s);
50 What do you understand by default arguments and constant argument? Write a short note on their usefulness.
Ans. Default arguments: C++ allows us to assign default values to a function’s parameters which are useful in case a
matching argument is not passed in the function call statement. The default values are specified at the time of
function declaration. Example: float interest(float principal, int time, float rate=0.10);
Constant argument: By constant argument, it is meant that the function cannot modify these arguments. In order to
make an argument constant to a function, we can use the keyword const as shown : int sum (const int a, const int b);
The qualifier const in function prototype tells the compiler that the function should not modify the argument. The
constant arguments are useful when functions are called by reference.
51 How is call-by-value method of function invoking different from call-by-reference method? Give appropriate
examples supporting your answer.
Ans. Call By Value Call by reference
 In call by value method, the called function  In call by reference method, the called function
creates its own copies of the original values send accesses ad works with the original values using their
to it. references.
 The changes done in the function in formal  The changes done in the function are reflected back
parameter are not reflected back in the calling in the calling environment.
environment.
 It does not use the ‘&’ sign  It use ‘&’ sign as the reference operator.
Example: Example:
#include <iostream.h> #include <iostream.h>
void change(int x, int y){ void change(int *x, int *y){
x = 10; /*change the value of x */ *x = 10; /*change the value of x */
y = 20; /*change the value of y */ *y = 20; /*change the value of y */
} }
void change(int x, int y); void change(int *x, int *y);

void main (){ void main (){


// local variable declaration: // local variable declaration:
int a = 100; int a = 100;
int b = 200; int b = 200;

cout<<"Before value of a "<<a <<endl; cout<<"Before value of a "<<a <<endl;


cout<<"Before value of b "<<b<< endl; cout<<"Before value of b "<<b<< endl;
change(a, b); change(&a, &b);
cout<<"After value of a "<<a<<endl; cout<<"After value of a "<<a<<endl;
cout<<"After value of b "<<b<<endl; cout<<"After value of b "<<b<<endl;
} }

52 Discuss the similarities and difference between global and local variables in terms of their lifetime and scope.
Ans. Local variable Global variable
 It is a variable which is declared within a  It is a variable which is declared outside all
function or within a compound statement. the functions.
 It is accessible only within a function/compound  It is accessible throughout the program
statement in which it is declared
 A global variable comes into existence when the  A local variable comes into existence when
program execution starts and is destroyed when the function is entered and is destroyed
the program terminates. upon exit.
Example:
#include <iostream.h>
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{
int Total=0; //Total is a local variable
for (int I=0;I<T;I++)
Total+=I; cout<<NUM+Total;
}
void main(){
LOCAL(45);
}

53 What is structure? Declare a structure in C++ with name, roll number and total marks as components.
Ans. A structure is a collection of variables referenced under one name. A structure is declared using the keyword struct as
in following syntax:
struct <structure tag>
{
[public:] | [private:] | [protected:]
/* data members’ declarations */
/* member functios’ declarations */
};
Example:
struct Student
{
char Name[30];
int Rollno;
float Total_Marks;
};
54 What are Nested structures? Give an example.
Ans. A structure within a structure is called nested structures.
Example:
struct addr //structure tag
{
int houseno;
char area[26];
char city[26];
char state[26];
};
struct emp //structure tag
{
int empno; See, address is a structure variable itself and it is
char name[26]; member of another structure, the emp structure.
char desig[16];
addr address;
float basic;
};
emp worker; // create structure variable
The structure emp has been defined having several elements including a structure address also. The
address is itself a structure of type addr. While defining such structures are defined before outer structures.
55 Write a program that asks the user to enter two integers, obtains the two numbers from the user, and outputs the
large number followed by the words “is larger by – units than smaller number” to the system console (e.g., if the
larger number is 9 and smaller is 6, message should be “9 is larger by 3 units than smaller number”).
If the numbers are equal print the message “These numbers are equal”.
Ans. #include<iostream.h>
#include<conio.h>
void main()
{
int a,b,dif;
clrscr();
cout<<"Enter a:";
cin>>a;
cout<<endl<<"Enter b:";
cin>>b;
if(a>b)
{
dif=a-b;
cout<<a<<"is larger by"<<dif<<"units than smaller number"<<endl;
}
else if(b>a)
{
dif=b-a;
cout<<b<<"is larger by"<<dif<<"units than smaller number"<<endl;
}
else
cout<<"These numbers are equal"<<endl;
getch();
}
56 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of
CNG by recording the miles driven and the gallons used for each tank.
Develop a C++ program that will input the kilometers driven and gallons used for each tank.
The program should calculate and display the kilometers per gallon obtained for each tank of gasoline.
After processing all input information, the program should calculate and print the average kilometers per gallon
obtained for all tanks.
 Formulate the algorithm as flowchart.
 Write a C++ program as instructed.
 Test, debug, and execute the C++ program.
Ans. #include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int tanks=0;
float tot_km; float avg_k_p_g;
cout<<"Enter how many tanks filled :";
cin>>tanks;
float *kms=new float[tanks];
float *gallons_used=new float[tanks];
float *k_p_g=new float[tanks];
for(int i=0;i<tanks;i++)
{
cout<<"Enter how much kilometers covered for tank "<<i+1<<" ";
cin>>kms[i];
cout<<"Enter how much gallon used from tank "<<i+1<<" ";
cin>>gallons_used[i];
k_p_g[i]=kms[i]/gallons_used[i];
cout<<"KMs per Gallon obtained for tank No. "<<i+1<<" "<<k_p_g[i]<<endl;
tot_km+=k_p_g[i];
cout<<endl;
}
avg_k_p_g=tot_km/tanks;
cout<<"Average kilometers per gallon obtained for all tanks is "<<avg_k_p_g;
getch();
}
CHAPTER-2
OBJECT ORIENTED PROGRAMMING
VERY SHORT/ SHORT ANSWER QUESTIONS
1. Discuss major OOP concepts briefly.
Ans. Following are the general OOP concepts:
1. Data Abstraction: Data abstraction means, providing only essential information to the outside word and hiding
their background details i.e. to represent the needed information in program without presenting the details.
2. Data Encapsulation: The wrapping up of data and operations/functions (that operate o the data) into a single unit
(called class) is known as Encapsulation.
3. Modularity: Modularity is the property of a system that has been decomposed into a set of cohesive and loosely
coupled modules.
4. Inheritance: Inheritance is the capability of one class of things to inherit capabilities or properties from another
class.
5. Polymorphism: Polymorphism is the ability for a message or data to be processed in more than one form.
2. What are programming paradigms? Give names of some popular programming paradigms.
Ans. Programming Paradigm: A Programming Paradigm defines the methodology of designing and implementing
programs using the key features and building blocks of a programming language.
Following are the different programming paradigms:
(i) Procedural Programming
(ii) Object Based Programming
(iii) Object Oriented Programming
3. What are the shortcomings of procedural and modular programming approaches?
Ans. Following are the various shortcomings of procedural and modular programming approaches:
 Procedural Programming is susceptible to design changes.
 Procedural Programming leads to increased time and cost overheads during design changes.
 Procedural and Modular programming both are unable to represent real world relationship that exists among
objects.
 In modular programming, the arrangement of the data can’t be changed without modifying all the functions that
access it.
4. Write a short note on OO programming.
Ans. OOP stands for Object Oriented Programming. In, Object-Oriented Programming (OOP), the program is organized
around the data being operated upon rather than the operations performed. The basic idea behind OOP is to
combine both, data and its functions that operate on the data into a single unit called object.
Following are the basic OOP concepts:
1. Data Abstraction 2. Data Encapsulation 3. Modularity
4. Inheritance 5. Polymorphism
5. How does OOP overcome the shortcomings of traditional programming approaches?
Ans. OOP provides the following advantages to overcome the shortcomings of traditional programming approaches:
 OOPs is closer to real world model.
 Hierarchical relationship among objects can be well-represented through inheritance.
 Data can be made hidden or public as per the need. Only the necessary data is exposed enhancing the data
security.
 Increased modularity adds ease to program development.
 Private data is accessible only through designed interface in a way suited to the program.
6. Write a short note on inheritance.
Ans. Inheritance enables us to create new classes that reuse, extend, and modify the behavior that is defined in other
classes. The class whose members are inherited is called the base class, and the class that inherits those members is
called the derived class. A derived class can have only one direct base class. Inheritance is transitive.
When we define a class to derive from another class, the derived class implicitly gains all the members of the base
class, except for its constructors and destructors.
7. What are the advantages offered by inheritance?
Ans.  Inheritance ensures the closeness with the real-world models.
 Allows the code to be reused as many times as needed. The base class once defined and once it is compiled,
it need not be reworked.
 We can extend the already made classes by adding some new features.
 Inheritance is capable of simulating the transitive nature of real-world’s inheritace, which in turn saves on
modification time and efforts, if required.
8. Do you think OOP is more closer to real world problems? Why? How?
Ans. Yes, OOP is more closer to real world problems because object oriented programming implement inheritance by
allowing one class to inherit from another. Thus a model developed by languages is much closer to the real world. By
implementing inheritance, real-world relations among objects can be represented programmatically.
9. How are classes and objects implemented in C++?
Ans. A class is a blueprint for object. A class is implementing with the help of an object. Suppose a class has a member
function named display(). Now, to implement that member function display we have to use object of that class.
The objects is implemented in software terms as follows:
(i) characteristics / attributes are implemented through member variables or data items of the object.
(ii) behavior is implemented through member functions called methods.
(iii) It is given a unique name to give it identify.
10. What is the significance of private, protected and public specifiers in a class?
Ans. A class groups its members into three sections: private, protected, and public. The private and protected members
remain hidden from outside world. Thus through private and protected members, a class enforces data-hiding. The
public members are accessible everywhere in a program.

11. While implementing encapsulation, abstraction is also implemented. Comment.


Ans. Abstraction is the act of representing essential features without including the background details. Encapsulation is
the way of combining both data and the functions that operate on the data under a single unit. Encapsulation is the
way of implementing abstraction. Thus, it is true that while implementing encapsulation, abstraction is also
implemented.
12. Discuss the relation between abstract and concrete classes.
Ans. In C++ an Abstract Class is the one, which defines an interface, but does not necessarily provide implementation for
all its member functions. An abstract class is meant to be used as the base class from which other classes are derived.
The derived class is expected to provide implementations for the member functions that are not implemented in the
base class. A derived class that implements all the missing functionality is called a Concrete Class. A concrete class
derives from its abstract class.
13. Illustrate the concept of Inheritance with the help of an example.
Ans. Inheritance is the capability of one class to inherit properties from another class. For instance, Student is a class
wherefrom class GraduateStudent inherits as given below:
class Student
{
protected:
char name[25];
int rollno;
public:
void readStudent();
void showStudent();
};
class GraduateStudent:protected Student
{
protected:
char subjects[50];
public:
void readAradStud();
void showGradStud();
};
14. Encapsulation is one of the major properties of OOP. How is it implemented in C++?
Ans. A class binds together data and its associated functions under one unit thereby enforcing encapsulation as
encapsulation means wrapping up data and associated functions together into a single unit. While implementing
encapsulation, following things are taken care of:
(i) Anything that an object does not know or cannot do is excluded from the objects.
(ii) Encapsulation is used to hide unimportant implementation details from other objects.
(iii) The data and associated functions are wrapped up in one unit called class.
Through encapsulation, an interface is made available to world through which users can use the class.
15. Reusability of classes is one of the major properties of OOP. How is it implemented in C++?
Ans. Reusability of classes is implemented through inheritance in C++. Inheritance is implemented by specifying the name
of the (base) class from which the class being defined (the derived class) has to inherit from.
It is done with the following syntax:
class<derived class name> : <base class name>
{
<- derived class own features.
}
16. How is polymorphism implemented in C++?
Ans. C++ implements polymorphism through virtual functions, overloaded functions and overloaded operators.
The term ‘overloaded function’ refers to a function having one name and more than one distinct meaning.
For example,
float area(float a)
{
return a*a;
}
float area(float a,float b)
{
return a*b;
}
TYPE C : LONG ANSWER QUESTIONS
1. Write briefly about different programming paradigms.
Ans. Programming Paradigm: A Programming Paradigm defines the methodology of designing and implementing
programs using the key features and building blocks of a programming language. Following are the different
programming paradigms:
(i) Procedural Programming: Procedural programming paradigm lays more emphasis on procedure or the algorithm.
Data is considered secondary. Data is loosely available to many functions. This paradigm is: Decide which procedure
we want; use the best algorithm we can find.
(ii) Object Based Programming: In object based programming, data and its associated meaningful functions are
enclosed in one single entity a class. Classes enforce information hiding and abstraction thereby separating the
implementation details and the user interface. It also supports user-defined types.
(iii) Object Oriented Programming: Object oriented programming offers all the features of object based programming
and overcomes its limitation by implementing inheritance. The object oriented approach views a problem in terms of
objects involved rather than procedure for doing it. We can define the object oriented programming (OOP) paradigm
as following: Decide which classes and objects are needed; provide a full set of operations for each class.
2. Discuss OOP concepts. How are these implemented in software terms in C++?
Ans. Following are the general OOP concepts:
1. Data Abstraction: Abstraction refers to the act of representing essential features without including the
background details or explanations. Abstraction is implemented through public members of a class, as the outside
world is given only the essential and necessary information through public members, rest of the things remain
hidden.
2. Data Encapsulation: The wrapping up of data and operations/functions (that operate o the data) into a single unit
(called class) is known as Encapsulation. Encapsulation is implemented with the help of a class as a class binds
together data and its associated function under one unit.
3. Modularity: The act of partitioning a program into individual components is called modularity. C++ implements
modularity through separately compiled files. The traditional practice in the C++ community is to place module
interface in files named with a .h suffix; these are called header files which can be used through #include directive.
4. Inheritance: Inheritance is the capability of one class of things to inherit capabilities or properties from another
class. Inheritance is implemented in C++ by specifying the name of the (base) class from which the class being
defined (the derived class) has to inherit from.
5. Polymorphism: Polymorphism is the ability for a message or data to be processed in more than one form. C++
implements polymorphism through virtual functions, overloaded functions and overloaded operators.

4
CHAPTER-3
Function Overloading
SHORT ANSWER QUESTIONS
1. How does the compiler interpret more than one definitions having same name? What steps does it follow to
distinguish these?
Ans. The compiler will follow the following steps to interpret more than one definitions having same name:
(i) if the signatures of subsequent functions match the previous function’s, then the second is treated as a re-
declaration of the first.
(ii) if the signature of the two functions match exactly but the return type differ, the second declaration is treated as
an erroneous re-declaration of the first and is flagged at compile time as an error.
(iii) if the signature of the two functions differ in either the number or type of their arguments, the two functions are
considered to be overloaded.
2. Discuss how the best match is found when a call to an overloaded function is encountered? Give example(s) to
support your answer.
Ans. In order to find the best possible match, the compiler follows the following steps:
1. Search for an exact match is performed. If an exact match is found, the function is invoked. For example,
2. If an exact match is not found, a match trough promotion is searched for. Promotion means conversion of integer
types char, short, enumeration and int into int or unsigned int and conversion of float into double.
3. If first two steps fail then a match through application of C++ standard conversion rules is searched for.
4. If all the above mentioned steps fail, a match through application of user-defined conversions and built-in
conversion is searched for.
For example,
void afunc(int);
void afunc(char);
void afunc(double);
afunc(471); //match through standard conversion. Matches afunc(int)
3. Discuss the benefits of constructor overloading. Can other member function of a class be also overloaded? Can a
destructor be overloaded? What is your opinion?
Ans. Constructor overloading are used to increase the flexibility of a class by having more number of constructors for a
single class. By this we can initialize objects more than one way.
Yes, Other member function of a class can also be overloaded.
A destructor cannot be overloaded.
4. Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming used
in the following program jointly illustrated by the functions [I] to [IV]:

#include<iostream.h>
void Line() //Fuction [I]
{ for(int L=1;L<=80;L++) cout<<"-";
cout<<endl;
}
void Line(int N) //Fuction [II]
{ for(int L=1;L<=N;L++) cout<<"*";
cout<<endl;
}
void Line(char C,A,int N) //Fuction [III]
{ for(int L=1;L<=N;L++) cout<<C;
cout<<endl;
}
void Line(int M,int N) //Fuction [IV]
{ for(int L=1;L<=N;L++) cout<<M*L;
cout<<endl;
}
void main()
{ int A=9,B=4,C=3;
char K='#';
Line(K,B);
Line(A,C);
}
Ans. Output:
####
9 18 27
The name of feature of Object Oriented Programming used in the above program jointly illustrated by the functions
[I] to [IV] is known as ‘function overloading’.
5. Here are some desired effects. Indicate whether each can be accomplished with default arguments, with function
overloading, with both, or which neither. Provide appropriate prototypes.
(i) repeat (10, ‘-‘) displays the indicated character (‘-‘ in this case) given number of times (10 here). While repeat()
displays ‘*’ character 12 times. Also repeat(‘#’) displays the given character (‘#’ here) 12 times and repeat (7)
displays ‘*’ given no of times (7 here).

(ii) average (4,7) returns int average of two int arguments, while average (4.0, 7.0) returns the double average of
two double values.

(iii) mass (density, volume) returns the mass of an object having a density of density and a volume of volume,
while mass (density) returns the mass having a density of density and a volume of 1.0 cubic meters. All quantities
are type double.

(iv) average (4,7) returns an int average of the two int arguments when called is one file, and it returns a double
average of the two int arguments when called in a second file in the same program.

(v) handle (a-character) returns the reversed case of the passed character or prints it twice depending upon
whether you assign the return value to it or not.
Ans. (i) It can be accomplished with function overloading.
void repeat(int n, char c);
void repeat();
void repeat(char c);
void repeat(int n);

(ii) It can be accomplished with function overloading.


int average(int a,int b);
double average(double a,double b);

(iii) It can be accomplished with default argument.


double mass (density d, volume v);
double mass(density d, volume v=1.0);

(iv) It can be accomplished with function overloading.


int average(int a,int b);
double average(int c,int d);

(v) It can be accomplished with function overloading.


char handle(char a);
void handle(char a);
6. Write function definitions for question 7 on page 119.
Ans. int themax(int a)
{
return a;
}
int themax(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int themax(int a[])
7. Write function definitions for question 8 on page 119.
Remember that cube’s volume is side3
Cylinder’s volume is πr2h
Rectangular box’s volume is length x breadth x height.
Ans. float volume(float side)
{
return side*side*side;
}
float volume(float radius, float height)
{
return 3.14*radius*radius*height;
}
float volume(float length, float breadth, float height);
{
return length*breadth*height;
}
8. Write definitions for two versions of an overloaded function. This function’s 1st version sum() takes an argument,
int array, and returns the sum of all the elements of the passed array. The 2nd version of sum() takes two
arguments, an int array and a character (‘E’ or ‘O’). If the passed character is ‘E’, it returns the sum of even
elements of the passed array and is the passed character is ‘O’, it returns the sum of odd elements. In case of any
other character, it returns 0 (zero).
Ans. int sum(int a[])
{
int n,sum=0;
cout<<"Enter n:";
cin>>n;
for(int i=0;i<n;i++)
{
sum=sum+a[i];
}
return sum;
}
//
int sum(int a[],char c)
{
int even=0,odd=0;
switch(c)
{
case 'E':
for(int i=0;i<5;i++)
{
if(a[i]%2==0)
{
even=even+a[i];
}
}
return even;
case 'O':
for(int j=0;j<5;j++)
{
if(a[j]%2!=0)
{
odd=odd+a[j];
}
}
return odd;
}
}
9. Compare the usefulness of default argument and function overloading, supporting your answer with appropriate
examples.
Ans. Default values can be provided the function prototype itself and the function may be called even if an argument is
missing. But there is one limitation with it, if you want to default a middle argument, then all the argument on its
right must also be defaulted. For instance, consider the following function prototype: float amount(float p,
int time=2, float rate=0.08);
cout<<amount(2000,0.13);
Here, C++ will take 0.13 to be the argument value for time and hence invoke amount() with values 2000, 0(0.13
converted to int) and 0.08

Function overloading can handle all possible argument combinations. It overcomes the limitation of default
argument but also compiler is saved from the trouble of testing the default value.
Example:
float area(float a)
{
return a*a;
}
float area(float a,float b)
{
retur a*b;
}
10. Raising a number n to a power p is the same as multiplying n by itself p times. Write as overloaded function
power() having two versions for it. The first version takes double n and int p and returns a double value. Another
version takes int n and int p returning int value. Use a default value of 2 for p in case p is omitted in the function
call.
Ans. double power(double n,int p=2)
{
double res=pow(n,p);
return res;
}
int power(int n,int p=2)
{
int res=pow(n,p);
return res;
}
LONG ANSWER QUESTIONS

1. Given below are incomplete definitions of two classes:


class Item {
int itemno;
char description[21];
int QOH; // Quantity-On-Hand
int ROL; // Reorder-Level
int ROQ; // Reorder-Quantity
public:
:
// Overloaded Constructor Definition
void purchase(int n)
{
: // adds n to QOH
}
void sale(int n)
{
: // subtracting n from QOH
}
void display(void)
{
// display item details
}
};
class store{
Item itemlist[50];
//List of 50 items
:
public:
: //constructor(s)
new()
{
:
//To add new item into itemlist
}
delete()
{
: //To delete new item into itemlist
}
order(itemno, qty)
{
: //To order qty pieces for itemno
}
order()
{
: //check which item's QOH is
: // below their ROL, then order for
: // ROQ pieces for all those itemnos
}
bill()
{
: //Ask itemno, qtysold and
: // prepare the bill. Also update
: // Item's information by
: // calling purchase() of Item.
}
};

Using above information, write a complete C++ program that lets you sell, purchase or order a specific item or
items.
Ans. Code snippet of the above problem is given below use it and complete the program.

You might also like