ENEE 114 Sample Midterm Exam: Programming Concepts for Engineers - Prof. Shuvra S. Bhattac, Assignments of Electrical and Electronics Engineering

This is a sample midterm exam for the ENEE 114 course at the University of Maryland, College Park, covering programming concepts for engineers. The exam includes questions related to code segments, function outputs, and writing functions. It is for reference only and was used in the March 12, 1998 exam.

Typology: Assignments

2019/2020

Uploaded on 11/25/2020

koofers-user-7fn
koofers-user-7fn 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Electrical and Computer Engineering, University of Maryland at College Park
ENEE 114: Programming Concepts for Engineers
Fall 2000, Prof. S. S. Bhattacharyya
Handout #9
Sample midterm exam, (from ENEE 114, March 12, 1998)
This is not an assignment -- this is for your reference only.
OFFICIAL EXAMINATION
From: The Code of Academic Integrity
Academic dishonesty is a serious offense which may result in suspension or expulsion from the
University. In addition to any other action taken, such as suspension or expulsion, the grade “XF” denoting
“failure due to academic dishonesty” will normally be recorded on the transcripts of students found responsible
for acts of academic dishonesty.
Students are encouraged to report academic dishonesty. Dial 314-8206 and ask for the Campus
Advocate.
Student Name (printed):_______________________________________________________
Student I.D.: ________________________________________________________________
Signature:__________________________________________________________________
Recitation section number: _____________________________________________________
Seating: Section (circle one) LeftCenterRight Row# (front=1) _____________
EXAMINATION RULES (Read Carefully)
Place final answer for each question into the appropriate bold box or underlined blanks. You will not
receive full credit even if you have the right answer if it is not placed in the right place.
This examination is open book and open notes, but no calculators are allowed.
Please PRINT legibly. If your work is not clear, it will be marked as wrong.
Please write your name and recitation section number at the top of every page.
Please show your work for all questions directly on this examination in order to receive partial credit
(where appropriate).
If you need more space than provided, use the back side of these pages.
Please make sure that all pages are present. Notify instructor immediately if a page is missing.
Number in brackets before each question is total points awarded for that question.
Total
432
/100
/20/20/20
5
/20
1
/20
pf3
pf4
pf5

Partial preview of the text

Download ENEE 114 Sample Midterm Exam: Programming Concepts for Engineers - Prof. Shuvra S. Bhattac and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Department of Electrical and Computer Engineering, University of Maryland at College Park

ENEE 114: Programming Concepts for Engineers

Fall 2000, Prof. S. S. Bhattacharyya

Handout

Sample midterm exam, (from ENEE 114, March 12, 1998)

This is not an assignment -- this is for your reference only.

OFFICIAL EXAMINATION

From: The Code of Academic Integrity

Academic dishonesty is a serious offense which may result in suspension or expulsion from the

University. In addition to any other action taken, such as suspension or expulsion, the grade “XF” denoting

“failure due to academic dishonesty” will normally be recorded on the transcripts of students found responsible

for acts of academic dishonesty.

Students are encouraged to report academic dishonesty. Dial 314-8206 and ask for the Campus

Advocate.

Student Name (printed):_______________________________________________________

Student I.D.: ________________________________________________________________

Signature:__________________________________________________________________

Recitation section number: _____________________________________________________

Seating: Section (circle one) Left Center Right Row# ( front =1) _____________

EXAMINATION RULES (Read Carefully)

• Place final answer for each question into the appropriate bold box or underlined blanks. You will not

receive full credit even if you have the right answer if it is not placed in the right place.

• This examination is open book and open notes, but no calculators are allowed.

• Please PRINT legibly. If your work is not clear, it will be marked as wrong.

• Please write your name and recitation section number at the top of every page.

• Please show your work for all questions directly on this examination in order to receive partial credit

(where appropriate).

• If you need more space than provided, use the back side of these pages.

• Please make sure that all pages are present. Notify instructor immediately if a page is missing.

• Number in brackets before each question is total points awarded for that question.

Total

Question 1[20 points]

For each of the following code segments, show the exact number of asterisks that are printed to the screen.

Example:

int i=3; NUMBER OF ASTERISKS: 6 if (i<2) printf("****"); else printf("******");

a) [4]

int i=0; NUMBER OF ASTERISKS: ___________ while (i<12) { if ((i%3)==0) printf(""); i++; if ((i%4)==0) printf(""); }

b) [4]

int i=1, j=1; NUMBER OF ASTERISKS: ___________ while ((i+j)<10) { printf("*"); i++; j+=2; }

c) [4]

int i=3, j=7; NUMBER OF ASTERISKS: ___________ if (((i+4)(j–2)) < 30) printf(""); else if (((j+4)/i) <= 3) printf(""); else printf("**"); if (((i+3)<(j–7))&&(!(i+j < 20))&&(i)) printf(“****”); if ((!(i>1))||(!((j+4)<23))||(ij < 100)) printf(“*****”);

d) [4]

int i=6, j=17; NUMBER OF ASTERISKS: ___________ if ((i<j) && (j>=(36))) printf(""); else if (((2i)<j) || ((3i)<j)) printf(""); else if ((3i)==(j+1)) printf("**");

e) [4]

int i; NUMBER OF ASTERISKS: ___________ for (i=0; i<100; i+=10) { switch(i) { case 30: printf(""); break; case 60: printf(""); break; case 90: printf("****"); break; default: printf(""); break; } }

Question 3[20 Points]

For each of the following four programs, show the exact output as it would be printed to the screen.

a) [5]

#include <stdio.h> int main(void) { int x[] = {4, 5, 11, 6, –1, 0, 3}; int i=2; printf("1: %d\n", x[3]); printf("2: %d\n", x[1] + x[4]); printf("3: %d\n", x[i++]); printf("4: %d\n", x[++i]); printf("5: %d\n", x[x[1]]); return 0; }

b) [5]

#include <stdio.h> int main(void) { int nums[] = {2, 1, 6, 1, 5, 1, 4}; int i, sum = 0; for (i=(–5); i<=5; i++) { if (i==0) i++; if (i<0) sum += nums[–i]; else sum += nums[i]; } printf("The sum is %d.\n", sum); return 0; }

c) [5]

#include <stdio.h> int main(void) { int x[] = {4, 5, 11, 8, 18, 0, 3}; int i=1, m=0; while (i<7) { if ((x[i]–x[i–1]) > m) m = x[i]; i++; } printf("Result: %d\n", m); return 0; }

d) [5]

#include <stdio.h> #define M 5

int main(void) { int A[M], i, sum=0; for (i=0; i<M; i++) { A[M–i–1] = i*2; } for (i=0; i<M; i++) { sum += A[i] * (i+1); } printf("The sum is %d.\n", sum); return 0; }

program output

program output

program output

program output

Question 4[20 Points]

Linda Jones drove her car non-stop for 20 hours. During the first 10 hours, she drove at a speed of 45 miles

per hour, and during the last 10 hours she drove at a speed of 48 miles per hour. Write a function called

miles_driven that takes a single parameter x , which is of type int , and returns the number of miles driven by Linda

during the first x hours of her drive. The return type of miles_driven should be int. For example, if the value of the

argument to miles_driven is 3, the function should return the value 135.

No error checking is required in the function. You may assume that whenever the function is called, the

value of the argument x is in the range 0? x? 20.

Code for function miles_driven(x):