Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Mastery Exam with Solutions | Computer Program for Science | CSC 107, Study notes of Computer Science

Material Type: Notes; Professor: Hertz; Class: Computer Program for Science; Subject: Computer Science; University: Canisius College; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-fmk
koofers-user-fmk 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC 107L – Programming For Science
Mastery Exam
Directions:
1) This exam is to be done individually and is open book and open notes, but closed
Internet. Any communication between students is considered de facto cheating
and any students involved will automatically fail this lab. Any questions you may
have should be directed to the instructor.
2) Read the instructions for each problem carefully. Questions explicitly state the
code you need to write. If you are unsure about whether you need to write
something, ask the instructor.
3) You should start by typing (including a space before the period & the period):
cp ~hertzm/mastery/* .
You will find all the files you need for this mastery exam. You may need to write
C programs from scratch.
4) Each question is independent and you can solve the problems in any order you
wish. Since the questions are weighted equally, you may wish to solve the
easiest/quickest problems first.
5) There are different levels of completion of each question: it compiles, it runs but
crashes, it runs without crashing but gets the wrong answer, and it runs and gets
the correct answer. These are worth 20%, 20%, 20%, and 40%, respectively.
Commenting your code is appreciated, but will not be graded. You can only earn
credit for code you modify and submit.
6) At the end of class, e-mail your .c files to me.
pf3

Partial preview of the text

Download Mastery Exam with Solutions | Computer Program for Science | CSC 107 and more Study notes Computer Science in PDF only on Docsity!

CSC 107L – Programming For Science

Mastery Exam

Directions:

  1. This exam is to be done individually and is open book and open notes, but closed Internet. Any communication between students is considered de facto cheating and any students involved will automatically fail this lab. Any questions you may have should be directed to the instructor.
  2. Read the instructions for each problem carefully. Questions explicitly state the code you need to write. If you are unsure about whether you need to write something, ask the instructor.
  3. You should start by typing ( including a space before the period & the period): cp ~hertzm/mastery/*. You will find all the files you need for this mastery exam. You may need to write C programs from scratch.
  4. Each question is independent and you can solve the problems in any order you wish. Since the questions are weighted equally, you may wish to solve the easiest/quickest problems first.
  5. There are different levels of completion of each question: it compiles, it runs but crashes, it runs without crashing but gets the wrong answer, and it runs and gets the correct answer. These are worth 20%, 20%, 20%, and 40%, respectively. Commenting your code is appreciated, but will not be graded. You can only earn credit for code you modify and submit.
  6. At the end of class, e-mail your .c files to me.

Question

In this question, you will compute the resistance of a circuit that contains a number of resistors that operate in parallel. Given a series of n resistors in parallel whose resistances are R 1 , R 2 , R 3 , …, Rn, the resistance of the circuit is computed using:

Rciccuit R R R R n

1 2 3

= + + +K +

The resistances will be stored in a file named “resist.txt”. The first line of this file contains the number of resistors it contains. Each line then contains the resistance for the next resistor. Write a program (named question1.c) that reads in this file and outputs the circuit’s resistance. You can do this using the following algorithm:

algorithmalgorithm main(void) algorithmalgorithm FILE * fIn; int i , resistors ; double circuit = 0, resistance ; Open “resist.txt” and store file pointer in fIn Read resistors from fIn forfor forfor i = 1 to resistors , inclusive, increasing by 1 each iteration Read in resistance from fIn Increase the value of circuit by ( resistance )- end forend for end forend for Close fIn

Set circuit to circuit

Print out the value of circuit

While you do not need to match my output exactly, you should get the same numerical result as I did. The instructor’s solution printed out:

This circuit has a resistance of: 2.