Quiz 2 - The School of Electrical Engineering and Computer Science

advertisement
CptS 121 – Program Design and Development
January 25, 2016
Your Name: ___________________________
ID#:
___________________________
TA’s Name: ___________________________
Section #: ___________________________
SOLUTION: Take Home: Quiz 2 (15 pts) – Introduction to Computer
Programming and C
NOTE: Submit a hard-copy to your TA in lab this week (along with your
solution to Quiz 1)!
1. (3 pts) Identify the three hard rules for user-defined identifiers. If a
programmer breaks these rules, then the compiler will report a syntax
error.
1. An identifier must only consist of alphabetic characters (lowercase
and uppercase), digits, and underscores.
2. An identifier must not begin with a digit, but can begin with an
underscore.
3. An identifier must not conflict with a reserved word.
2. (3 pts) Why are variables declared and used in C programs?
Variables are declared to allocate memory for a program. The type
associated with each variable provides the compiler with how much
memory should be allocated and how the information will be
represented in memory. In many cases, variables are initialized to a
value upon declaration. Variables can be written to, read from, and
updated by instructions in a program to help solve a given problem.
3. (3 pts) Provide each result for the following three C language
expressions. Numbers listed without a decimal point are considered
integer values and ones with a decimal point are considered double
precision floating-point values.
a. 15.0 / 2
=_____7.5______
b. 6 / 7
=_____0______
c. 8.0 / 2.0
=_____4.0______
4. (3 pts) What C data types should be used to best represent the
following? For each blank, you may list int, double, or char only. These
types may be used multiple times.
a. The initial of your last name?________char________
b. The average salary of engineers? _____double_____________
c. Number of available jobs in computer science?
_______int___________
Instructor: Andrew S. O’Fallon
CptS 121 – Program Design and Development
January 25, 2016
Your Name: ___________________________
ID#:
___________________________
TA’s Name: ___________________________
Section #: ___________________________
5. (3 pts) Provide an example of a technology that interests you. Explain
why!
Instructor: Andrew S. O’Fallon
Download