Test 1
Test 1
a). Discuss the significance of C as a foundational language in systems programming and its
influence on the development of other languages.
Speed: C code compiles directly with the hardware resulting in fast execution. This makes it
ideal for critical applications performance like operating systems and embedded systems.
Grammar and Core Concepts: Languages like C++, Java, and Python, adopted aspects of
C's grammar and core programming concepts. This makes it easier for programmers familiar
with C to learn these languages.
Foundation for Interpreters and Compilers: C is often used to develop interpreters and
compilers for other languages. This highlights its efficiency and ability to interact directly
with the underlying hardware.
Briefly compare C with Python in terms of performance and application domains. (5 marks)
C is faster than python due to its direct access of memory and low-level control.
Python has more libraries like NumPy that improve numerical computing speed than doing it
on C.
Application Domain
Python: Web development, Data science and machine learning, prototyping and rapid
development.
b). Explain the concepts of compiled languages and the role of the C compiler in translating
source code into machine-executable instructions. (5 marks)
Compiled language is written in a human-readable format with a specific grammar for the
language and its not directly understood by the computer's processor it needs to be translated
into machine code, which is a set of instructions specific to the computer's architecture.
C compiler acts as a translator between C source code and machine code and it works in
multiple stages such as preprocessing, compilation, assembly, linking. Its roles are Syntax
Checking, Memory Management, Optimization, Machine Code Generation.
2. Problem Analysis and Requirements (10 marks)
a). Describe the steps involved in analyzing a programming problem, including identifying
inputs, outputs, and the core logic required for a solution. (3 marks)
1. Identify Inputs.
2. Identify Outputs.
3. Break Down the Logic.
4. Identify Constraints.
b). Imagine you are developing a C program to control a traffic light system at a busy
intersection in Kampala. Outline the key requirements for such a program, considering
factors like timing, safety, and responsiveness to traffic conditions. (7 marks)
a). In C, explain the difference between statically typed and dynamically typed variables.
Provide an example to illustrate this difference. (5 marks)
b). What are pointers in C, and why are they considered a powerful but potentially dangerous
feature? Discuss their role in memory management and data manipulation. (5 marks)
a. Design a flowchart for a C program that calculates the electricity bill for a household. The
program should:
* Apply a tiered tariff structure (different rates for different consumption levels)
b). Explain the concept of selection (conditional statements) in programming. How are
different types of selection represented in flowcharts? (5 marks)
a). Write a C program to implement the electricity bill calculation described in the flowchart
above. (15 marks)
b). In your program, demonstrate the use of: (20 marks total)
c). Discuss the importance of code readability and maintainability. How can you apply good
coding practices in your C program to achieve these goals? (Optional, for bonus points)