EECE 230 Exam 1 Sample, Fall 2005

American University of Beirut · Introduction to Programming · 1 page · Dr. Ali Hajj

All EECE 230 files
EECE 230 Exam 1 Sample, Fall 2005, page 1

Stuck on a question? A tutor can walk you through it.

More EECE 230 files

Show the text of this exam
EL-HAJJ A. FACULTY OF ENGINEERING AND ARCHITECTURE AMERICAN UNIVERSITY OF BEIRUT FALL TERM 2005 QUIZ ONE EECE230 November 2005 COMPUTERS AND PROGRAMMING NAME:____________________ ID No.:_____________________ CLOSED BOOK ( 1 Hour 30 minutes ) 1- Write a program that implements the following: (use the double type)  Write a function area(width,length) that calculates the area of a rectangle with given width and length. (5 points)  Write a function perimeter(width,length) that calculates the perimeter of a rectangle with given width and length. (5 points)  Write a function scaled_rectangle(scale, width,length) that modifies the width and length of a rectangle by multiplying each by the scale. Use value parameter and reference parameter when necessary.(10 points)  Write an interactive program that asks the user to enter the width and length of a rectangle, and uses the previous functions to calculate and display its perimeter and area.(10 points)  Add code that asks the user to enter a scale factor, and uses the previous functions to calculate and display the perimeter and area of the scaled rectangle.(10 points)  Creates a data file called “rectangle.dat” in which to store the width, length, area, and perimeter of the scaled and unscaled rectangles of the previous questions. (10 points) 2- Consider the function sum(n)= 1+1/5 +1/10 +… +1/5n .  Write a nonrecursive version of sum(n). Use it to calculate sum(100). (10 points)  Write a recursive version of sum(n)= sum(n-1)+ 1/5n. Use it to calculate sum(100). (10 points) 3- Implement the following code:  Write a boolean function multiple(a,b,c) that returns true if any of the three integer arguments is a common multiplier of the two others. (10 points)  Write a function largest (a,b,c) that returns the largest of the 3 arguments. (10 points)  Write code that reads three integers, checks if any of these three integer is a common multiplier of the two others, and displays this common multiplier or displays “No common multiplier”. (10 points)