Docsity

7 Problems on Computing for Engineers - Exam 1. | CS 1371, Exams of Computer Science

Partial preview of the text

Download 7 Problems on Computing for Engineers - Exam 1. | CS 1371 and more Exams Computer Science in PDF only on Docsity!

Georgia Institute of Technology

College of Computing

CS 1371 Computing for Engineers

Test 1 Practice Test - Fall Semester 2006

Use this practice test and the book questions for chapters 1-7 excluding

Section 7.3 – enumerated types for practice.

There is some measurable probability that the real test will contain one

of these problems as written.

Problem 1 – Short Answer

a) What computing language does this course (CS 1372) use? Circle one answer.

A) A

B) B

C) C

D) Matlab

b) Three of the following are required from the ANSI C syntax, and one is just good coding

advice. Circle the one which is merely advice.

A) An identifier must consist of only letters, digits, and underscores

B) An identifier defined in a C standard library cannot be redefined

C) An identifier cannot begin with a digit

D) A C reserved word cannot be used as an identifier

c) Which of the following is a valid identifier (circle all that apply)

A) 2letter

B) double

C) two*four

D) Joe's

E) none_of_the_above

d) Draw a line through any of the list below that do not result in a valid constant of type

double.

(i) 3. (ii) 0. (iii) .12345e (iv) 2.34e (v) 1, (vi) 15e-1. (vii) 12.12e+ (viii) 150

d) Mark any changes to each line below so that they are complete comments

% a single line comment /* this one /* seems like a comment */ doesn't it / / This is a comment? *\

e) Write the results for each of the following operations

Problem 3 – Tracing

What is displayed when the following code is run (assume it compiled and linked correctly)?

--------------------------------------- myStuff.h----------------------- #include <stdio.h> void fun1(double); void fun2(int); -----------------------------------------------------myStuff.ccp----------


#include "myStuff.h" void fun1(double D){ for(int count = 0 ; count < D; count++){ printf("42\n"); fun2(count); } } void fun2(int I){ for(int count = 0 ; count < I; count++){ printf("1371\n"); } } -------------------------------------------------------basic.ccp----------


#include "myStuff.h" int main(void) { double n = 3; printf("start\n"); while (n > 0 ){ fun1(n); n--; } printf("done"); getchar(); return 0; } Your answer here:

Problem 4 – Coding

Two beat artists, Slick and Monique, are going to perform together one night at the club. Unfortunately they will probably use different beat styles that only overlap a few times a minute. The club manager ask you want to make sure that there will be sufficient simultaneous beats to keep the audience enticed, so you need to get a program ready for when Slick and Monique arrive. Your program will prompt them for their beat speeds in beats per minute, and print the number of overlaps. You can assume they will both start at the same time with a beat and keep a steady pace. Hint: the frequency of coincidence is the absolute value of the difference between the two beat frequencies.

The basics are provided for you.

#include <stdio.h> int main(void) { // most of your code here

Problem 6 – Coding

Write a function guess_it that consumes an integer and repeatedly asks the user to enter a

number until he enters the given number. If the number is right, the program exits. If not, it

prints either “go higher” or “go lower” until he gets it right.

Problem 7 – Code Analysis

Consider the following code. Circle and mark with a C all the errors that will produce a

compilation failure. Then assuming these are corrected, circle and mark with L all the logic

errors.

#include <stdio.h>;

int main() { int year, days; printf("what year? "); scanf("%d", year);

bool leap_year = year%1000 ~= 0; leap_year = leap_year && year%4 == 0;

for(month = 0; month <= 12; month++); { switch(month) { case 1: days = 31; break; case 2: if leap_year days = 29; else days = 28; case 4: days = 30;

otherwise: days = -1; } } }