Final Exam with Solution 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 Final Exam May 13, 2010
CS 10061 Introduction to Computer Science
Section 1
Spring 2010
Call Number 11591
Final Exam
May 13, 2010
YOUR NAME: ______________________________________________________________
1. (15 points) Write code to output the sequence of numbers:
1 4 9 …... i*i until 100
for(int i=1;i<=10;i++) cout << i*i << endl;
2. (10 points) What is output by this code?
for(int i=2;i<100;i=i*i){
cout << i << “ “;
}
cout << endl;
It will output:
2 4 16 <endl>
Page 1
pf3
pf4

Partial preview of the text

Download Final Exam with Solution 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

Final Exam

May 13, 2010

YOUR NAME: ______________________________________________________________

  1. (15 points) Write code to output the sequence of numbers: 1 4 9 …... ii until 100 for(int i=1;i<=10;i++) cout << ii << endl;
  2. (10 points) What is output by this code? for(int i=2;i<100;i=i*i){ cout << i << “ “; } cout << endl; It will output: 2 4 16
  1. (15 points) Write a function definition for a void function that takes three integer values and returns their sum and product (note that we need two additional parameters to return the sum and product) void sumprod(int a,int b,int c,int& sum,int& product){ sum = a+b+c; product = abc; }
  2. (15 points) Writer a driver program to test the function: double unitPrice(int length, int width, double price) { double area = length * width; return (price/area); } #include using namespace std; int main() { int len,width; double price; while(1){ cout << “Input length, width and price”; cin >> len >> width >> price; cout << “Output: “ << unitPrice(len,width,price) << endl; } return 0; }
  1. (15 points) Write a program segment to read in two strings (of maximum length
    1. and output them separated by one space. Note that the strings may contain blanks. char a[31],b[31]; cout << “Input two strings on separate lines”; cin.getline(a,31); cin.getline(b,31); cout << a << “ “ << b << endl;