Mid exam - Icivil-Hu

Transcription

Mid exam - Icivil-Hu
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form A
University of Jordan
King Abdullah School of Information Technology
Department of Computer Science
Computer Skills II (Scientific Faculties) / Midterm Exam
Student Name:
Section No.:
Student ID:
Instructor.:
Note: Answer ques on 1 here.
Syntax Error
Correction
1
#include <iostream>;
#include <iostream>
2
Using namespace ;
using namespace std;
3
doubl av;
double av;
4
Else without if
Remove ; from end of if
5
For(int i=0;i<5;i+)
for(int i=0;i<5;i+)
6
For(int i=0;i<5;i+)
For(int i=0;i<5;i++)
7
cin<<number;
cin>>number;
8
<<number" Is Odd"<<endl;
<<number<<" Is Odd"<<endl;
9
Main function with no close brace
Add another } to the end of
program
10 number variable is not declared.
Add the following statement: int
number;
-١-
Instructor:Nabeel ALassaf
Nov 10th, 2007
Instructor:Nabeel ALassaf
Q1: Find and correct syntax error(s) in the following program.
(10 points)
#include <iostream>;
using namespace ;
void main ()
{
int a,b,max;
int x;
doubl av;
char z;
cout<<"Enter Two Integer Number:";
cin>>a>>b;
if(a>=b);
max=a;
else
max=b;
cout<<"Max="<<max<<endl;
For(int i=0;i<5;i+)
{
cout<<"Enter Integer Number:";
cin<<number;
if(number%2==0)
{
cout<<"Number "<<number<<" Is Even"<<endl;
else
cout<<"Number "<<number" Is Odd"<<endl;
}
}
-٢-
Instructor:Nabeel ALassaf
Form A
Nov 10th, 2007
Instructor:Nabeel ALassaf
Q2: What is the Output of the following Code Segments?
void main()
{
int x , y; double z;
string str = "";
char w;
Form A
(10 points)
Assume the input as
follows:
12 3.9 20
Hello
cin>>x>>z;
cin.get(w);
cin>>y;
getline(cin,str);
x += (str > "Hello" ? 10 : 100);
cout<<"x is:"<<x<<"\n"<<"y is:"<<y<<"\n"
<<"z is:"<<z<<"\n"<<"w is:"<<w<<"\n"
<<"str is:"<<str<<"\n";
}
void main()
{
int j = 12 , i = 4 ;
cout<<j--<<" "<<i<<'\n';
while( j > 9 )
{
switch( j ) {
case 10:
j++;
case 11:
cout<<(j % 5)<<" ";
case 12:
cout<<++j<<" ";
break;
default:
j += i/2;
break;
}
cout<<j<<"\n";
j -= 5; }
}
Stored Value For Each
Variable
x = 112
y = 20
z = 3.9
w = space
str = Empty String
Output
12 4
1 12 12
-٣-
Instructor:Nabeel ALassaf
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form A
Q3: Write a C++ code to read a group of integer values and calculate
the average of only even ones. The input should terminate at the time
of input for a negative integer.
(5 points)
#include<iostream>
using namespace std;
void main()
{
#include<iostream>
using namespace std;
void main()
{
int val, counter = 0;
è1 mark
double sum = 0 , avg;
cout<<"Enter a value: ";
è1 mark
cin>>val;
while(val >= 0)
è1 mark
{
if(val%2 == 0){
è1 mark
sum += val;
counter++;
}
cout<<"Enter a value: ";
cin>>val;
è1 mark
}
if(counter != 0)
{
avg = sum / counter;
è1 mark
cout<<avg<<'\n';
}}
-٤-
Instructor:Nabeel ALassaf
Instructor:Nabeel ALassaf
Nov 10th, 2007
Form A
Q4: Write a C++ code to input an integer value (assume its name is N)
and calculate the summation for the first N terms of the following
series: (Note: Don't use Pow function in your solution)
(5 points)
1
1
+
2
+
1
+
4
1
8
+
1
16
#include<iostream>
using namespace std;
void main()
{
double sum = 0;
è1 mark
int N, x = 1;
cout<<"Enter Number of terms:";
cin>>N;
è1 mark
è1 mark
for(int i = 1; i <= N ; i++)
{
sum += 1 / x;
x *= 2;
è1 mark
}
cout<<sum<<'\n';
è1 mark
}
-٥-
Instructor:Nabeel ALassaf
+
….
Instructor:Nabeel ALassaf
Nov 10th, 2007
Form B
University of Jordan
King Abdullah School of Information Technology
Department of Computer Science
Computer Skills II (Scientific Faculties) / Midterm Exam
Student Name:
Section No.:
Student ID:
Instructor.:
Note: Answer ques on 1 here.
Syntax Error
Correction
1
namespace std ;
using namespace std ;
2
Void main ();
void main ()
3
Char z;
char z;
4
if a>=b
if (a>=b)
5
for(int i=0;i<5;++)
for(int i=0;i<5;i++)
6
cin>>number
cin>>number ;
7
Else
else
8
<<number<<" Is Odd"endl;
<<number<<" Is Odd"<<endl;
9
return 0;
It should be removed because of
void main()
10 No end for main function
Place } at the end of main function
-١-
Instructor:Nabeel ALassaf
Nov 10th, 2007
Instructor:Nabeel ALassaf
Q1: Find and correct syntax error(s) in the following program.
(10 points)
#include <iostream>
namespace std ;
void main ();
{
int a,b,max;
int number,x;
double av;
Char z;
cout<<"Enter Two Integer Number:";
cin>>a>>b;
if a>=b
max=a;
else
max=b;
cout<<"Max="<<max<<endl;
for(int i=0;i<5;++)
{
cout<<"Enter Integer Number:";
cin>>number
if(number%2==0)
cout<<"Number "<<number<<" Is Even"<<endl;
Else
cout<<"Number "<<number<<" Is Odd"endl;
}
return 0;
-٢-
Instructor:Nabeel ALassaf
Form B
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form B
Q2: What is the Output of the following Code Segments?
(10 points)
void main()
Assume the input as
follows:
{
int z , y; double x;
34 2.4 19
string str = "";
Computer
char var;
Stored Value For Each
cin>>z>>x;
Variable
cin.get(var);
x = 102.4
cin>>y;
y = 19
getline(cin,str);
z = 34
w = space
x += (str != "Computer" ? 100 : 10);
str = Empty String
cout<<"x is:"<<x<<"\n"<<"y is:"<<y<<"\n"
<<"z is:"<<z<<"\n"<<"w is:"<<var<<"\n"
<<"str is:"<<str<<"\n";
}
Output
void main()
{
7 18
int x = 18 , y = 7 ;
3 16 16
cout<<y<<" "<<x--<<'\n';
while( x > 12 )
{
switch( x ) {
case 17:
y++;
case 14:
cout<<(y % 5)<<" ";
case 12:
cout<<--x<<" ";
break;
default:
y += x/2;
break;
}
cout<<x<<"\n";
x -= 5; }
}
-٣-
Instructor:Nabeel ALassaf
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form B
Q3: Write a C++ code to read a group of integer values and calculate
the average of only even ones. The input should terminate at the time
of input for a negative integer.
(5 points)
#include<iostream>
using namespace std;
void main()
{
#include<iostream>
using namespace std;
void main()
{
int val, counter = 0;
è1 mark
double sum = 0 , avg;
cout<<"Enter a value: ";
è1 mark
cin>>val;
while(val >= 0)
è1 mark
{
if(val%2 == 0){
è1 mark
sum += val;
counter++;
}
cout<<"Enter a value: ";
cin>>val;
è1 mark
}
if(counter != 0)
{
avg = sum / counter;
è1 mark
cout<<avg<<'\n';
}}
-٤-
Instructor:Nabeel ALassaf
Instructor:Nabeel ALassaf
Nov 10th, 2007
Form B
Q4: Write a C++ code to input an integer value (assume its name is N)
and calculate the summation for the first N terms of the following
series: (Note: Don't use Pow func on in your solu on)
(5 points)
1
1
+
2
+
1
+
4
1
8
+
1
16
#include<iostream>
using namespace std;
void main()
{
double sum = 0;
è1 mark
int N, x = 1;
cout<<"Enter Number of terms:";
cin>>N;
è1 mark
è1 mark
for(int i = 1; i <= N ; i++)
{
sum += 1 / x;
x *= 2;
è1 mark
}
cout<<sum<<'\n';
è1 mark
}
-٥-
Instructor:Nabeel ALassaf
+
….
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form C
University of Jordan
King Abdullah School of Information Technology
Department of Computer Science
Computer Skills II (Scientific Faculties) / Midterm Exam
Student Name:
Section No.:
Student ID:
Instructor.:
Note: Answer ques on 1 here.
Syntax Error
Correction
1
using name std ;
using namespace std ;
2
cin>>a,b;
cin>>a>>b;
3
max variable is undeclared
Add the following statement:
max;
4
cout<<"Max=<<max<<endl;
cout<<"Max="<<max<<endl;
5
for( i=0;i<5;i++)
for(int i=0;i<5;i++)
6
cout>>"Enter Integer Number:";
cout<<"Enter Integer Number:";
7
If(number%2=0)
If(number%2==0)
8
If(number%2=0); causes else
statement being without if
if(number%2=0) [ remove ; from the
end of if statement ]
9
<<number<<" Is Even"<<end;
<<number<<" Is Even"<<endl;
return 0;
It should be removed because of void
10
main()
-١-
Instructor:Nabeel ALassaf
int
Nov 10th, 2007
Instructor:Nabeel ALassaf
Q1: Find and correct syntax error(s) in the following program.
(10 points)
#include <iostream>
using name std ;
void main ()
{
int a,b;
int number,x;
double av;
char z;
cout<<"Enter Two Integer Number:";
cin>>a,b;
if(a>=b)
max=a;
else
max=b;
cout<<"Max=<<max<<endl;
for( i=0;i<5;i++)
{
cout>>"Enter Integer Number:";
cin>>number;
if(number%2=0);
cout<<"Number "<<number<<" Is Even"<<end;
else
cout<<"Number "<<number<<" Is Odd"<<endl;
}
return 0;
}
-٢-
Instructor:Nabeel ALassaf
Form C
Nov 10th, 2007
Instructor:Nabeel ALassaf
Q2: What is the Output of the following Code Segments?
void main()
{
int x , y; double z;
string str = "";
char w;
Form C
(10 points)
Assume the input as
follows:
56 13.9 29
Good
cin>>x>>z;
cin.get(w);
cin>>y;
getline(cin,str);
y += (str > "GOOD" ? 20 : 50);
cout<<"x is:"<<x<<"\n"<<"y is:"<<y<<"\n"
<<"z is:"<<z<<"\n"<<"w is:"<<w<<"\n"
<<"str is:"<<str<<"\n";
}
void main()
{
int k1 = 14 , k2 = 6 ;
cout<<k2--<<" "<<k1<<'\n';
while( k1 > 11 )
{
switch( k1 ) {
case 14:
k1++;
case 13:
cout<<(k2 % 5)<<" ";
case 12:
cout<<++k2<<" ";
break;
default:
k2 += k1/2;
break;
}
cout<<k1<<"\n";
k1 -= 5; }
}
Stored Value For Each
Variable
x = 56
y = 79
z = 13.9
w = space
str = Empty String
Output
6 14
0 6 15
-٣-
Instructor:Nabeel ALassaf
Nov 10th, 2007
Instructor:Nabeel ALassaf
Form C
Q3: Write a C++ code to read a group of integer values and calculate
the average of only even ones. The input should terminate at the time
of input for a negative integer.
(5 points)
#include<iostream>
using namespace std;
void main()
{
#include<iostream>
using namespace std;
void main()
{
int val, counter = 0;
è1 mark
double sum = 0 , avg;
cout<<"Enter a value: ";
è1 mark
cin>>val;
while(val >= 0)
è1 mark
{
if(val%2 == 0){
è1 mark
sum += val;
counter++;
}
cout<<"Enter a value: ";
cin>>val;
è1 mark
}
if(counter != 0)
{
avg = sum / counter;
è1 mark
cout<<avg<<'\n';
}}
-٤-
Instructor:Nabeel ALassaf
Instructor:Nabeel ALassaf
Nov 10th, 2007
Form C
Q4: Write a C++ code to input an integer value (assume its name is N)
and calculate the summation for the first N terms of the following
series: (Note: Don't use Pow func on in your solu on)
(5 points)
1
1
+
2
+
1
+
4
1
8
+
1
16
#include<iostream>
using namespace std;
void main()
{
double sum = 0;
è1 mark
int N, x = 1;
cout<<"Enter Number of terms:";
cin>>N;
è1 mark
è1 mark
for(int i = 1; i <= N ; i++)
{
sum += 1 / x;
x *= 2;
è1 mark
}
cout<<sum<<'\n';
è1 mark
}
-٥-
Instructor:Nabeel ALassaf
+
….
a
2010 C++
07919956314
Of
*uil
Xi1rr"Lt tf- f"U"-t"s t"
6t-,,r
+:J"'lt
",,,---i,i
;
iu-lt
rlsc
1
C+r identifiers?
1. RS6S6...
2. STOP!.
3. urn..--lrP .
4. ?*[iY --51
Long
.
.LrJi'rl
.
1
_
..;ii.
(3Frrr
ria 3 r-i.Jr;
JaiJ
ar*',.'+r r
I 4u.,
pf gsJY
(-)
!rq$
-;
r-r.r3gl
"'-, 1?#if.H"ffi?*d't
Eii
+r-g i,, ;-rri
;-:F*:li:lrru
oi*rr:dl 6r;$rt 3 rj''i.a.1.l3cJtr
zF4 an'llv:3'5
Q2) if x=5, y=6 '
'
? .. ' .
reason
the
state
p-ossible ,
-'
r'
"
,-,.
!x+z)4oY '
2. GiY\V.w.
3. (x%oY\4oz '
4. $4oz) 4ox'
5. ((x*y)*w)*Z.
'Jr'|;:"irOyU'
f,$r' E
'i'-'"1
evaluate each of the following-statements '
l.
,
ffi
5,,.4; L"
is not
,;.\
'^""' L.!
3
:
6 o/o g
11
o s = rls .j.
( 4 + s) (1 t.lll.r
i o +st tz-e4l
-g=1t
=
('FJd-]
s:(i% s)$ (tgJl
i,---G,-ujl
8! r6lt i"+or;s:6v"
pj*J"$ 4+F,:r
--,:it y" e) (t f_.'.u
tt-:'fiL-fl
: +sfr i-"^ru
s
l.t,'
#t
a r6t?1..-<r *.
su,i 6
*$r 3ir"
{rs;sto"+
eJil-l
i5 EJ,$
-,L'.u.,:,Erlt, ..'stt
-"+'i"--':I.:'r-sr
1
42t =
if possible' If it
,
(11-6'
!'1o " "
li1S Eij
gJllll
r l#"HrrfitISIo*l
2o1o
079 19956314
C#
i.1l-,i: u"-ii : 3u-'ll rlro!
qpi#^lt
:
Q3) Given
intnrmrk;
double xrY ;
are valid?
Which of the following assigaments
1, n=m=5;
2. m=k=n*2;
3. irx+B=k;
4. kl-1=n;
5. x/Y=x*Y;
(a)
*, dx''{il,Tl#'
'
H* i##ffi [ ;t
$ e!a,r r "+--;r r.r rav FE
i-:Ut +gill { .tti-Yl + -
rr+4=0)
to
to finit the value assipeil
Q4) Do a walk-tbrough
I
is E+r,
?
1)a=3;
2)b = 4;
l)c=(a 9ob)* 6i
4)d=c\b;
5j e=
(a+b
i ' ' ,,+
+ c+
d^ur,r, +i::
tl)/ d;
e-1r'il l'ii .r o1t i-,,ur
* x ur rio r u,lJ- a!
_:.rrr+ll
SYntax Error
L"'iJl i'rtil oY
Lsi""r
u;r grll JLJI cts
2010
c++
dit'Jl
Or+ u",-il
; 3{4"'Jl rll9!
o19 tg9s63l4
da&Eents?
of the fouowiDg
n<\ What is the outPut
I-indo{iliostteam'n'
int mun( )
t
,,
Worlil ! " ;
cout << EeIo
re6:rn 0 ;
)
statements?
of the fotlowing
o6) What is the output
i include <iostrearn'n'
int main( )
I
tt
sout >> welcome
return 0 ;
tt
;
Svntax Error .
L,r.l....\'ort:,'Jl dlY
)
(>>)
.
iaqur
r.1alP
rF)l
il"+i 1'-F
079 t9956314
: f,sfi
2010
C++
e'e
Q7) fr'hat is the output gf the fo[owing statements? .
# include
<iostrerT.li':- '
'1
Cl-,,a
iJ".lt
,
r-j''' . ;r'... ':''-\
,
rF--ji
: 3u,-Yt .rt.p t
)
int main( )
{
-; librl, I
Syntax Error
iLl
!#e di:t
Jt
4#
eFt,.,r<
Q8) What is the output of
# include <iostream.h-
th. e
eda.x
rr*1.
r-Lf
cl
tFJ i= G-rs,+,rlr allii
Le='s,a ;.,!all o3l
-i ul-GIt &Jri fui.
or
r os..
"r.l
return 0;
rjrJFj jip 1]i
fuSi J lle JS,i{
6ain ( )
. y6ifl
following statements?
>
int niain( )
{^
cout << aL{ello World
!'o;
SYntax
Ercr
, iJ,r# r!si,. u+l J ( rr !r ) &jJis dir 0J{ fuSJ Ot !a+J Alel+! +Ji. u4.r €l-Oy
2010
07919956314
C+r
c,s
0l-,..4, {--ji
jJ+all
t
the following statements?
Q9) What is the output of
<iostream'h>
iut main( )
{
cout-<<'(fIeIIo World ! "; tt
cout << " I'ta a C++ Program ;
return 0 ;
# include
.
:s.3;
f
FIelIo
_;
r;13{l
! I'm a C++ Program
6$ ) 3 stl .P- ,Je r.,l-
Worltl
6Y 411L- .Je
ei-ctr\ = '(Y)
--)
P.r
following statenents?
Q10) What is the output of the
# incluite-<iostream.b>
int main( )
J
t
?
t;a
cout <<
cout <<
" Elello Wotld \$r " ;tt
" I'rn a C+l Plogram I
return 0 ;
a.r.rc
.,i!;
3
I
us .y;tl
ie!! {i#
u'y":!r-Csa-r se
$ello Sorl{ ! \n I'm-a C++ Program
€:
Ci-'E+
;E g+ : rf!f{-
"b
eJ+
/9956314
079
:
2010C#
iYifr
al-,/r u.-jl
e l'*:l
;
iu-)l lt.r1
statements?
Q11) What is tLe output of the following
# inclutle <iostream.h>
intmainO
{
ir.Hello
v
World !-Vr " ;
eout <<
cout i< ..itr,m a C.r_r pr6gram
return 0 ;
.,@ (_
]
-:
u. tJ+ll
Error
dii-! ajl
SJ'ii'.ax
Lr;1 gr r..r.6.:.::; i.L$n Il elsi-l
!j'1,
J A'LJfir
i lttJll' !er CEI ..l!'{J
tL'G u+! J
'J''f
statements?
Q12) What is the output of the follqpiftg
# include <iostream'h>
)'
int main(
t.
r'nt
b
t-1
t t-\
(
r:c,;
t
t-
7-ii=\
\.-_a-'
result=a-b;
coui <<
return
('
" res';lt
;
-
0;
)
-: +l-r+ll
.eri"ts$BE';
aEjJSLlr&r!e..'^iyJ:Aidt+r-er:Lcfllit.ri.,41.aliJSs!.r11s!'r.,5*.3,rQIJrer!eeL,YJ!€
2010c#
o7919956314
Ol-rni
"PFl
U-i-----ri :
iu-ll
rt'P!
of the following statements?
Q13) What is the output
# include <iostrearo'h>
int main( )
t,ilrta:'5;
int riiiutt ;
a=5;
b =2;
a=z+ll
.^
1gsut1 = a
--.bj
cout << "' i'esult
refurn 0 ;
.(
"
;
........-*-.
-
c# *$e - eJ:ra r.o ) &lJ+itll e'+' t' e" t'V,g)Jffi
following statements?
O14) What is the output of the
i
include
tv2\
int main(
inta
cbar
<iostream'h>
)
.- \
)
(--.----
reiult;
a=5;
b--2;
a=a+1;
iesult=a-b;
"cout
i< " reiult
\1:
.-' i
\
i r'' i
";
return 0 I
)
', ,
. '.'
i
.-
.
'
-: +l-*ll
Slntax Error
,t'.i:.:t
ur,.,n:
ot
079 19956314
:
At-.ir u"---ii
zlluc+. ei-,Jit
c.-Yie,
; iu-Yt
st.lc1
Q15)Supposea,bandcareintvariahleaqda'=.5antlb=6'whatvalueisassignedto
*"n ,"ai"Ul" uft"a each statement executes?
'1.
a =.(i[.r-.t-; a.3 t
i=2* a+(++b);
3. b=2*(+-rc)-(a+r);
?^
. -:+l.dl
.*r
Q16) what
$:.it
1";1
.:t.1
4lJ 2 f-JlJ (1
. E- -#st'l.g:r2d cr r +-ri*lt !4eJ+
L"*
L1i
s;
;l-+
j
25 t'Jt (2
p6,as.,
4 tiiell
. |.a:r
43 flJll (3
'ir,icr t,7'
+iri
6.rr*r
will appear on the
F"Jll*!:ljliJ
,*rr
ee
tllt
tlll
screen after execlrting shis segment of cgile ?
inta=3,b= 4,c=51
i)
if ( a>z && c-b<2 ) cout <<".4"'';
2) if ( atz=L ll b>6) cout <<'8";
3) if ( !(c==s)lla<b ) cout8C";
4) if ( !(a+3>b-2 && a--=c-2 ) cout << D ;
5) if ( a/>lll {cca} ) cout <C'E";
. .r:i 6lrYl
. 6bl-.
!b1,,.
t+Ji
f5;5..a irJlJhI
4jy 1rl j^.rll
e,!ti1j$l
'++i
4I"t Sy 91r 1'+ (2 tJll
clr OJs: irr ':-sr fuil"li
- Lgulr ;rral
di'.f-!
lJ,il
G.elll
dC a J3$l
PLr 1.+
4!"+ (4 eJiil
- (,r J$rdl &Jrq + fj4iJ 'J!B
4j'J elLti il"+ (5 t.1lll
. C*. 8lJ5>! 4.dri o.UYl rls' ?ri3*l
u*,!i
-. J rtJL,,.
:
07919956314
Q17) what is
aJrE
thlfinal
value
2010 Cr-+
: 3g-!t Slc!
Al-dr Lr-jl
j:"lt
eP
is 9 ?
of x if the lritial value of x
>=0P
x=x+1;
if(x>=1)
: =x'+2
if (x
-: -,1,#J
. 6..u;rJr
rriji ilt, ie 'rra ;r
vYt li,l 3 6Jit+' r-il
il"+
Syntax'Error
it'otl r-p' ri
q trl$i'
?
output of the C++ cqile
Q18) what is the
x=5 i .:
if(x>10)
{ tout << " ,,Hello " I
Y_ cout
--*rr,<< There. "areI
{
Ho*
You ? " I
" "
(
#sl
There' How are You ?
.
Lit
!.JPill 4L+l
iF J'u -)p r'gf
;31:l r !n:]l'4l,oll
ril
J
"r
rL ;'L'+ t5r
g"
;iql
grtl
'6f"l d b'ir
oY
: 0#
07919956314
2010
C*+
q's
ir'"lt
Ol-..or
uj-il
; 3u-ft st.r1
?
Q19) what is the output of the C+r cotle
@_m=2I; if (r"frim <= 10 )
.. if (num>=0)
r-
cout <<
-
" Num
is between 0 antl 10
"
;
else
cout <<
u.li sJl ,il
" Num is greater than 10 "
CY
ili
lir r
.'i-
LiJ+ rj -;5..
;
r''&l
'
.
t|l-+
.r*''ll
-;
crJS;Jl
SYntax
Error
rE 41
d!F:i
.r.r.*5 cl e;#t
:r'it tr'-:lt.r lrr. t'r+ i"'t^
Jl J,sl.J '
c'!
Q20) what is the output of the C++ cotle ?
alPha = 5 ;
cin >> beta ;
switch (beta)
{
casel: alPha=alPha+1;
case2:alPha=alPha+2;
case3:alPha=alPha+3;
default : alPha = alPha + 4 ;
-:.rlf+ll
Warring
Lls et.ria.l esl
ifn
liA J
oyr-J &."+ ,Jo
*r
eis,
d}J 6,lU.lg!
ql.J'L;t,J,gi
!{r o+f # t
07s19956314 z
0#
2010
Cl.+ e'l}"Jt
gt.-,,s
4,-:l
?
Q23) what is the output of the C++ code
age=50;
_
switch {hge > 21)
{
true : cout <<'I-egal Age";
break ;
case false.]cout <<'Below Legal Age";
break ;
<< "Bail InPut"l
:
cout
default
case
(I)
CB4 OI!i: ll.ri3'i j'r
?
Q24) what is the output of the C++ code
alPha = 3 ;
// Assume inPut is 5
>> bufa
"io
switch (beta)
;
{
i case 3 : alPha = alPha + 3 ;
\ case' C : alPha= alPha+ 4 ;
break;
default : alPha = alPha + 5 ;
]
t2
-: +l.r+lt
Syntax Error
i'r:. t3l ?J'r!q Lgiliall lJ'aljll tlrsl-'
; 3u-!l
rtel
079 t9956314
t C#
2010 C++
6t-,.,,r cF--ji
,j'|"":t
code ?
Q25) what is the output of the C+r
int base = 2,'result;
swilch @ase)
{
casel:result=base;
break;
case 2 : result t= base ;
break;
x
*
case 3 : result = base base base I
break;
J"frit , cout << "your base number is too large" << entlll
)
. ;1i".31 i-.el
,+tI ;is$
@r-r: (rrll s^
-3r-r.l9..ll
AI
4
lrll
EJ+
?
Q2Q what is the output of the C+i code
inti=1;
white(i<=5) cout <<
.
"i
is
'p<<+ti
{Lriiall
,l,.tll
e.t
<< endl ;
c'J (j-
e-r!S
qIS $r
'srr.,*
crL$i
I
'slLti
A"+ s! .i$1"'!l
jp
Slntax Error
r''b3inlll ll"atiJl s'rr':l
2010
o79 t9956314
C+r
e's
irl-a u/L-ii
i,-lt
: ir:*yt rt.p!
Q27) wlat is tbe output of the C++ code ?
inf -i = 1;
whiieli > o )
{
i ='i+j;
j--;
)
cout << i I
_:
. u4.li u.ati s..Jl
lil
.,.3
&lri1*l
ii
Jil,A ql cir.,F: !+J
/jI
+l:+ll
Slntax Error
s+
.#Jt
!n-.,JFi
*J
Q28) rvhat is the output of the C++ code ?
inti=1;
,'- while(i >0)fl
{*
i=+-t-i;
j-;
)
cout <<
i
;
.
&lr Ir.J
-: crlJ+ll
Syntax Error
.Lyill .q LEji:* lJ.G rj-,r;l
2010
o1g t9956314
cr+ '/
j#'ll
iJt-,,,r
or-ii
: 3g"tt
ltP!
?
of the C++ coile
what is the oqtpui
o29)-ioti=1;intj=1;
-
1*"('offi+
i:i:-i;
j++ ;
]
*"' ".t
-: -Jr+ll
i**
,r
r'r'q$:
p
1t"+ ov
&Jr ol-ulr
&u4
r
e^uvr ee cFl cru+rJ
iiiti
ilE'
?
of the C++ code
o30) what is the output
int i = 1; int i;. 1;
while ( > 0r)11
-
{i=++i;
j++;
i*t"i;
.
Ll#'$'
uJ
tr+tr $
L!"+ Of t
r.'"r''rl1!"roJ&!'illi6'u';lt1-Aeslrc4,,'Id:'i
Ol-'rr'rn
&Jr
07919956314
t tfi
Ol-,ir L1,,.-ii
2010 C++ eP i.".lt
Q31) what is the value of counter after the following statements executes ?
.50 $*ll 6..r.51 51
eSJl AYI OIJJlj|
a-t
+
l-,.\6.
-: +lrtll
&{ 51 eJt El4
: 3U-!t lt,p!
07919956314
: O#
2010
C+r qI j*..J|
Ol-.ir cy-j
Q33) Suppose sum, num antlj are int variables , and the input is : 4
l+ ll+ e{-n
What is the output of the following eoile?
cin >> sum ;
cin >> num ;
7 12 9
-1
for(j=1;i<=3,i++)
{
ein >> num I
sum=Eum+num;
!
cout << sum << endl
;-Lji:. ,-!,.'+ A}3!
el j,r.
;
rl ia j€ill
_: +ls+ll
Lr+,!
'19 Al,r3.rll
it
+ ,Jitr
a!3fi.
iJ.aG
Syntax Error
r.ru d+ . ,J-E .r.e..d
..!,i3
Q34) Suppose input is :
5 3 4 -6
8
What is the value printed by the following C++ cotle?
int sum = 0 ; int num ; int i ;
cin >> num I
for(j=1;j<=5,j#)
t
cin >> num ;
if(uum<0)continue;
l
!
sum = sum + num ;
cout << sum << endl I
-;
r-r.
lja.ll
07919956314
t 0#
2010 C++
5 3 4 '6 I
Q35) Suppose input is :
What is the value printett by the followiog
int sum = 0 ; int num ; inti ;
cin >> num I
rl.g
j#Jl
C+r
&1-,,a Lp.---ii ; iU-,!t
code?
for(j=1;i<=s,i++)
{
cin >> num;
if(uum<0)eontenue;
sum=srrm+num;
]
cout << sum << enill I
.
Q3O what is the output of the C+r code ?
for (outer = 'F' ; outer >= 'A' I outer--)
{
for (inner = 'A' I inner <= outer ; innerr-r)
{
)
cout << inner I
cout << tt \n
)
"
I
ili
Jinjs
Lgi
-; cr. ljqJl
Syntax Error
!,iill ;.,!xill S,
lt.lc,1
079 199563L4
:
2010 C'{-+ er!
lil.eiJn
i,".lt
Al-,,a c1.'-jl
: 3u-Yt rl.re!
Q37) what is tbe output of the C+r code ?
for (outer = 'F' I outer >= 'A' ; outer-)
{
for (inner = 'A' I inner <= outer ; inner+r)
t
cout << inner ;
)
cout << tt /u
I
"
;
_:
. gE!,.l ;.,f.11 gl.!ii-l J,4yl J i.Li l3a J OJ'ilt ,.i.p g* ( / )
lJl,il
+tJ+ll
dii-l
L:Y
Q38) what is the output of the following C++ code ?
int x = 7 ; bool found = false ;
do
t
tt tt I
if(x<=2)founal=true;
cout << x <<
elsex=x-5;
) while (x > 0 && lfound);
cout << endl ;
u" e3.1ill f-.!.LJ"r,ll 6!.iJ
y2
$ill ieq! .q
j
i,,:- l3ll
19
i-ssll rri a}i C.uJCl O. eA tll'+
r2
-: trl:J. I
7 c*.!Jt eJ+
. CaUII
079 19956314
: ;'#
2010
C++ .;I
i+.ll
Al,-,jr
u*-ji
:
la.tt
rt,s!
Q39) what is the output of the following Cr-+ coile ?
t\tx=1 ; bool fotmd = false ;
do
t
cout << x <<
'
tt
tt
;
if(x<=2)found=true;
elsex=x-5;
)while(x>0&&lfound)
cout << endl I
C"uJCl
+i!
eq
f
Yl J
ifui,i. ii..Lq
-:+tJ+l
Syntax Error
,..{in
Oi
u+r drlr ;&+ ,ri 6Y
Q40) what is the output of the following C++ eoile ?
int x = 7 ; bool fotmd = false ;
do
{
cout << x <<
tt
tt
I
if(x<=2)found=true;
elsex=x-5;
]while(x>0&lfound)
cout << endl
;
, ( 4& ) lb $l ;JLrl tl.rii-l o--!
20
A q-U
-; .,. t3,;Jl
Syntax Error
<ts
tj6\l3 rrt3 ( ft ) sl i-,t&l
dii-l
1jy
'
UoiversitY of Jordan
KASTT-'semester
CoEpBter
Date:
Second exam
I
Tioe: I hr
.
oo?c{lEc/
SeatNumber:
Lecturer Narte:
Section #:
II
Ql
retum 0;) "
voiit funQne([n1& a,.int
stafiq int
fir$=-z;
b){
.
I
i ---------"-*y';
stt II [,
I lz., l1
_}o_$, I i
tZ
r-b-2j
r'ni=nnuu+
-,j1.{'T:"'
";
5
V
ilffii*"**df$P
V'
i,1_iHJlo,zr, #'r'
t _r.,,***
"#1ij#,C;
rt.1tto
the followinB:l3Ptsl
pr) and JOD'
Q2) WriG C+F statements that do
riro RO'
.roD- -- . Lirs'
*&"k' Dollar'
a) Define an enum typ",."u,o'"y-dp", *it t['" viue-t
to
Ro
assign
typd currercvS'pe aird
b) Dec!6re. a variable .ver*-ii"!
1i.ile
myCurreucY.
ti'"o"-ent) mycurr€nsy to the ne:it value
"lTa"-*""
value of the variable myCurrency'
tle
d) Ougut
Mv answer
;t'f
B)
'.....(t? L
r( );
x-=o'?t
in tbe list'
i'z
b)
")
!
rr\
(r
the variable
J,i
iE
of the for}o,iDg ProgEaD
*3 l{bar is rhe outputs
e
'
int main
"'i"t O
'i"-
'
f
i,u;
*'1.''',
roat
..^u^,o^nint:
e
4
-7. oJ/e.o
i
i'
-
'.--.---->
'i za's
ti.
t
o
?-*n.@
t+f"irt:, :1t',;;ill:d:ii":4:::::::,,, 5a,zt*zi .,
d,r
ccuu )-ii- / - #-i"=;..1:.i\tlllTll)1.i,"*,,,,,
i
Z"i-ai;_.r"x41163t>{2)
x=a+b++/"t1lil:lii.."...iai'?y'o
;
(2) <<x<<end't'
cout<<s etprecis ion
y = x-3 /2+3.5;
--
.out<<Yr.
(@
D7.,
?19."'
,tlh
'2;?.*'
<i'dst'"""i>
---- #$"lode
--
--lusing
r--\
std.nam esPace;
'2,/.,,
.-"/ur)lld mai"Ot
{
iDtEEEt count=0;
,to, l'
DOUBLE sum=0
/-..---/
6,9"r"JF'-9'
c-in<<num;
sum
:
= 1+2+3+4+5;
go-unt =sum+num;
rcturn
)
!l;
Ci'^2> ^u'n '
0f Jorilan
UniversitY
KASIT
S:ilH'::"'#'#ill#ff1
Seet No.
nams o"-','oi..Fst.No,
3frd--ent
obo#98
'Lecturer:
Scction:
rffi P#*:il;?iii];:,tmlFr"r.f,li:lir#";ffi;f"n'ri;it5p"'*'n-
Etffi**,i'****t
int
funcAtrPha
(f]
'
E_ " ?:T"l,l""t[:tfi!',ilY'*.,
.
v. inL y) i
i
:':i".'."ruS;l*Siil'J"fl'.1?. :]::-:":^1I1.....r" castcint>tx + o.s),
-=
f
-i-
';: $'a = 4;
i.
t
and
then arrer rnE
>8""'-"' -
l?'::t*;'"'I'",*.,0_"'I
b. x=x.:\.:?t.Y2x-
o. -Tl,-.-putnur ii-tqi c++
20;
I ium
num = zu,
i;inum <=
r'-\. I
t?
b - 3''
code
10)
o)
'' iftt tll"i.i."^".
(nun. >=
lj:*=1f"H.#
+.
'\
LY'""
i
is
7..-0.
n'{
,,..*'
i
.j ,'l"'.-1."'
:
-:1'
rt
.\rr !
--,. 110";
betueen ^o and
e.i:""-'..,;.'"an'
!
1o';'
-T
\.'1i""rion".'
fi:nction is called'
different values
'----- each tim. the
!o
to use urrrvr-!'
programmer
>grammer
thc
-'rn, -e',Jl;-allow
'r 12. Paraficters
,-"it;^f-L:[- 4-u
Y;),i',1)",,3";;;:,1:llilf;"i"f!\'*' u*'
ncxt ti tlrc qucsion nuuber
the.statenten!
"ontpteres
or
an",eeis
qucstio't' Place your ansver in lhe sPact
'he
!
r
!.:
'l;
il;i
:J
-t
C, 13.
Whst is tlle value
of counter
o'ecutes?
after the following statcmcnts
3rr
couDter = 0i
(cou4t'er <= 50)
rhile
+ 3i
counte! = cqunter
.
:.
|:
rS
t9.
b. 50
IcI 51
-rt-
,i
1l
None of thesc
-g_. 14. r.,._Xl.",,i.n:Hf,nr"f"rd.,iilil:;?jitre*.andthcinPutis:
{ ? Lz e
-1
cin>>sutli
cin>>nurni
;;;ij-= i' j
I
r,
<=
3'
j++)
sr,- = t{i tZ --t1 *1+
cin>>numi
-l
Suln=SUm+num;
lout<< sun<<endt ;
@ 24'
b. 25
c. 41
o. 4z
Q-. 15.
5 3 4 -6 I
tbe following
What is the valuc printeil by
int j,
ini sur = 0;j int num;
j++)
{
i"rti = 1; <= s,
cin>>num;
o] continuei
['i;;;'
SuPPoseinPutis:
sum = sulrl + nuni'
'1.
..
3*'.
=
code?
q
=t j-t=
-_ tz.
.
I
Z
3
i-u
j- E
-- 20
couE<<sum<<endI;
@zo
b.
c.
d.
C#
14
12
Nonc oftbese
C* -code?
is the outPut of the follow'lDg
J. 16.
'-' What
false;
found
=
lool
7;
i;; | =
dol
cout<<x<<" ";
if (x <= 2) found E truet
er;e x = x - 5'
(x > O ee lfound);'
!,,hile
)
rtrl
X=?
x =2
€
.l
cout<<end1i
a.7
b.2't
c.72
@ None ofthese
i
:
'.1
:i::i.
:t.
rii.
!:!.i
.
'
r-i
$
ofthc expression 25 Th"
J
2l:
--'14
r
--.v"ol'o
3'
+1
is:
il
@25
d. 22.
v'
"'
Suppose
that alPha isa double
valiabl?' What is thc
frr":':g..Eii!,!6--*>
oi r
@ alPna = zt'"
b. alPha = zr't
c. alPha = 22'0
d' None of tlrese
b.
23.
*tt * tj::" *tbe
following statcmcnt
zt' 'ilr'
'',,
.
.'""
,r^,rrr't
p twor bool ;our;
:
3ii:il'"r,i:l;ffi,rnl,"#,i.1",i"Lenaarevarid?
ti il
iilil
i
2'3 + 3') = Lwe'
fl"t = t2 <=' 31
'
;:;ry ii) is varid valid
tlil.are
6 iir""a'
rii'r encl (lar) are valid
'
-9:.
f,
c
'
. o
b. 1
^
;- ii;'';a (iii,
24. JupP,ose
dr_ ,.i
"'
are varid
thai\x,'i "?
l"l="ili"'E'
expression atwavs
$/'hich of the iollowing
i,.==ot
iilii-'=9r
Yll;ii
llXi6i
d. (x>0) EE(x==0)
:"-
.'
:
fragment ifthe
what is thc output ofthc following-code
Ii[';;--int
tt"''j-" t *'
l
inPut veluc
is
4?
alPha = 1o;
cLD>>num; '.
switch (nun)
t
1.". :: arPha++; breaki t
case 4:
g, alpha = alPha + 3;
".r.
:::: ;, ,i'"r,. = alpha + 4, bEeaki
aiptra = alPha + st
;;;ri;'
l'
cout<<alPha<<endl;
a.
13
b.
I{
c,
15
@
17
a"
-r
?'
f'\' \(/o
bt
,l
,:-r
i!
ii
ri
'tr
"'
Problem
lo.
i;
j,"Jlj:I H*."*Tff [
fi:::'"t#:,]!::'i:rH:]T'dfils:fr3itH'J:':"]H'
synd-e;ff;: iay attention tiend of lines' ;-
program must be comptete ano
-
b.t<<'x "
C-*-t<<
)
,, /aA
.-o""_/ V
i:.
+.
*
perfornr the following
Q2) ltrrite an ellicient C++ Program to
ii iiiiJJiJGruslu.lelt)-e.s-'
-
Iind the hig[q5t grade fi)r each student (either first
or second) tlen find the average ofthe selected
hiqhest crades.
- From iire setecld highest grade for each student,
find how matry 8ot betlfEn I EQ to 9i].
Vol) mctin L
f
Ntnb@'n'n=#\
r,"l-
Fl""l F ,
Sec
.coLa
, 1o lral = d t averase
r.l"t
| {< " .'n
Ci1" --,) II i
tt/" of- s l-
)e.ntr s"'J!
t
:
ts+
[,," ( '"[l't ; \ <=N ' i )
l- {.d -€rnler }ho g ro.b ol \te li.sl
fr.,,.,
.(.
1.tr.'7.'Y;
n ?r^Lt'/
a or[.(
l4n
e rl ra
rte
el
lha
e.k'o'-,
\ rr" 'i
5econJ exqn\y''t \
ci";)gcc i
max--Ei
i-(-re.>''n'z'()
- )<c '
\
! 1' ': '' h'' t1l. a
" ,,,
h'rx
cjrn6!.
qX
i1
zccucl I i
+ -- I ;
-ror..,l+ = V.acrx i
l'1
l',^
1!(
.f.{aot
4'l - "-.-Y\+ =\ ;1 // ?or '
n va )'
6 r.r > oo
clv: ltr€= To |qt /
:::,'i;
c
, t, I dc
\
//
,Thz
'r^a
c'4Yora:'e or luc
1,u,,bcr
ol
'
:
1<en'
..,r-'z'<' qvcroll
r\
hi3lnesl 3rd'd'
belwa'n
s lu'lc^t lh", I 5ol
(8o
- ao)\3€
t
rn<< e'
..''"n
'n
jJ
LciF,.rr.,. ( Bo -Q o)
t
I
I
// Print thc obicctr (using
pointers)
IJ
wtclas5tP.3(lc;sto'!''
,
i+
hn/*-
i"o; i=4t
u'
'
4
ijtl*'
I '
'')
lr7=--'i:r-'try...
l*-'
1 ,,J<f/,
I
t/
-1
I
Q2 n)
'^4;
"
-,/
Whrt h
\
iri
the vrtue of
Y in the follor{ing erPression:
/
to
? roor zooi ll"=
-}il'',
'"'6'-='\:
;";;tu" uto"it'uot"'tinB lr stsrcmcnts'
X= \ o.>
'4
/x)q)
numb"-' +gC",5'eg'f'
w.i. . FEli
aI n,.-'.\ctt " lo o ) )
* f,i.r-f^ f r,..mb.,',' ) =.7 "
f rout- L1 ly+awt 1< t,<lli a,L./
_h/r.Mt h.u'.= 6;
to priut the
os.
t
O.l: l
:
'--:t-.
*'
5
;r
f' :
r,r^l-i ;
x l;
te
t t:td
("d z< 'tJ
;
tbc
to ovcrload method lql to compEte
rite nrcthod (funcdon) dcfinition'
in tie sain:
il,'li'"i.rp.'t"a;dcd
ilainQ
t
*ut..rqatO>r'
cout << sqr(1o.5);
)
1..
/t ,t'lilli"^
Long
6'l,Y tL"nl
sgv tu-'^h"'U) '
!
| ,r^n'n
1
I
I a4;lr:+ alr,'/?
/.4^h
fu,tbte' S 9v [41'tble *)
7.
-n
l"y{Z;
(2.t
4
v
5o1".''^'
s--rrr*,N",n" ' [r*,b'*^
St-
Nr*fcr: o1? 14q
Scat No.
Jf
and :
Ql. Con3ider the following
'i
:"
L.'
,"
# include < iosbeam>
class5yctaE!
t int -ii
oublic:
t
.r.i'
'-i"ii"t (tnti) {i = i;}
'
j,
'
ini get_i0 {rehrrn t;;'
main$
t
using
myctass rrtins
obiects of t'vPc -"^r-'c
5
cobjects'
//-Declare
b3 ilta"' lL4tt
iE7
'
rrrrl scfting
rrmJs'
values
fron
l
to 5
'to
/'\
(9
..1.,..r,,r1- lr.{
|
+ ;r LtJ,-t5t1 I, Y5"' " -' "
i' !.
-,/
+j' r lc, s'.(J. ) ur.'
.
c\rr:
1Gl.
wu1ll"
1
above'
// Print the objecr dcctat"d
i.,'
?'
r
wf t:, > i-+; |++)
j
(c.l
chE(
<<
.
Ct*st
[-l
I
.9,r
ic))
of srrays)'
ro use PoiutcBlPttcsd
// Modify thc codes above
*'::;';n|1;!i1,,
t.J t<
Ia6
d) @-
?lt1)
r zL ?-> "ttJ:r
r
{
\
a
un'v
.!LJ,.l|ls..Jt
Cr.+
Ql)
i 90 I I
02 &!l
':l
Find the outPut
rii
ti
A) #includeciostream.h> z
int main ( )
{
for(int n= 6; n>=l; n-)
-{-if(n%2:0)
--
'
'':"ouaai
+fo.r:m <<
o
o
g
endl; 4"--
\r -elseif(n-4)
i - - I cout <<." break " << endl;
<---:
)
:,
l!
int num = 3;
y Y
L,I n
7'
.*i
-,:.
8;
else
cout<< numi+ << endl; )
'r"i-'
return O:
. -,
/
( '
\
'...'YI \
'..
,,.,1-
7-7
,1- B) /linclude<ioslreaJn h>
7' intrnain() '*''Pa'li,
..,ff
{-int x:2; int Y=3; int z--4:
')"{t.6'--. -- z=x++: y-11-; 1=z++; ,
'to;r?z'Z< endl << y'<< enril << x << eirdl;
,f '
-.--)..srvitch1z+y+x;
)i
,.,L
)ti- \- -'
tase 7 : cout << "seven' <:-.qry!i
{
I
.t
2
32
5
1..
I
.1
tl
rri
c€
_.
--
'
t
I t
n)
>. .."
'.l.e'
e1*
I
.
: cout << "eightl<< endl"'
:,.
case 9 : cout (< "nins" <<
i<
<<'ten"
endl;
IO'
cout
case
case
endli
l
return 0i
)
'-;C)
#in clu
.-.j' : ini
main ( )
d
E<iostream h>
I
I
:r
\ {' irlt d=lo: int k=l: int al; 'rn!
a'
int al=3600; int a2=700; int a3=80; int a4--l\
v=
al+tZ+a3+24;
)vhile (k <= 4
)
di
)
= 't.-'
a=
a
.i
j)
,rf
l!
1
5
a),1
-'1
'a
'i
)
o
''.: |
:
..
I
I
't'.1
- '..t?
- 51"t't
rr
'.?a!l
i,
2'
?
\
h
,
:;.,
i= ':
_t'.2
_.,)
c,>, lt;
!
425
'lo13
'I
j l.
I d;
cout << aa << eDdll
r'J--L'
r- I^'I
.,r llji).,a
feturn u;
' "--i,
':.
F7+I
1
t, '{i= aX
.,c''
!,- .t
3?.9.
t2
:.,,
--ioo
-
B, -\'.
riq
i
^"7
ooo
-to O
' 8..,oi5.-
tE:.
'
lo
-'7.-iof ; te_i
-/ \o
|z-t*
6s;
'otq= to>
ls
t1
- o,'
Er=?
il
oncs:
if siatcmcnts into switch
followiug
thc
ConYert
S5.
I
'i'Sli'rl*?n#h.:rii
etse
{... }
eiff
&zJ"
'ot'rL
o
> l2tte
uz'lz
Y,tf = +\
ttuct i,n ( )
(olo R (ancliLlb h '',
.r'n )) /a>''clilr'.7!^ "
;;t t.i'
,/ re 'r
cl
'i*
1t
\ t**
Rccl
.,'
'
r'o n
t
)
-/
': :.
: '. r""
-'\
:
J
bre"t'( i
tu/w 'llll'd 'r
,
:
hrt.r'[r
0,,u
:.
bre^rt-;
&4*rf
1
.
-.--
,/
t
'3
?
L'r'r-
Second E:iam
)J
ffi;
t{r '
'.i"i""t
-t
1al.
sor'
oon:57fr
a
program ihat ;eads
""t"
;
a screen'
,,r .
: n"lrrr
'
ac+, rr l)
('--v,"le-
(,(* ..= .)
.,;-\
\7
.to''e. . f;\e (','..^*\"-<' J*\-)
c\oS<- . t- i \<.('r,rq-6'1'
CqILY <1rl,\.r\.
,'
rie-Lr-,r.tin rJ r'
2a -.
I
f^-,
\Z?-
file of real numbe'i $er'.Fffithe
*:,
?il-'(.1 ...a::* --**,:')
--L " )
-ix-i.-e,,n'.\,2,^-'-2.
r'-
No:
' -"'t;
t
wnte a piogram Lrral ressd :-.liii*r"n
muitiple
-a:ee:'::"
-- -5 otherwise
"t" of
nrints the name & the grades lI all or urtrrl-ar
5"'
of
lll grades a'" *ultiple
ffiq,in-*;-"j*ot
4=
i^
JuJ.e zrosL**"^.\r)
;
',ai
ai '--i^i;LI
rl-l-i..3 r., -:
\o1 vr,J, z )
k\r' <
.o r! y5 " 9t,)".t )l' ,...*'" "^"[
<in<-< rt <(* 1< '7 z<2,
5y''r'i'"i
)'
>
r+az8 Li"^'-'t 4* z r' 5cl 5 =
'4,, ".-ri =' AD A " 'J<'"u &Z 7'-"J6 = o )
c)
, P- ( x :,$
C-D
\u-q rJ r\eq ,,
vtf <<
.:\se
-oul
{t Ll(i'l
<<.
"N"+ "'[l
"<<r, <<?<4-u <<:Z
.1i
x u.,.^l!ig
.*-
O"
1
.t...
I
tt -L 5";
{,
{'
I
I
I
II
ti
I
I
I
I
t
of creriit hours' collage
a C++ Progia$ ihat reade '&re number.
'S' : college
: medicine coi''age'
f
F-' : ensineerinc collage"M'
-oi
'arla
rD rot everv srudeDt (the input is
fot tttait hours)' thenEnds & prints the
terminated by reading
'"'=o
ihe student asumr::ng- that one credit
amount that should t" p'ia
rc'ittaiJine coilese' i5 foq engiaeering' l0 for
cl3.
- \lrite
:;;.#"; ;:;: "''iu"et
iy
.
i 'iollage
1.o.,
;;;;;t0
and i5 for II collage'
science
of
i
funcilon to cElculate
- i : Hint : You have to use a 'Yaluq -$eturning
I'iirr*.rr,thatshr;iri'lbeiaid'
' *inJ*J" {-'oslrcuo.''.7 .
6
$
a
Ei-.'-.qdilV*rvs ;
E'l'r n"*!""
co,,{- r-< '.'Ple.^"
.e c({.1.f 'h6!({i aaJ qs\'^t€
.:"\ >> cr,..J.'L\ 6u(s D <cJ <- ,
aq-Jc)
I
c-^i,:- ! ' :.<.g.-1-<<"Co\\'{\-- 'l-
Iul_+gfL
J,rbk
'
:
s-*I<<''z
<.1
,'
*-Z!-
l.
I
-, t)( <a!\
T!* (oa-< '' *#
i-t.*\^l-. 1.e*J1t*'t'1
;
,-uuV zz! Suh.. .-* t'<-- s^,-'
1<!rlf 91
r-
";
.
,'
.,",",^\..
,--nror'r;o'a
: " Fr6 .'L
'
C.
'i',,:=;'r 2
, O')d.
I
Lq.'-;"i'i
S,&at is the output of the folloiving program'?
#include <ios'ueasr>
usiog nar.nesPace std;
int x:
;6iIi"i.ici
1 ii,t&, int) ;
void minnie ( int , int& ) ;
. ilint main ( )
't
-i
':'.i'
.
intfi$t;
irrt
=5;
second
x:6;
'mickeY (first , seccnd ) ;
eoui<<{irst
' <<second
<4
minnie (firsi , second ) ;
couK<first <4 " <<seco.rd
'
retur:r
0;
)
void mickeY ( int&
i:l'
ini fus! ;
firs'r = b
)to
-='r+1\.t
= first + 41 ...
b
, ht&
v : lsecond
X = U *v;
)
l-
i
-.--T
to''
IQ'
-u-LP
t-l
tt
r0
i
rl
rl
T 11,,,
li
'1.
-
.
r
int b);
+ i2;
void minnie ( int u
{
int second ;
secoad =
.
^,
g
cl--
fo
C,
v)
;
<4 '<<x<<endi;
<4
' <<x<<endl;
i--6e)
..\
.i.qr[iirfir.<ryq,u+
"m##
-
.-^--.-r,.nrneraturcsf(
ry,ffi
r
ffiF"lffiil#;:
m=*o
l*rrra*iJ,
o' *o'
one'dimedBhnar a,'d)'
in
ExantPle:
the
Etrt$trct*s' k4'!vorils' ' "etc'
sffer fitiing the Edsse'l
ffi
rd:Ts:ftrl:*:t!*)i,,
---ii)rd', A
inac*o"treet -'^r' :+"an*r{l\
.#l*ffi},*ffi
-4={4
I
..1r+I
*iM#lr,,rr"*EDt'k'
, j,r(ant..t-Vzz-- zb i .kit
ci4
))
i i{I},gt4ltdlr{ff
ilfl ; '.
Lr-,''llfil;Tl4
.
\
"u**,1'* $4. 4 ]-'::
:'":#$g|ffiif,ti,--].
f
.,,n1...
#,H-SHtrtffiY#(*z
f,r(nf
i-*a; i>= I i
' a.--,.f-<<A
til:':
(-
?
6il-uc:',
o
: couas€
'M' : medicine
Iil"r-:i *'gjil."ri"g
"o["ei, ni..r"1
of sciences , 'I' : collage
.e.1-e..v*9agJ*""H;';:
nnds & prins the
rn'+
!i
ry141*
' ;;;;,h"i*. lii*l:ii*'Im1',f,m#m:
;t:
*-'s"iiii"1ffii, *"*,?'#;rri
bour costs 20 J'D's
;;u"g" of science and 15 for rT collage'
to"#f vio"' i"t"'ioe-t:f:99"*E-g!sl9t"--
Hint : you r,"r"
the amount that should be
paidl----
.
*a.haf<,. slrectn,->
.'.'i'-':)
urtne:-go'q
;',,
_.d/prll--S;s
t{ietrprr
1!f I
'iir-'ii])'))
\14! ,t
ti , c'lctv'cc/aJ€')t'
q"" 1,^'
inl- n-,". )^/ t\
,i- j"L
tVirr;pi,l,l |.i"LJk;
'
u['1(,'
i Sciencs,f; fi:r\ ri
c'.tttt.ttk1 ,'u-,
l.i.t!ey l-!1.:
6,
t'
{;rrfr;i_ l''.*,*
?,,;,rk.,..i,
,'.*r-['.111
tt,.,artn
"1n5 |i^,r-/rnf
4:ieh-t'
,:i t,,i/',
."
l' 4 :
t";,1,
F(croJL€
\,
,l-:lrl"nl
't."J")
;
rrc.'-ri:'.t'un"ld;'"')'.,n[d
tt) a
1"'
c'^r4
e
J
1'''..zr'':'-t'
i:""1'"i'i: ':t' '^j''i
'
tl
Q2.
What is tlre output of the following program ?
#include <iostream>
using namesPace std;
int x;
void mickeY ( int& , int ) ;
' void minnie ( int, int& ) ;
*#,.*ffiH#
int main ( )
t
It
iJ
int first
int s:cond
!".
'c.!"1.?14,
5;
-j'r..3 x = 6;
mickeY (first , second ) ;
cout<<first <4' " (<second
minnie (first , second ) ;
o
cout<<first <4 <<second
rehrm 0;'
=,{sfl
JJf,
''"f,tl!-'
:
)
void mickeY ( int&
',ti j .'. .
a,
int
€
'<<x<<endl;
(4
'<<x<<endl'
b);
{ htfust; ..-,,
fnst = 6
a:2* b:
'.t
"*:ilffi##
i-12;
b= fust + 4;
i
'lEi.
int u , int&
'1i-:"-"'-i . *o ':
void minnie (
t
.
int second;
,. second =
x;
v) ;
r- - !ro
it.-\
l.v
I
ii:*""idi',d + +:
*: s *v!
I
I
I
I
: {gl
-t
"f*Hf;d##i
'I'rF'F
4
.
I
e+*
Exam, May 10,
L63o-3
@F*:*r"t'
L
The odtpqt of
-t
$q Cr+
code (Assumc'ill variables 4ro properly declaroC)
n = 1i
(l
Point)
*rtr*
;il:"'"'"'", r#-f$iF
,7r",,0
1
2. The output oflhe Cf+ codo (Assume all variables are propgdy dcclareql.)
cout<<'StI i
for (coun; = 5; coun! <= 3,; corint-- )
cout<<'ol
.couE<<'pt i
.
Output
is
(l Point)
:
3. What is fhe output ofthe following C++ code? (Assume all variqlles are propelly deglarqp.)
int
foo O i
A
.!- -
+b
(l
Pcint)
(l
Point)
'
coul<<foo
( ) <<end],
voj d main I
ccut<<foo O <<errdl, cout((foo 0 <<endl;
inE foo'( ) {
,
.rtBri
*.!,rc;f
)
&ffil#.,ix'*r*" P"i
i:.lii
i:lt,=,i,,'
turn xi
..
)
-j.elirP
r.e.
;Hlrrrorr.r
Wliit is.tic output ofrhe followinfl C'l+
code? (Assunre all variqbles arc propcrly declarcd-)
ii.
co'rnt t 1; '
nun = 25i
lrhile (count < 25)
a1 (
Output is
,25ala,J
'..
lrum
= nuni.:
/,/
1;
count++;
l
cout<<couDt<<" "<<num<<endI,
for instructoB
use onlv
$t,$J' llbJlilF'
2id.L1
'iruirU*'t+rt
r++t
Qr.
mrrsolJ
Writc
a
function prototype thst
d
t
kcs no pala$.elets.?
Q2
(l
Point)
Q]
Q4
call for thc filnolion giveir ih a. (l Point)
Q5
J
(l ioinr)
l.
Q6
Q7
olal
C". Ere-\
-"
tlz-
L7,
r
r"rtt< a s.'J|cl^ '1o frf^f ts tn it. 6o -"'t
t.^.< oC (L4. ",eetss r tt ..ritt' pria* 6 r".* A (.>
.r:i6};'
LG?rese,4 sdr , e*A 1 reg res o-:t frr,
411e1f
.
-'l
''
1,-
t i+' r.,-r )
statemenl in linc 3 lo
rI- For thc code given betoY{, write a
q
ro"al identifier num' (2 Points)
Pdr *rc E6bal identificr nqm'
4nothcr stalcmqrt at
int ;ptiorthi
t
2
I
4
.)
<< ii4um
Co'tl<
rwrn
<'"41
i
I
)//end ofrnain
ofthe
6. Use enumeratioo to rePresent days
Ye4L:*^:ri\e
it
a
furction
will receive one day
at
oft
week as
r*i{cL
-...,alo/..le
alg (lc
,16+l)
sr")' (t,J *'in1v)i !
I
?1t. >oaP(iat x, in1'9 t
\iii
---,rt r Ki
Y
i"t
r€+ k
=',
f.,..ti*
tL.
*t*n *;
re-t,rr
^
'l
€e
v
slatic
i
t"qloci
't{q
tr..
,""t1' 1' dooble I t
Y)
lu,'r" s-*f (d"Lle r ' &uLle
.J*I,t"
s,,*P (
tc --
xi
'rJ feturn /',
.etucn
l(F
Y--
=
^.
)j ll
Ptot'1rl<
,r) i r*3 int lc--o.i
y 3 F-; r.f-.^
[(
f"*f''*^
{j
,*"
oF
d et€
(\
utilH.,flHs"
,.
,
:
+r.a
(,^.4:i
-t.'
,,
srGr cr-e{*1
a
Jorda-rr
Skills-2
No; f5'
May I0' 2003,
F.iA;',
1.
declared'X! Poim}'
Thc orbut of the Cr+ code (Assume aII vuiables gpp.roPerly
t'.:"::.:"::.,',*Si#SI
'
Wi;-
2'TheoutPutoftheC.l-+code(Assumeatlvariaclesarepropertydectared.)(1Pgint)
cout<<"St" i
ior (qount = 5i coiJrlt <= 3; couat--)
cout<<
'o'
;
cout<<rPri
Output is
d'r--,
vv/
-\t, .)
,,r'
For instructors
use
ry$itr4J$l,li$r
ol
Lr;nr*r.t'rflnld+l
all$Ii*r
.. !-: ;
'1"
l,
,i,. \ z
':'5'6-
nd trles no Parameters?
"
giveu
Write a firaction heading (firneljdn dcllamtion) for the same fiurcdon
\,
i!
a-
(1
Poilt) Q6
Q7
L
zoa
Q3.
Qs
m;n
,7b!;
V.; / 1l})_-4-I V";/
ti '- '----
,ol( '.
Point)
!oint)
'.i\,illM
,', i ".'.
(l
Q4'
gi{cn in aa- {I I
tunctioyi{en
thc lunction
firncdon
firnction call for the
Yasl n;n
'
Q2
voil m;"
Writ .
W.it
odv
Trtal
t,,r"a l_i
I
lllt
St Name
[.egtur6:
SeatNo.:
>
blanla:
,/
pass the
stateneat iD a called fimotion is used to
'tfue ,,.7,,,4.a
l,-';"h;;ia-r;*ri*5;ftotbecallingfirnctioa'
I I.
Q1) Fill in
, ry-r'@*.of
i: ffi ;##;;d r;i!G
an ideoriEet is lhe nortiotr of
txe-pJor:?l
IfJ5ffi*"*"6qffif
Q2)
Wlat
does the fpliowing
int xGnt
a,intb) '
/n/'u
"#*ffiils#
rctur!4
x(a,b-l)l
Fill even positioned array locations rruith odd numbers '3'5'7" "
suchthat A[0] = 13t'z1= 3'{il-*il&enurmbers
2,4,6,8,"'
And odd Positioned arraY loca
Such that A[1] = 2, A[3] = 4=..
b,
fis
=@
3u.
.i.
else
ir
elffit or*''"1 :
fii::ctior' do?
{ if (F =a)
rcturD a +
partiorlar
1
itT,';i*-jl.'" .-t*o t= t'+t:PwA,:
:ipff'
c,
Complete the following firactiou that
aumbers bY 2.
33
AE
will
add to odd nuobers
^I(*
ti
, tu*)
/L7(
f"..='/ o) G<4L1
n'7:";=
t'd-t
f,)
o1
cqt<<rl: n- +'t-<<*Al;
i-
9{/*
I
1
n-2Yt>
'
dividi even
'''
O+l
it/o )<
wt.ii,
O. oirtboi ciitie following
program?
#inctude {oshLarh.b>
#iaclude< iomzriri!.h>
ilrtY=5t
..+oid:{)'..'.
'.\{
...t'.1-:i'- r..
'
tutx=20;
x=x+y;
cout<<sets(4F<.<<Y;
*.1
,4###f
,,,+i
L-p
33
o-L
.I'!-:J
/':
;7 \.*-) |
a?'
.?
,:\l
..
=il
!.i *
.;'laL
.r-
f
f,F
. -- . --]+'sEEl
r- -. (,TJ,A
,
t..
:
q{ls'*{t+,$'s'h
conputcrs.lrE-28i';€iE#ij#; p]"1esi;r*i-.+:
'?
,..i*.'l'ti: -3rPeelretg '
!i' atl useil identiEeE !r'
i#ff[:el:
as$ime
a abgfe C++ stctencDt io alo &e fotroslng,
dedared. (5 Potrc)
odulus 5'4'
i'raizD it to the sxpr€ssion
iJeoiz
Odstionll Write
ircailv
-'1i
;;i;;;
.--\I ez..-i,nvz =57
5
-a
5l1
i
o(pl'essioa{I3+c) to the idgEtifiEr 'AA oompoutrrt asslgDmcnt slaEment that adds thE
b)
(ts+c),
,--".---
.A+--
c)
to&e consolc
OutPuts
a
j
,
:
s aecimal points'
floaiing poinl i{entifiii.r R itr 6xEd iilrf,st "iith
i!-'^Q 1-l tr'
6c console?
i,
s--.---'ae-*,\i.ir e- (ci',.: t-T R)
p-<r ei
a...-. r- r <-V
sI$ &om
ia*tino
idJng
on.*.. p; *
--io ni; i,ti-rluio: il; tii
"-
el
--l loYE
Ensurcs tbE sAfrg
u----6*\
E#"-"o-n
J,*\.^
G,.
L--
j
<<."\V,1\ ov e C+ +
'
pro','E ,"trch'."a"
ilffi;;i:,fil;'";;ii'tc
i
n
\-
X
.,rf ^,i
r-- oi -p!:ffiffi.1fl8tr1#;
nx
the Enrlrtst ona You inust usc
(< P\r*-\ '('-<
l. c'-.r!
a\orr\a\c
;
-
a'[ r'.l5 )'
.
i
I
.r.*\,r.d' bS
cou.h (<- \'.r.\c"r
C\ vr )) :L :.> 1>>
n = $ i .,,
i$ ("..i- 7 7)
,..^'r
: ?
a"$ tel
lt
A;
l.
wl\ .a
Pii("t'"tetr CA) i
Eetr
"#.ffiIilf
'-l+-._
'
{"
QiiestioE3: What
I
is
a'-;
. ---.Zt?
oittu fofio#-g p-gl-u-'
ihc output
v)76-i'.
-
(5
' Z't"
Folab)
lfincludc <ioslrcam>
using aamesPa@ s14
irrt
{
,\/
rraiDo
intx;
i
couF<itatic-castf<doubl>(26,/1)t4<<cndl;
v:34/4+
6
-lr
+(10(>9ox
.5?
'-1i1 .. ii--.*,r.sr.Laf
r
,'qts
.r
caie
1
tout<<'tlcllo
.i
ii 1nr'
''t
>
,.I
%ffir#
I0',(,
casc o:
f
[...\r..;,
Fri,icill'"
switch(
.l
t/
douHcy;
t: coul<<C#"i brcalq
couF<' WelcDrn' !o C++"; kEalq
defauit : couK<No malrh";
casc 2:
l
rehrD 0;
cc",tr(< 3
QrcstiDn
-r,-r- crr+
3.
or strteDeEt it trle-or frlsr- (5 PolaE)
4:Trn..lTatsr .pdicaQ whctber th' $qElenc"
is a iow la,el lai
*"-F
'
/
-.-
oPer'lor wsks
be decimel aubets' h0rthe tlojutrls
Ttc opcrards of rllc modllus oPcialo! car
*
9'#-/
it "\ail?rbltsi Thc sEtc'ssi' alPha = beta++' is cqui]BlEolto
allj,ha - ++beEer. F /a
"t"l*--t
oiit* or' b 6"li'r':"' " ''
6. supposi a - s- !id& 6o orecutif"* ti"-*11-,*-" '
5,-
I
7.
SDp,pose
Tbc
thsl a1Pha
resulr
i.D
The rcsdt of a l:eic€r
9.
Thc oulPut oflhc C++
.
.
-"*
T
*"tTl.l -
codc
10)
,'-:-,
";
are You?"j
is: There. tlou 'are
'
if lscore =
iD t$E
'
&!d:q b 8boor rimb],L,>
,..
/
tf
V
SLdcEcrn Er,EtuatEslo
lucof scbr6'rs5o. tr -.''
true (r )l iftbEva
^ -/'
.
t2
"
-" -'- i's'
t
. -:_1:.-
i' on rt
=t
Yoozf /
foltowing
50'),:
u*i'uf,*
2Jrrlfl Ak$Jr,ritrrlilrJ
lffia5r"a-z5l:rdt
* --"it iUfu
.
cout<<"rher6' 'j-.
10, Thr qxPrcssiou
/
d vatuer arc Dot r,E . sc Warf-- F ,aa
LrP
,/
ceftstion
)t = 5t
ir (,. >
--'.oorlciselr"
cout<<t'Hor{
ttro
*nllr&jll'
inF't faillm ifthc
- t.
Bre
i;j;1*ijflrr,g:jr.
'i.1;1fa5;.a-fgrtZ.r.p
5latcmc',ts
cir>>xi
cin>>vt
will
s'd beLa
.i . t -'
-....-..,
..
.
"eq'
-! I
oS.*+
j
"3
while
"fissf,#{
[nua.t'=
49
E.rotar
for.
e're,rr.r11\t:s
...q"r
,Self|6.ntta
,yrde.!e"a
r+-
3-
t -!E-.Lrr -F
. .. . tr--tl.'dl
Tr,PrJg'.ltT'-r"
.
.!dlrErJ!-
.
- .4aL
W-4D
liun":_\_:/
t(Asrr-
Co pqter
?i
;ilJil'ilfr
tuuctioa@sli-':11pte5'
it$.:.j.:111ryF:$""93$ft|
@parara.ee4crf
'4
.,fl' incl")e 1ir:sWeonT
tc;n3 E. nan€sPece. slU;
.'-..'rtl --:an"tlor-'o /.J ( r,iT. LJ':
11
j',
)'
c
Co*tl CCsk,.Upt"
it's
'-
o\|l z(,ir.'r. hp(-o! ( +!( e"at;
t: ((S) (<.e,,a\i
1^g+,,rn;
Iv.nr
t+.,
:l
+,+
E{
{s,.,.,"4
Conk.r-4
b"erl
t
.\
- t'!.Lti
ii
f\
ili"-riffi
;ff.:;ffi;,Jf
--FUN_A
'g,'Id*"T."**'Tf 1**"TP
j
;y€il;t
(x,Y)
&
|,vlnqe
t*^i"*gtr par-alrxsllo'F
-'-'i-*-r;;*'"*?-:TDm
'9
fidqi Pt'-cgxarned x Y' -ii
hv$,{**xatrdY,
fioioo ,-ul"rffxlEtil G
a3-tgg't"1Yol1-9g:":-r.i..oeqedrnr,aluc?-. . .., -/
";f
|
"#:Af ' fBrJYfitu'"iE-fT#EH?
q{:59ks,tgi,h#^{5""i?,--","r-q-tr
odi#I" Y\{,-,
--,'.-ddt
'Ji;^r,
:il-eF^ I evJ , r.t.-::::!.
iiii-l:srn::,fpe
fi'ffi
b)
A calt to a void fulction
@o
namcd FUN-B
aad
,"ia
po""a ;Y t.ef€gcer:rd Y
l'
-,, ..ll
is
P8s
Defiaes an ctrr.Ineraio s@Ed USER-T
EIarcsUsB.oftYP'USER-fYPE?.'
'
, ct lvrtt
*L{sER oct-soirrt!
rJu{.-t \ -
d=vsYp-rwtcad of the f
Lo,*hco the
" 6,6 #,m*'"=Tdiffi-r,Ei,?r1,f
felwn
t,
z
r, . Jj
(xzYD
ffif;*#
.i
llwLs1ll!IhG..EIEE
{
X = 100;
aout<4'X =* << X<414";
x3E
='
Cout<<" X
X-;
l
<< X << "
b'';
b++;
..
a-- lo
'ry'- \tF
*" Zo
o\ -- lq
void mein( )
{
iut a= 10
; htb = 20:
. mur<C'a="<<a<4'
bJ'<<t<<1e";
j:
Foda,b);
oout<4'
t
l2'-zo
\
}):zd
sJ'<ia<4'
1
i
e{x
I
qCrJ
;o
1.1G
afel>o
*1i
I
I
i
I
."=t"
=
"t1:T:t
j,
,rcs>.
arrsy b
?.o,++i
,-t
?2
\
-t
a}
€
b(6'J
^*j1
-\
"dt*-'6o't''*)
'^l'"
-- o
lrtat.
i: .: {.1- ar
r'l -- .--1;
'o - 1
z
t<^'""^ a=
t if ( a[S] :-{ ), rcturD s;
,,.o;1 .r , -- . c
\
elscif(S-0) rEhra-t; '-;"
=ti)
5-r
4c
- - - t1*tn
;-t:')
rcnrm firod,, s-r, x );
.a'
- -.. Ln atrr*lt
A Asrumarray a [5]; ( 5,7,1,.10,4] !!{ rou mlt the firirCirn rvith
T*'.11.,i.
i:}'
R+fi,,s{sl,ro)r
16
.
t r*,,
r'.'
Iat tor4iItall'.hts'intx;""tord ilt at l, .htS, int X) " t- s.'
E*-: '
j;Til
-
<'
+tl
Wbat \EiI be tle rala ia f,, 1 ;-l++-:-
I
i
,l
---=i
'.*i
1
--
i
I
to do the following:
Q4. Write a program
greitelloolirt ' '"
1. R6ad ah array of 10p grarles calt it
2, Wrile a function
3, Write
a
laclt le
*
.:- .ir:1.
a
to return average of the array'
above tle average.
functio[ to Print the number of studeEts
=*reon^'\)
7t"&Ag Fvq (sr-+.t,1 .'\ts')
-:
,.'-i' t t'!i] rY -t
...+-.- Y-. -r-..
L3r
- '
n t. -/(f,-
aB.
"r..i,ii,
(lo
r:
,"
-.(,
i
inr.aiu.Io1JlQ=,t"*'-t:"-:+itr-u-Elo--c=-)';
jv*- rr,'"tr^ C )
7 aon=-f i'L Vi- =-'\'co;
I
--,fdq#iYl["
r-r
--L <"<1'!=
rrew
o
L\ie=-\
!
q ...A'<, <" 1lrrl*'7+'" Qr*'bt^"
F.':-CirPL=o ii<-7T-==
i i+t
eia>> ?y-deIal;
H"f.-r: -- AvS (2grnJe ,?i'
.,S =ir"d =
<>o>
N)u
coF<< I== \1ur,rher
n&" t' "#'.j5i;,.,i,#"
-'#'T,fi;;r:.r
( ft.$- '5"*Je E1
--trr"+-L -*, ?
jF
f*v3
FI.i 'ill-:"
IT
JIJ
(='i=e ;
Fl,** frv-r-6e -=2"w /=
'.
',-...- .-!'-..
'
-k.
r.*r.rn 4[\-,'aEF-;
T
-
,,t or*.
a2)
(FI*L ryr-t.,s- "j5o ' F\o-S** '' ,'
'
1) all of the following are example of integer date type except:
a. int
c.bool
b. double
d.long
e.none of the above
2) the value of expression 26-3%14+1 is
a.0
c.24
b.23
d.25
e.none of the above
3) suppose that x is in int variable .chosse the value of x after the
following statement:
x=16+static_cast<int>(12.5)/2;
a.x=20 b.x=20.25
c.x=21 d. x=22
e.none of the above
4) diven
int one;
double tow;
bool four;
which of the following assignment are valid?
(i) one =7*3%4.0
(ii) 2.3+3.5\tow
(iii) four=(2<=3)
a.(i) and (ii) are valid
b.only (iii) is valid
e.none of the above
c. (ii) and (iii) are valid
d.(i) and (iii) are valid
5) choose the value after following statement :
cin >>x >>ch >>y;
a.
b.
c.
d.
e.
x=15 ch=A y=73.2
x=15 ch=a y=73.0
x=15 ch=A y=73
this statement result in error becase there no spaces in 15 and a
none of the above
PDF created with pdfFactory trial version www.pdffactory.com
6) whate are the value after the following statement:
cin.get(ch1)
cin>>alpha
cin.get(ch2)
a. ch1=A
ch2=' '
b. ch1=A
ch2='1 '
c. ch1=A
ch2=' '
d. ch1=A
ch2=' \n'
e. none of the above
alpha=18
alpha=8
alpha=1
alpha=1
7) suppose that x=25.67 y=356.872 and z=7623.9634. whate is
the output of the follwing statement :
cout<<fixed<<showpoint
cout<<setprision(2)
cout<<x<<''<<y<<''<<z<<endl
a.25.67356.87 7623.96
c.25.67 .356.88 7623.79
e. none of the above
b.25.670.356.87 7623.97
e.25.670 356.876 7623.967
8) suppose that x is in int variable .which of the following
a.
b.
c.
d.
e.
expression always false:
(x>0>||(x<=0)
(x<0)&&(x==0)
(x>=0)&&(x<=0)
(x>=0)||(x==0)
none of the above
9) what is the output of the statement :
cout<<setfill('8')
cout <<"12345678901234567890"<<endl;
cout<<(5)<<"18"<<setw(7)<<"happy"<<setw(6)<<"sleepy"<<en
dl;
a.12345678901234567890
PDF created with pdfFactory trial version www.pdffactory.com
***18 happy sleepy
b.12345678901234567890
***18**happy**sleepy
c.12345678901234567890
***18**happysleepy
d.12345678901234567890
***18**happy sleepy**
e. none of the above
10)
suppose x and y are int variable .consder the following
statement..
if (x>3)
y=1
if (x==3)
y=1
if (x<3)
y=2
what statement is Not equal to this cpde ?
a. if (x>=3)
y=1
else
y=2
b. y=(x<3)?2:1
c. if (x>3 && x==3)
y=1
else if (x<3)
y=2
d. y=(x>=3)?1:2
e. none of the above
11)
consider the following statement
int y=(12<5 ||9 <=12&&9>x)?2:3
a. 2
b. 3
c. 7
PDF created with pdfFactory trial version www.pdffactory.com
d. 9
e. none of the above
12)
whate is the output of the following code fragment if
input 4
int num
int alpha=10
cin>>num
switch(num)
{
case 3:
alpha++
break
case 4:
case 6:
alpha=alpha+3
case 8:
alpha =alpha+4
default:
alpha=alpha+5
break
}
cout<<alpha
a. 13
b. 14
c. 17
d. 22
e. none of the above
13)
what is the output following c++ code:
num=11
while (num%)
NUM+NUMCOUT <<NUM--<<ENDL
a. 0
b. 6
c.8
d.22
PDF created with pdfFactory trial version www.pdffactory.com
14) what is the output of the following code ?
int x=0
int i
for(i=0;i<4;++1)
x++
if (x=3)
cout <<"***"
cout<<endl
a. *
b. **
c. ***
d. ther is no input
e. none of the above
15) what Is the output of the following c++ code
for(int x=2;x<10)
{
x*=2.5
cout <<x%2<<" ";
a. 001
b. 010
c. 110
d. 100
e. none of the above
16) ssuse all variable are propy declared .what is the output of
the following c++ code?
Num=100
While(num<=160)
Num=num+5
Cout<<num<<endl
a. 150
b. 155
c. 160
d. 165
e. none of the above
PDF created with pdfFactory trial version www.pdffactory.com
17)suupose sum and num are int cariable ,and the input is 18 25
60 -11 -1.what is the output of the following code ?
sum=0
cin>>num
while (num!=-1)
{
sum=sum+num
cin>>num
}
cout<<sum<<endl
a. 92
b. 109
c. 110
d. 119
e. none of the above
18)suppose that the input is 5
int sum=-2
int num
int j
for (j=1;j<=5;j++)
{
cin>>num
if (num<0)
sum-=num
else
sum+=num
}
cout<<sum<<endl;
3
a. 20
b. 22
c. 24
d. 26
e. none of the above
PDF created with pdfFactory trial version www.pdffactory.com
-6
8 whate is output
Q2)
Write the c++ programe that prompt the user to read 50 integer
then count how many number are odd even and zero?
#include <iostream>
#include <string>
using namespace std;
int main()
{
int c;
int sum;
string res;
int sum;
for(c=1;c<=50;x++)
cin>>num;
if(num%2)==0
res="even";
else if (num%2)!=0
res="odd";
else if (num==0)
res="zero";
c=c+1;
sum=sum+res;
}
PDF created with pdfFactory trial version www.pdffactory.com
Q3) write the c++ code that used to evlaute the following series?
Note :(use repeat structure in your soluation)
#include <iostream>
using namespace std;
int main()
{
int z;
int sum=0;
for(int i=1;i<=6;i++)
{
z=((i*3-1)/7+5(i-1);
sum=sum+z;
}
cout<<"the sum is"<<sum;
}
PDF created with pdfFactory trial version www.pdffactory.com
Q1:- multiple choice questions
1-The value of the expression 26-14%3+1 is:
a. 0
b.1
c.24
d.25
2- Suppose that Alpha is a double variable. what is the value of alpha after the following
statement executes :
Alpha=14.0 +static_cast<double>(15/2):
a. Alpha=21.0
b. Alpha=21.5
c. Alpha=22.0
d. None of these
3- Given: int one; double two; bool four;
Which of the following assignment statement are valid?
(i) one=7*3%4;
(ii) 2.3+3.5=tow;
(iii) four=(2<=3);
a. Only (i) is valid
valid
b.(i) and (ii) are valid
c.(ii)and(iii)are valid
d.(i)and(iii) are
4- Suppose that x is an int variable. which of the following expression always evaluates
to true ?
a. (x>0)||(x<=0)
b.(x>0)||(x==0)
c.(x>0)&&(x<=0)
d.(x>0)&&(x==0)
5- What is the output of the following code fragment if the input value is 4?
int num; int alpha=10;
cin>>num;
switch(num)
{case 3:alpha++;break;
case 4:
case 6:alpha=alpha+3;
case 8: alpha=alpha+4;break;
default: alpha=alpha+5;
}
cout<<alpha<<endl;
a. 13
b.14
c.15
d.17
6- What is the value of the counter after the following statements execute?
counter=0;
while (counter<=50)
PDF created with pdfFactory trial version www.pdffactory.com
counter=counter+3;
a. 48
b.50
c.51
d. None of these
7- Suppose sum ,num and j are int variables , and the input is 4 7 12 9 -1
What is the output of the following code?
cin>>sum;
cin>>num;
for (int j=1;j<=3;j++)
{cin>>num;
sum=sum+num; }
cout<<sum<<endl;
a.24
b.25
c.41
d.42
8- Suppose input is: 5 3 4 -6 8 what is the value printed by the following C++ code?
int sum=0;int num; int j;
for(j=1;j<=5;j++)
{cin>>num;
if(num<0) continue;
sum=sum+num;
}
cout<<sum<<endl;
a.20
b.14
c.12
d. None of these
9- What is the output of the following C++ code?
int x=7; bool found=false;
do{
cout<<x<<” “;
if(x<=2) found=true;
else x=x-5;
} while (x>0 &&!found);
cout<<x<<endl;
a.7
b. 2 7
c.7 2
d. None of these
10- All of the following are examples of integrals data types EXCEPT:
a.int
b.double
c.char
d.short
11- Suppose that x is an int variable. Choose the value of x after the following statement
execute:
PDF created with pdfFactory trial version www.pdffactory.com
x=15+static_cast<int>(10.5)/2;
a. x=20
b.x=20.5
c.x=21
d.x=22
12- Suppose that x is int variable and y is a double variable and ch is a char variable input
is
15a 73.2
Choose the values after the following statement executes?
cin>>x>>ch>>y;
a. x=15,ch=’a’ ,y=73.2
b. x=15,ch’a’,y=73.0
c. x=15,ch=’A’, y=73.0
d. This statement results an error because there is no space between 15 and a.
13- Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is
A 18
What are the values after the following statements executes ?
cin.get(ch1);
cin.get(ch2);
cin>>alpha;
a.ch1=’A’,ch2=’ ‘,alpha=18
c.ch1=’A’,ch2=’ ‘,alpha=1
b.ch1=’A’,ch2=’1 ‘,alpha=8
d.ch1=’A’,ch2=’\n ‘,alpha=1
14- Suppose that x=25.67, y=356.876, and z=7623.9674. What is the output of the
following statements?
cout<<fixed<<showpoint;
cout<<set precision(2);
cout<<x<< “ ”<<y<<” ”<<z<<endl;
a.25.67 356.87 7623.96
c.25.67 356.88 7623.97
b.25.67 356.87 7623.97
d.25.67 356.876 7623.967
15- What is the output of the following statements?
cout<<setfill(*);
cout<<”12345678901234567890”<<endl;
cout<<setw(5)<<”18”<<setw(7)<<”Happy”<<setw(8)<<”Sleepy”<<endl;
a. 12345678901234567890
***18 Happy Sleepy
b. 12345678901234567890
PDF created with pdfFactory trial version www.pdffactory.com
***18**Happy**Sleepy
c. 12345678901234567890
***18**Happy Sleepy
d. 12345678901234567890
***18**Happy Sleepy**
16- Suppose x and y are int variables. Consider the following statements:
if(x>3)
y=1;
if(x==3)
y=1;
if(x<3)
y=2;
Which statement is not equivalent to this code?
a. if(x>=3)
y=1;
else
y=2;
b. y=(x>=3)?1:2;
c. if (x>3 ||x==3)
y=1;
else if (x<3)
y=2;
d. y=(x>=3)?2:1;
17- Consider the following statement
int y=!(12<5||3<=5&&3>x)?7:9;
What is the true value of y if x=2?
a.2
b.3
c.7
d.9
18- What is the output of the following code?
int x=0;
int i;
for(i=0;i<4;++i)
x++;
if(x=3)
cout<<”*”;
cout<<endl;
a.*
b.**
c.***
d. There is no output
19- What is the output of the following c++ code?
num=10;
while(num)
PDF created with pdfFactory trial version www.pdffactory.com
num=num-2;
cout<<num--<<endl;
a.0
b.6
c.8
d.10
20- What is the output if the following C++ code?
for (int x=1;x<10; )
{
x*=2.5;
cout<<x%2<<” “;
}
cout<<endl;
a.0 0 1
b.0 1 0
c.1 1 0
d.1 0 0
21- Assume all variables are properly declared. What is the output of the following C++
code?
num=100;
while (num<=150)
num=num+5;
cout<<num<<endl;
a.150
b.155
c.160
d.165
22- Suppose sum and num are int variables , and the input is 18 25 61 6 -1 . What is the
output of the
following code?
sum=0;
cin>>num;
while(num != -1)
{
sum=sum+ num;
cin>>num;
}
cout<<sum<<endl;
a.92
b.109
c.110
d.119
23- Suppose that the input is 5 3 4 -6 8. What is the output of the following C++ code?
int sum =0;
int num;
int j;
PDF created with pdfFactory trial version www.pdffactory.com
for (j =1 ; j<=5;j++)
{
cin>> num;
if (num<0)
sum -=num;
else
sum+=num;
}
cout<<sum << endl;
a.20
b.22
24- The value of 15/2:
a.7
b.7.5
25- The value of 22%7 is:
a.3
b.1
26- The value of 17.0/4is:
a.4
b.4.25
27- The value of 5-3.0+2 is:
a.0
b.0.0
c.24
c.7 ½
c.3.142
c.4 ¼
c.4
28- The value of 15.0/3.0+2.0 is:
a.3
b.3.0
c.5
d.26
d.0.75
d.22/7
d. Undefined
d.4.0
d. None of the above
29- if (6<2*5)
cout<<”Hello”;
cout<<”There”;
Outputs the following:
a. Hello There
b. Hello
c. Hello
There
d. There
30- if (‘a’>’b’||66>static_cast<int>(‘A’))
cout<<”#*#”<<endl;
outputs the following:
PDF created with pdfFactory trial version www.pdffactory.com
a. #*#
b. #
*
#
c. *
d. None of the above
31- if (5<3)
cout<<”*”;
else
if(7==8)
cout<<”&”;
else
cout<<”$”;
outputs the following:
a.*
b.&
c.$
d. None of the above
PDF created with pdfFactory trial version www.pdffactory.com
THE ANSWER SHEET
1
d
11
a
21
b
2
a
12
a
22
c
3
d
13
a
23
d
4
a
14
c
24
a
5
d
15
b
25
b
6
a
16
d
26
b
7
a
17
d
27
d
8
a
18
a
28
d
9
c
19
a
29
a
10
b
20
b
30
a
Good luck
PDF created with pdfFactory trial version www.pdffactory.com
31
c
‫ﺑﺴﻢ اﷲ اﻟﺮﲪﻦ اﻟﺮﺣﯿﻢ‬
Q:-show the output questions
1-
2-
3-
4-
Int x,y,z;
X=20;
Y=30;
Z=40;
If(x+y+z>=10&&y<=12)
Cout<<”x”<<x<<endl;
Cout<<”x+y”<<x+y<<endl;
Else
Cout<<”z”<<z<<endl;
Cout<<x-y-z<<endl;
Int x=20;
Intw;
Int y=0;
If(x==20&&y>=-1)
W=x+y;
X=8;
Y=6;
Else
{ w=x – y;
X=2;
Y=4;
}
Cout<<”x=”<<x<<endl;
Cout<<”y=”<<y<<endl;
Cout<<”z=”<<z<<endl;
Z 40
-50
X=8
Y=6
W=20
Int w,x=2,y=0;
If(x=30)
Cout<<x;
Else
Cout<<y;
Int a,b,c;
Cin>>a>>b>>c;
Int w;
W=((a+b+c)<=12?a-b:a+b);
Cout<<w;
30
10 11 12
W=2
1
PDF created with pdfFactory trial version www.pdffactory.com
5-
Bool x;
X=(20>=10);
Cout<<x;
1
6-
Int x=10;
Int x=10;
Int x=10;
Int y=18;
Int y=18;
Int y=18;
Char c1,c2,c3;
Char c1,c2,c3;
Char c1,c2,c3;
C1=’A’;c2=’B’;c3
=’c’;
C1=’M’;c2=’B’;c
3=’c’;
C1=’A’;c2=’B’;c3
=’R’;
If(c1==’A’||c2==’Z’)
Y=x+2;
X=12;
Else
If(c3==’C’)
Y=x-2;
X=-12;
Else
{
Cout<<”Nothing”<<endl;
Cout<<”do again”<<endl;
}
Cout<<”x=”<<x<<endl;
Cout<<”y=”<<y<<endl;;
Nothing
X=12
Y=12
X=-12
Do again
Y=8
X=10
Y=18
X=1
X=2
Without any break
7- Int x;
PDF created with pdfFactory trial version www.pdffactory.com
Cin>>x;
Switch(x)
one
{
Case 1:
Cout<<”one”<<endl;
Tow
Break;
Three
Case 2:
invalid
Cout<<”tow”<<endl;
Break;
Case 3:
Cout<<”Three”<<endl;
Break;
Defult;
Cout<<”invalide”<<endl;
_______________8- Char ch1;
Int x=10,y=20,w=0;
Cin>>ch1;
Switch(ch1)
{
Case’A’:
W=x+y;
Invalide
Case ‘b’:
W=x-y;
W=20
Case ‘R’:
PDF created with pdfFactory trial version www.pdffactory.com
W=x*2;
Defult:
Cout<<”invalide”;
}
Cout<<”w=”<<w;
9- Int a=1;int b=1,b=0;
While(a+b<=10)
{
Vb=vb+2;
Vb=10
A=a=1;
B=b+1;
}
Cout<<”vb=”<<vb;
10- For(int k=10;k>=5;k--)
Cout<<k<<endl;
Cout<<”good”<<endl;
10
9
8
7
6
5
good
11- Int i=1;int sum=0;
For( ; i<=5;i++)
15
Sum=sum+I;
Cout<<sum<<endl;
12- For(int k=1;k<=5;k++);
Cout<<k;
PDF created with pdfFactory trial version www.pdffactory.com
6
13- Int i=5;
While(i++<10);
11
Cout<<I;
14- For(int i=1;i<=20;i++)
{
If(i==8)
Break;
Else
1
2
3
4
5
6
7
Cout<<i<<endl;
}
15- Int k=1;
For(k=8;k>=1;k--)
If(k%3)
{
K+=2;
Cout<<k<<” “;
}
Else
{cout<<i<<” “;
Break;
}
16- Int z=10;
For( ; ; )
{
PDF created with pdfFactory trial version www.pdffactory.com
10 9
Z++;
Cout<<z<<” “;
11 12 13 14 15
If(z==120)
Continue;
If(z>=15)
Break;
17- For(int k=1;k<=5;k++)
{
If(k==3)
{
10
10
W=w+10;
Cout<<w<<” “ <<endl;
}
If(k==4)
{
Continue;
W=w+20;
}
Cout<<w<<endl;
18- Int k=1;p=0;
For(int x=-1;x<3;x+=y)
If(k=p)
PDF created with pdfFactory trial version www.pdffactory.com
-1
3
0
Cout<<p<<” “;
Else
Cout<<k++<<” “;
Cout<<x<<” “<<k<<\n;
19-
PDF created with pdfFactory trial version www.pdffactory.com