UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Similar documents
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CS 108 Computing Fundamentals. October/November Array Bootcamp

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

COS 126 General Computer Science Spring Written Exam 1

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

CS16 Exam #1 7/17/ Minutes 100 Points total

APS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example:

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CSE413 Midterm. Question Max Points Total 100

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Slides adopted from T. Ferguson Spring 2016

Final Exam. COMP Summer I June 26, points

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity:

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015

1. The keyword main in C language is used for

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

ESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011

BSM540 Basics of C Language

ECE 15 Fall 15 Midterm Solutions

Q1: Functions / 33 Q2: Arrays / 47 Q3: Multiple choice / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

CSE 131S Introduction to Computer Science Summer SON Exam I

16.216: ECE Application Programming Fall 2011

Fundamentals of Programming & Procedural Programming

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Make sure the version number is marked on your scantron sheet. This is Version 1

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Programming for Electrical and Computer Engineers. Pointers and Arrays

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

C introduction: part 1

DECLARAING AND INITIALIZING POINTERS

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2013 Midterm I Key

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

C Programming for Engineers Functions

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CSCI 2132 Software Development. Lecture 18: Functions

Chapter 2. Section 2.5 while Loop. CS 50 Hathairat Rattanasook

Project 1. due date Sunday July 8, 2018, 12:00 noon

Q1 (15) Q2 (15) Q3 (15) Q4 (15) Total (60)

Fundamental of Programming (C)

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

Fundamental of Programming (C)

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

EXAM Computer Science 1 Part 1

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

ECOR Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

ECE15: Introduction to Computer Programming Using the C Language. Lecture Unit 4: Flow of Control

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter 12: Pointers and Arrays. Chapter 12. Pointers and Arrays. Copyright 2008 W. W. Norton & Company. All rights reserved.

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

CSE 131 Introduction to Computer Science Fall Exam I

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

As stated earlier, the declaration

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

Module 6: Array in C

Decision Making -Branching. Class Incharge: S. Sasirekha

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

C Program Development and Debugging under Unix SEEM 3460

Principles of C and Memory Management

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

COS 126 MIDTERM 1, FALL

To become familiar with array manipulation, searching, and sorting.

CSCI 2132 Software Development. Lecture 20: Program Organization

ENCM 335 Fall 2018 Lab 2 for the Week of September 24

Transcription:

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 20, 2011 6:15 p.m. 8:00 p.m. (105 minutes) Examiners: J. Anderson, T. Fairgrieve, B. Li, G. Steffan, A. Veneris Exam Type A: This is a closed book examination; no aids are permitted. Calculator Type 4: No calculators or other electronic devices are allowed. All questions are to be answered on the examination paper. If the space provided for a question is insufficient, you may use the last page to complete your answer. If you use the last page, please direct the marker to that page and indicate clearly on that page which question(s) you are answering there. You must use the C programming language to answer programming questions. You are not required write #include directives in your solutions. You may use any math function that you have learned, as necessary. The examination has 13 pages, including this one. Circle your lecture section (one mark deduction if you do not correctly indicate your section): L0101 L0102 L0103 L0104 L0105 L0106 Li Fairgrieve Anderson Steffan Fairgrieve Veneris Monday 2 PM Monday 9 AM Monday 11 AM Monday 11 AM Monday 4 PM Monday 4 PM Full Name: Student Number: UTORid: MARKS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Total /3 /3 /3 /4 /4 /3 /8 /8 /4 /12 /12 /12 /12 /12 /100

Question 1 [3 Marks] Write a single C statement that declares a bool variable named mybool and sets its value to true if and only if the value stored in an integer variable named myint is an even positive number. You may assume that the variable myint has been declared and initialized already to some value. Question 2 [3 Marks] The golden ratio conjugate Φ is defined as Φ = 5 1 2. This mathematical constant is used in different fields of computer engineering such as numerical analysis, combinatorial algorithms, etc. Write a single C statement that declares a constant variable named PHI and sets PHI to be equal to the value of Φ given above. You may make use of functions defined in math.h. Question 3 [3 Marks] Suppose we have the following declaration and initialization of variables: double a = 23.0, b = 20.0, c = 15.0, d = 8.0, e = 40.0; What is the value for the following expression? (int) (a + b / (c - 5.0)) / ((d + 7.0) / (e - 37.0) / 2.0) 2

Question 4 [4 Marks] Let i be an int variable with value 5, j be an int variable with value 0, and k be a bool variable set to false. State whether the following expressions evaluate to true or false. Expression Answer ( (i >= 3) && (j == (int) 0.0) ) ( ((i!= 3) (j!= 4)) ==!((i == 3) && (j == 4)) )!( (i-4) <= 0 ) ( k && (sin(42.0) == 0.1372) ) Question 5 [4 Marks] Write a single C statement that declares an int type variable named lotto, and initializes it to be an odd random integer between 601 and 649 (inclusive). Question 6 [3 Marks] What will be printed by the following C program? int i; for(i = 0; i < 5; i++) printf("%c", a +i); return 0; 3

Question 7 [8 Marks] Given the following C program: #include <stdio.h> int a = 1; int b = 2; while (a <= 45) printf("%d\n", a); a += b; b++; return 0; What is the output from an execution of this C program? 4

Question 8 [8 Marks] Given the following C program: #include <stdio.h> int row, col; for (row = 1; row <= 5; row++) for (col = 1; col <= 9; col++) if ((col > row) && (col <= (9-row))) printf(" "); else printf("*"); printf("\n"); return 0; What is the output from an execution of this C program? 5

Question 9 [4 Marks] For each of the following parts, determine the number of times that the word Chicken will be printed. Place your answer in the appropriate box. (a) for (int i=0; i < 10; i++) for (int j=0; j < 10; j++) if (i < j) printf("chicken\n"); Will print Chicken times. (b) for (int i=0; i >= 0; i++) for ( ; i < 100; ) while (i!= 0) printf("chicken\n"); Will print Chicken times. 6

Question 10 [12 Marks] Write a program that prompts the user to enter two dates and then indicates which date comes earlier in the calendar. Assume that the user enters valid dates. Here is a sample output from an execution of the program: Enter first date (day/month): 20/10<enter> Enter second date (day/month): 22/9<enter> 22/9 is earlier than 20/10 Here is another sample output from an execution of the program: Enter first date (day/month): 20/10<enter> Enter second date (day/month): 20/10<enter> The two dates are the same. #include <stdio.h> 7

Question 11 [12 Marks] Write a program that finds the largest positive number in a list of numbers entered by the user. The program must prompt the user to enter numbers one by one. When the user enters 0 or a negative number, the program must stop prompting the user for numbers and display the largest positive number that was entered. Note that the length of the list of positive numbers could be arbitrarily large. You may assume that at least one positive number will be input. Here is a sample output from an execution of the program: Enter a number: 60<enter> Enter a number: 4.89<enter> Enter a number: 100.62<enter> Enter a number: 75.2295<enter> Enter a number: 0<enter> The largest positive number entered was: 100.620000 Notice that the numbers aren t necessarily integers. #include <stdio.h> 8

Question 12 [12 Marks] Write a function named pythagoreantriples that accepts a positive integer x as its parameter, and prints one triple (x, y, z) such that: (a) x 2 + y 2 = z 2 ; (b) y > 0 and y <= 100; (c) y < z; (d) x, y, z are all positive integers. If no triple exists that satisfies all four conditions, then the function prints "No solution exists.". Assume that the argument value for x is a positive integer. For example, if we compile and run the pythagoreantriples function with the following main() program: pythagoreantriples(3); pythagoreantriples(12); pythagoreantriples(20); pythagoreantriples(49); return 0; the following will be printed: (3, 4, 5) (12, 5, 13) (20, 15, 25) No solution exists. Place your solution to this question on the next page. 9

Place your solution to Question 12 on this page. void pythagoreantriples (int x) 10

Question 13 [12 Marks] In the indicated position in the program below, define a function called rotate that rotates the values pointed to by the three pointer-to-integer parameters in such a way that after executing the function, the first has the original value of the third, the second has the original value of the first, and the third has the original value of the second. Example 1: Please input three integers: 3 4 5 After rotation, the list of integers is: 5 3 4 Example 2: Please input three integers: 9 3 7 After rotation, the list of integers is: 7 9 3 Program: #include <stdio.h> // define rotate HERE: void rotate (int *a, int *b, int *c) int x,y,z; printf("please input three integers: "); scanf("%d %d %d",&x,&y,&z); rotate(&x,&y,&z); printf("after rotation, the list of integers is: %d %d %d\n",x,y,z); return 0; 11

Question 14 [12 Marks] Amicable numbers are two different positive integers such that the sum of the proper exact divisors of each is equal to the other number. A proper exact divisor is a positive integer exact divisor of a number, other than the number itself. For example, the proper exact divisors of 6 are 1, 2, and 3. 220 and 284 are amicable numbers. The reason is as follows: the proper exact divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110, the sum of which is 284. The proper exact divisors of 284 are 1, 2, 4, 71, and 142, the sum of which is 220. Write a complete C function called areamicable, the prototype of which is given below, that accepts two numbers of type int as parameters, named m and n. The function must return the Boolean type bool. The function should return true if m and n are amicable numbers, and should return false otherwise. You may assume that the arguments passed to the function are indeed positive integers. bool areamicable (int m, int n) 12

This page has been left blank intentionally. You may use it for answers to any questions. 13