Program - Introduction to Engineering - Previous Exam, Exams of Biomedical Engineering

Main points of this past exam are: Program, Simply Typing, Compile, Text Editor, Functionality, Designed, Lines of Code

Typology: Exams

2012/2013

Uploaded on 04/01/2013

nishaa
nishaa 🇮🇳

4.3

(13)

56 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 190 Spring 2011
Programming Practice for Exam 1
Programing part of Exam 1 will consist of one problem for which you will be asked to write a
program in C. You can use your favorite text editor, such as vi or nano. You should name your
source code file exam1.c. You can compile your code using gcc compiler as follows:
gcc -g -Wall -Werror -ansi exam1.c -o test
You can then run your program by simply typing
./test
Make sure your program compiles and works before your turn it in. We will not grade a program
that does not compile and you will lose points if the program compiles with warnings. You obviously
will not receive any points if your program does not do what it is supposed to do. Both functionality
and coding style will be graded, with most points given for functionality and some points given for
style. No style grading will be done if the program does not compile.
The programming part of the exam is designed to be one hour long. Not including comments and
empty lines, the exam program can be written in less than 20 lines of code. If your program grows
in size to over 30 lines, you are probably doing something wrong.
Instructions how to turn in your program will be provided at the exam.
Practice Problem 1
In this problem, we will estimate cos(x) function using Taylor series expansion:
where n is the degree of the Taylor series expansion and x is an angle in radians. The program
should print a prompt "Enter x in radians: " and take x in radians as an input. Then the program
should print a prompt "Enter the number of terms: " and take n as input. It then should
approximate the value of cos(x) using the first n terms of the Taylor series expansion and print out
the value of cos(x). Assume the value of x is always given in the range of –π to +π.
You may find cos(x) function plot useful for debugging purposes:
pf2

Partial preview of the text

Download Program - Introduction to Engineering - Previous Exam and more Exams Biomedical Engineering in PDF only on Docsity!

ECE 190 Spring 2011

Programming Practice for Exam 1

Programing part of Exam 1 will consist of one problem for which you will be asked to write a program in C. You can use your favorite text editor, such as vi or nano. You should name your source code file exam1.c. You can compile your code using gcc compiler as follows:

gcc -g -Wall -Werror -ansi exam1.c -o test

You can then run your program by simply typing

./test

Make sure your program compiles and works before your turn it in. We will not grade a program that does not compile and you will lose points if the program compiles with warnings. You obviously will not receive any points if your program does not do what it is supposed to do. Both functionality and coding style will be graded, with most points given for functionality and some points given for style. No style grading will be done if the program does not compile.

The programming part of the exam is designed to be one hour long. Not including comments and empty lines, the exam program can be written in less than 20 lines of code. If your program grows in size to over 30 lines, you are probably doing something wrong.

Instructions how to turn in your program will be provided at the exam.

Practice Problem 1

In this problem, we will estimate cos( x ) function using Taylor series expansion:

where n is the degree of the Taylor series expansion and x is an angle in radians. The program should print a prompt "Enter x in radians: " and take x in radians as an input. Then the program should print a prompt "Enter the number of terms: " and take n as input. It then should approximate the value of cos( x ) using the first n terms of the Taylor series expansion and print out the value of cos(x). Assume the value of x is always given in the range of –π to +π.

You may find cos( x ) function plot useful for debugging purposes:

Practice Problem 2

In this problem, we will write a program to compute integral of a function f ( x )= x^2 +2 x +3 on an interval [ a , b ] using Riemann sum method with left endpoint function evaluation rule:

∫ ∑ ( )

where n is the number of rectangles used in the approximation. The program should print "Enter a and b values: " and take integration interval boundaries a and b as inputs. Then the program should print "Enter the number of terms: " and take n as input. It then should approximate the value of integral for the user-specified interval [ a , b ] and number n using the above definition. Assume that input is always given such that a < b.

You may find y= x^2 +2 x +3 function plot useful for debugging purposes: