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

Practice Midterm Exam 2 - Fall 2006 - Computer Program for Science | CSC 107, Exams of Computer Science

Material Type: Exam; Class: Computer Program for Science; Subject: Computer Science; University: Canisius College; Term: Fall 2006;

Typology: Exams

Pre 2010

Uploaded on 08/16/2009

koofers-user-5uz
koofers-user-5uz 🇺🇸

5

(1)

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name: CSC107 F06 Midterm #2 Page 1
CSC 107: Fall 2006 Midterm #2
Directions:
Clearly write your name at the top of every page.
Skim the entire exam before you start working. Not all questions are of equal difficulty; start
with the easiest ones before moving to the harder ones.
No computers or collaborations allowed.
If you need extra space for a problem, use the back of the previous page and then, if you
need even more space, ask for scratch paper.
Indicate your final answer clearly. Erase, scratch out, or otherwise clearly show anything
that is not part of your answer. I will grade anything I see that might be your answer.
When a question asks you to write code, you must supply working C code to earn full credit.
Minor syntactic errors will not be penalized, but what the code does must be clear.
If you have a question about what something means, ask. Better to ask and get the question
right, then guess and get a 0.
Points Breakdown:
1. 18 points
2. 20 points
3. 25 points
4. 25 points
5. 10 points
6. 2 points
Total Points: 100 points
pf3
pf4
pf5

Partial preview of the text

Download Practice Midterm Exam 2 - Fall 2006 - Computer Program for Science | CSC 107 and more Exams Computer Science in PDF only on Docsity!

CSC 107: Fall 2006 Midterm

Directions:

  • Clearly write your name at the top of every page.
  • Skim the entire exam before you start working. Not all questions are of equal difficulty; start with the easiest ones before moving to the harder ones.
  • No computers or collaborations allowed.
  • If you need extra space for a problem, use the back of the previous page and then, if you need even more space, ask for scratch paper.
  • Indicate your final answer clearly. Erase, scratch out, or otherwise clearly show anything that is not part of your answer. I will grade anything I see that might be your answer.
  • When a question asks you to write code, you must supply working C code to earn full credit. Minor syntactic errors will not be penalized, but what the code does must be clear.
  • If you have a question about what something means, ask. Better to ask and get the question right, then guess and get a 0.

Points Breakdown:

  1. 18 points
  2. 20 points
  3. 25 points
  4. 25 points
  5. 10 points
  6. 2 points

Total Points: 100 points

Problems:

  1. [6 * 3 points] Each of the following printf, scanf, fprintf, and fscanf commands contain exactly one error. The error may be a syntax error or a run-time error. Using the following variable declarations, rewrite each commands to remove the error. All file output should use the fOutput file pointer; all file input should use the fInput file pointer.

int iA, iB, iC; double dX, dY, dZ; FILE (^) *fInput, *fOutput;

(a) [3 points] fscanf(‘‘Hi, Mom! I am rocking this midterm’’);

(b) [3 points] fprintf(FILE (^) *fOutput, ‘‘%d %d’’, iB, iC);

(c) [3 points] scanf(‘‘%d’’, iA);

(d) [3 points] printf(‘‘%lf’’ dZ);

(e) [3 points] fscanf(fInput, ‘‘%lf %d’’, &iA, &iB);

(f) [3 points] printf(‘‘%d %lf’’, &iC, dZ);

  1. [25 points] Use the provided function to complete the following program. For each of the solar system’s 4 inner planets (e.g., Mecury, Venus, Earth, and Mars), compute and print out how much a sack of potatos weighs on them. For full credit, you must use the symbolic constants and computeWeight.

#include <stdio.h> #include <stdlib.h>

#define MERCURY_GRAVITY 0. #define VENUS_GRAVITY 0. #define EARTH_GRAVITY 1. #define MARS_GRAVITY 0.

#define SACK_MASS 5 // Potatos are sold in 5 lb. bags

double computeWeight( double planetsGrav, double mass) { return (planetsGrav (^) * mass); }

int main( void ) { double potatoNewWeight;

/* Add your code here (^) */

  1. [25 points] Two cars, one going due North and one going due East, collide in an intersection. After the crash, the cars stick together. Complete the following C program so that it computes the angle and speed which the mass of crumpled steel travels.

#include <stdio.h> #include <stdlib.h>

int main( void ) { /* To solve this problem you will need to:

  • 1.^ Declare^ the^ variables^ you^ need
  • 2.^ Open^ file^ named^ ‘‘cars.dat’’^ for^ reading
  • 3.^ Read^ first^ car’s^ mass^ &^ velocity^ (both^ are^ doubles)
  • 4.^ Read^ second^ car’s^ mass^ &^ velocity^ (both^ are^ doubles)
  • 5.^ Close^ the^ file
  • 6.^ Compute^ the^ angle^ they^ travel^ after^ the^ accident^ using:
  • angle^ =^ atan((massCar2^ * vCar2)^ /^ (massCar1^ * vCar1));
  • 7.^ Compute^ the^ velocity^ of^ the^ 2-car^ wreck:
  • velocity^ =^ ((massCar2^ * vCar2)^ /
  • ((massCar1^ +^ massCar2)^ * sin(angle)));
  • 8.^ Print^ out^ value^ computed^ for^ angle^ and^ velocity.