{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm1-samplequestions

# midterm1-samplequestions - CS 201(Introduction to Computing...

This preview shows pages 1–7. Sign up to view the full content.

CS 201 (Introduction to Computing) Fall 2009-2010 Sabancı University - Sample Questions and Solutions for Midterm 1 Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also review recitation questions, samples covered in the class, homeworks and the questions in the book as well The amount of questions here is of course much more than the actual exam. QUESTIONS 1) Write a function that takes an integer type of parameter and returns its reciprocal. If the parameter is zero, then the function should return 0. In the main program, first input two integer values. Then find the sum of the reciprocals of all of the numbers between these two inputs. In the main program, you have to use the reciprocal function. 2 ) Write a function that takes three string values as parameters and displays them in lexicographical order. © CS201 Team at Sabancı University

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
NAME: 3) a) Rewrite the following expression using C++ syntax. 3 sin a a c b c b a c - - b) What are the results of the following expressions? 5+3/5+72*!(2+5)==12%8*-10 (20*1.5/(2*6-8)-7)*11 c) The range of short unsigned integer is [0 . . 65535]. Why is the upper limit is 65535? d) Write the statement to display the sum of the digits of a two-digit integer number (call it num). e) We do not include anything to use int, but we need to include string header file to use string. Why is that? f) Suppose you are writing a program to convert days into seconds. Assuming you are doing integer arithmetic using unsigned long integers for this purpose, what should be the maximum value of days to avoid any overflow problems? g) Rewrite using for statement instead of while while(year<=4002) { sum += year; cout << year << endl; year += sum; © CS201 Team at Sabancı University
NAME: } © CS201 Team at Sabancı University

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
NAME: 4) Trace and display the output of the program using the data given below? #include <iostream> using namespace std; int main() { int cnt, x, y, dif; cnt = 0; cin >> x; do { cin >> y; dif = y - x; if (dif > 1) while ( x+1 < y) { ++x; cout<<”Number= ”<<x<<endl; } x = y; ++cnt; } while (cnt != 3); return 0; } Data input 12 15 16 20 © CS201 Team at Sabancı University
NAME: 5) What is the output of the following program? #include <iostream> using namespace std; int A(int i); float B(char c); void C(float x); int main() { int p = 0; float q = 0.0; char r = 'D'; p = A(p); q = B(r); C(B(r)); p = A(A(p)); return 0; } int A(int i) { cout << "A" << endl; return i+1; } float B(char c) { cout << "B" << endl; return 7; } void C(float x) { cout << "C" << endl; } © CS201 Team at Sabancı University

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
NAME: 6 ) There are up to five (5) syntax errors of the following program. However, there might be less than five.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 12

midterm1-samplequestions - CS 201(Introduction to Computing...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online