Answers Key Exam 1 - 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 I February 17,
2010
CS 10061 Introduction to Computer Science
Section 1
Spring 2010
Call Number 11591
First Midterm
February 17, 2010
YOUR NAME: Answer key ( answers may vary )
Part 1 (Fill in the blank)
1. In C++, legal identifiers may contain these kinds of characters letters ,
digits , underscore (_)
2. In C++, a variable that has been defined but not initialized may not be use as an l-value . (l-
value or r-value).
3. Identifiers should at least give a hint to the human reader of the meaning/use of the
identifier in the context of the problem being solved.
4. The literal 'A' represents a character (char) .
5. The value of the expression 5/3 is 1 . (quotient on integer division)
Part 2 (Programming fragment exercises)
1. Declare a variable pay of type double.
double pay;
2. Write a statement that finds the average of two variables (already declared as type double)
called old and new and stores the result in a variable called result which has already been
declared double)
result = (old + new) /2;
Page 1
pf3
pf4

Partial preview of the text

Download Answers Key Exam 1 - 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

First Midterm

February 17, 2010

YOUR NAME: Answer key ( answers may vary ) Part 1 (Fill in the blank)

  1. In C++, legal identifiers may contain these kinds of characters letters , digits , underscore (_)
  2. In C++, a variable that has been defined but not initialized may not be use as an l-value. ( l- value or r-value ).
  3. Identifiers should at least give a hint to the human reader of the meaning/use of the identifier in the context of the problem being solved.
  4. The literal 'A' represents a character (char).
  5. The value of the expression 5/3 is 1. (quotient on integer division) Part 2 (Programming fragment exercises)
  6. Declare a variable pay of type double. double pay;
  7. Write a statement that finds the average of two variables (already declared as type double) called old and new and stores the result in a variable called result which has already been declared double) result = (old + new) /2;
  1. Write an output statement that produces the message “The result is” followed by the value of the variable result. Don't forget to start a new line after the output! cout << “The result is “ << result << endl;
  2. Assume the variables first and second have been declared double and initialized. Also assume the variable max has been declared double. Write C++ code to set max to the bigger value of first and second if ( first > second ){ max = first; }else{ max = second; }
  3. What is the most important difference between the while statement and the do-while statement? The do-while statement tests after the loop, so it executes always the loop at least once; the while statement always checks before executing the loop, so it may not execute the loop at all.
  4. Rewrite the following loop as a for loop: int i = 1; while(i < 5) { cout << “Line “ << i << endl; i++; } for(i=1;i<5;i++){ cout << “Line “ << i << endl; }