Homework Assignments for CSC 255

Fall 2004

 

Note: Any problem that begins with “Write a program … “:

  1. This means that the program must compile and run producing the correct output to get full credit.
  2. Save the program in your class account naming the program hwNpP.ccp where N is the homework number and P is the problem number in that homework set.  The workspace for the problem should be named hwNpP.dsw.  For example, Homework 2, Problem 2 should be named hw2p2.ccp placed in workspace hw2p2.dsw.
  3. Comment your code and use good programming style.  See the program First.ccp in Using-C.htm for details on headers.  All programs will have the information in the header as in First.ccp.

 

Homework 1 (Chapter 1):

1.      (20 pts) If an addition operation can be done in one clock tick, how long, in nanoseconds, does it take to perform an addition for a clock rate of:

(a)    60 MHz  (b) 120 MHz  (c) 180 MHz  (d) 1 GHz

2.      (20 pts) Exactly how many bytes of memory does a computer have if it is said to have:

(a)    640K bytes  (b) 64K bytes  (c) 1M bytes  (d) 16M bytes

3.      (20 pts) Give the decimal values for the following numbers:

(a)    000100012  (b) 07438  (c) E23A16  (d) 54328  (e) 010100100112

4.      (20 pts) Convert the following numbers to the specified base:

(a)    7778 to hexadecimal  (b) AD1116 to binary  (c) 111116 to octal  (d) 37718 to binary

5.      (10 pts) Give the decimal value of the following 8-bit tow’s complement numbers:

(a)    101011002  (b) 100000012  (c) 110000002  (d) 101001012

6.      (10 pts) Compute the following sums and products.  Your answer should be in binary.

(a)    01000110 + 0001010

(b)   00111011 + 0101100

(c)    00100111 * 0001111

(d)   00010101 * 0001000

 

Homework 2 (Chapter 2):

1.      (10 pts) What is the result of the following expressions?  Express your answers as <value, type>.

(a)    22.1 + 1.0  (b) 7 – 21  (c) (27 / 3) + 15  (d) –23 + 7 * 2

 

2.      (15 pts) Write a program that accepts a Fahrenheit temperature and outputs the equivalent centigrade temperature.  The equation for converting a Fahrenheit temperature to Celsius is:  Celsius = 5/9 (Fahrenheit – 32)

 

3.      (10 pts) Assume the following declarations:

float f1 = 23.3;

float f2 = 1.0;

double d1 = 3.1;

int i1 = 5;

int i2 = 10;

int i3 = 7;

short s1 = 11;

short s2 = 5;

char c1 = ‘0’;

 

What is the result of the following expressions?  Express your answers as <value, type>.

(a)    i3 / i2 + i1 * i3   (b) f1 / i2 + d1   (c) s1 / i3   (d) i2 + i3 + 3.0

 

4.      (10 pts) Write C++ expressions that are equivalent to the following mathematical formula.

(a)    a + b/c + d  (b) 1 / (1 + x2)  (c) 4/3 * π * r2  (d) (a + b)(c + d)(e + f)

 

5.      (15 pts) Write a program that prompts for and reads a distance in kilometers and outputs the distance in miles.

 

6.      (20 pts) Write a program that prompts for and reads a floating-point number and evaluates the polynomial 3x2 – 10x3 + 13.  The program should display both the number read and the result of evaluating the polynomial.

 

7.      (20 pts) Write a program that prompts for and reads a persons age in years and outputs your age in days.  You may assume that there are 365 days in a year.

 

Homework 3 (Chapter 3):

1.    (10 pts) For the following expressions, give the final values of the objects Cost and Price.  The objects of interest are:

int Cost = 5;

int Price = 10;

(a)    ++Cost;  (b) Cost++;  (c) Cost = Price ++;  (d) Cost = ++Price;  (e) Cost = Price++ + ++ Price;  (f) Cost += Price;  (g) Cost *= 5;  (h) Cost += Price * 5;  (i) ++Cost++;  (j) Cost = ++Price++;  (k) Price /= Cost++;

Note: two expressions are illegal.

 

 2.  (20 pts) Problem 3.12 on page 147 in textbook. (Note: iai, i9i, and i0i should be ‘a’, ‘9’, and ‘0’)

              3.  (20 pts) Problem 3.13 on page 148 in textbook. (Note: iai, ibi, and ici should be ‘a’, ‘b’, and ‘c’)

              4.  (20 pts) Problem 3.14 on page 148 in textbook. (Note: iAi should be ‘A’)

              5.  (10 pts) Problem 3.15 on page 149 in textbook.

              6.  (20 pts) Problem 3.16 on page 149 in textbook.

 

Homework 4 (Chapter 4 conditional):

1.      (10 pts) Problem 4.1 on page 222 in textbook.

2.      (10 pts) Problem 4.2 on page 222 in textbook.

3.      (10 pts) Problem 4.3 on page 223 in textbook.

4.      (15 pts) Problem 4.10 on page 223 in textbook.

5.      (15 pts) Problem 4.12 on page 224 in textbook.

6.      (20 pts) Problem 4.19 on page 225 in textbook.

7.      (20 pts) Problem 4.33 on page 227 in textbook.


Homework 5 (Chapter 4 iterative):

1.      (20 pts) Problem 4.28 on page 226 in textbook.

2.      (20 pts) Problem 4.32 on page 226 in textbook.

3.      (20 pts) Problem 4.37 on page 227 in textbook.

4.      (20 pts) Problem 4.55 on page 230 in textbook.

5.      (20 pts) Problem 4.58 on page 230 in textbook.

 

Homework 6 (Chapter 5):

1.      (20 pts) Problems 5.9, 5.10, 5.11, 5.12, 5.13, 5.14, 5.15, 5.16, 5.17 on page 276 in textbook.

2.      (20 pts) Problem 5.24 on page 276 in textbook.

3.      (20 pts) Problem 5.25 on page 277 in textbook.

4.      (20 pts) Problem 5.26 on page 277 in textbook.

5.      (20 pts) Problem 5.32 on page 277 in textbook.

 

Homework 7 (Chapter 6):

1.      (10 pts) Problem 6.2 on page 345 in textbook.

2.      (10 pts) Problem 6.12 on page 345 in textbook.

3.      (20 pts) Problem 6.20 on page 346 in textbook.

4.      (20 pts) Problem 6.22 on page 347 in textbook.

5.      (20 pts) Problem 6.26 on page 348 in textbook.

6.      (20 pts) Problem 6.46 on page 351 in textbook.

 

Homework 8 (Chapter 7):

1.  To be added later.