QUESTION #1
The questions are based on the following scenario:
A causes B or C, but not both.
F occurs only if B occurs.
D occurs if B or C occurs.
E occurs only if C occurs.
J occurs only if E or F occurs.
D causes G, H, or both.
H occurs if E occurs.
G occurs if F occurs.
1. Answer the following questions. Watch the wording closely, and be careful about assumptions. Be sure to write down anything that may seem applicable:
a. If A occurs, which may occur?
b. If B occurs, which must occur?
c. If J occurs, which must have occurred?
d. Which may occur as a result of a cause not mentioned?
2. Write a program in C that utilizes the scenario logic to graphically (ASCII characters) depict the stated scenario. This program should take character(s) from the command line as input. Remember to write the most optimal code possible.
QUESTION #2
1. Write optimized C programs that will do the following:
a. Convert a base 16 number to its base 10 equivalent. Use 23DA as a test number.
b. Convert a base 8 number to its decimal equivalent. Use 7025 as a test number
c. How many integers from 1 to 1000 are not divisible by 8 or 12?
d. How many integers from 1 to 1000 are divisible by 6 or 8?
2. Explain why did you optimize your code this way.
QUESTION #3
1. Considering compacting memory while managing equal-sized blocks. Assume each block consists of a data field and a pointer field, and that we have marked every block currently in use. The blocks are currently located between memory locations a and b. We wish to relocate all active blocks so that they occupy contiguous memory starting at a. In relocating a block remember that the pointer field of any block pointing to the relocated block must be updated. Design an optimized C program for compacting the blocks.
QUESTION #4
1. Write a program in C to multiply two linear matrices. This program should take as input the dimensions of each matrix, as well as the components of each matrix. Remember to write the most optimal code possible. Use the following matrices as a test:
1 0
-2 3 0 6 1
5 4 3 8 -2
0 1
QUESTION #5
1. Assume that your CPU does not have multiply and divide units. You can not use function in C that will not use multiply, divide and modulo operators. Write the following programs:
a) multiply any given number by 7
b) divide any given number by 7
2. Make sure that you write the most optimized code, and give full description of any potential errors that can happen using your function.