

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Exam 2 Material Type: Exam; Class: ELEMENTS OF COMPUTER SCIENCE; Subject: Computer Science; University: Old Dominion University; Term: Unknown 2006;
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Instructions: this exam is open book and open notes. The University honor code applies. To receive credit for the exam, you must sign the honor pledge at the end of the exam.
while'' instead of a
for'' loop.for ( k=10; k<15; k++ ) { if ( k <= 12 ) cout << “twice k = “ << 2*k << endl << endl; else cout << “k = “ << k << endl; }
What is the output from this code fragment?
of an integer array “Numbers” into it, each value on a separate line. The array should contain the integers 1 through 25. Your program must contain at least 2 for loops.
if ( i == 4 ) i += 5; for( j=4; j>0; j-- ) { cout << j*i << “ “; } cout << endl; }
_ f _ a) Every valid C++ program must contain the line “void main()” _ f _ b) Every valid C++ program must contain the line “#include <iostream.h>” _ f _ c) The value of the C++ expression 5/2 is 2.5. _ t _ d) Th e value of the C++ expression pow(2,2) is 4. _ f _ e) Use of a “while” loop usually indicates that you know how many times the loop will repeat when the loop starts. _ f _ f) “=” is used in C++ to compare the values of two numbers, as in “if ( a=b )” _ t _ g) In C++, “!” is the “not” operator. _ t _ h) ^c can be used to stop an executing program. _ t _ i) If a C++ program uses the log function, it must include math.h. _ f _ j) If a C++ program uses setw, it must include iostream.h.
Assume “Cint” is an integer and “Cfloat’ is a real. Show the output generated by each of the following statements.
a. cout << “The sum of “ << a << “ and “ << b “ is “ << a+b << endl;
b. Cint = a/b; cout << (Cint + 10)/2 << endl;
c. Cfloat = a/b; cout << (Cfloat + 10)/2 << endl;
d. cout << “The sum of “ << setw( 5) << a << “ and “ << setw(5) << b << “ is “ << setw( 4) << a+b << endl;
e. Cfloat = 1.5; cout << floor( Cfloat ) << “ “ << ceil( Cfloat ) << endl;