Solved Midterm Exam for Introduction to Computer Programming | CS 10061, Exams of Computer Science

Material Type: Exam; Professor: Rothstein; Class: INTRODUCTION TO COMPUTER PROGRAMMING; Subject: Computer Science; University: Kent State University; Term: Spring 2010;

Typology: Exams

2010/2011

Uploaded on 05/22/2011

koofers-user-oh6
koofers-user-oh6 🇺🇸

4

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 10061 Introduction to Computer Science, Section 1 Midterm 2 April 14, 2010
CS 10061 Introduction to Computer Science
Section 1
Spring 2010
Call Number 11591
Midterm 2
April 14, 2010
YOUR NAME: ______________________________________________________________
1. (10 points) Write a multiway if-else statement that outputs “Its hot!” if the
value of the variable temperature is greater than 80, it outputs “Its nice!” if
the value of the variable temperature is between 65 and 80, and otherwise
outputs “Its cold!
if ( temperature > 80 ) cout << “Its hot!\n”;
else if (temperature > 65 ) cout << “Its nice!\n”;
else cout << “Its cold!\n”;
2. (10 points) What is output by this code?
do
cout << 1;
while (y != y);
cout << endl;
Only the number 1 followed by an endl.
Page 1
pf3
pf4

Partial preview of the text

Download Solved Midterm Exam for Introduction to Computer Programming | CS 10061 and more Exams Computer Science in PDF only on Docsity!

CS 10061 Introduction to Computer Science

Section 1

Spring 2010

Call Number 11591

Midterm 2

April 14, 2010

YOUR NAME: ______________________________________________________________

1. (10 points) Write a multiway if-else statement that outputs “Its hot!” if the value of the variable temperature is greater than 80, it outputs “Its nice!” if the value of the variable temperature is between 65 and 80, and otherwise outputs “Its cold!” if ( temperature > 80 ) cout << “Its hot!\n”; else if (temperature > 65 ) cout << “Its nice!\n”; else cout << “Its cold!\n”;

  1. (10 points) What is output by this code? do cout << 1; while (y != y); cout << endl; Only the number 1 followed by an endl.

3. (15 points) Write a function declaration (prototype) and a function definition for a function that takes three arguments, of type double and returns their average. double average(double a,double b,double c); double average(double a,double b,double c){ return ((a+b+c)/3.0); }

  1. (15 points) Writer a driver program to test the function in question 3. #include using namespace std; int main() { double a,b,c; while(1){ cout << “Give me three numbers to test.”; cin >> a >> b >> c; cout << “The output is “ << average(a,b,c) << endl; } return 0; }
  1. (10 points) Assume variables max,n1 and n2 have been declared type int. Write code to set max to the greater of n1 and n2. max = (n1 >n2)? n1:n2;
  2. (15 points) Write a void function using two type int call-by-reference parameters that swaps the values in the arguments. Void swap(int &a,int &b){ int temp; temp = a; a = b; b = temp; }
  3. (5 points) Briefly explain what a stub is. A stub is a short function which cannot fail and is used to test another function which calls a function with the name of the stub.