0% found this document useful (0 votes)
25 views9 pages

Shane Graded Work

The document outlines various programming paradigms including Declarative, Logic, Concurrent, Reactive, and Dataflow programming, along with their examples. It also explains the translation of high-level programming languages into machine code using tools such as Assemblers, Compilers, Virtual Machines, and Interpreters. Additionally, it includes C programming tasks demonstrating basic operations, selection, and iteration.

Uploaded by

shamarasharpe48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Shane Graded Work

The document outlines various programming paradigms including Declarative, Logic, Concurrent, Reactive, and Dataflow programming, along with their examples. It also explains the translation of high-level programming languages into machine code using tools such as Assemblers, Compilers, Virtual Machines, and Interpreters. Additionally, it includes C programming tasks demonstrating basic operations, selection, and iteration.

Uploaded by

shamarasharpe48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Name: Shane Cunningham

Date: February 5 202

Subject: Computer Science- CAPE

Graded Work

Task:

1)

a) Declarative Programming

Declarative programming focuses on describing what the program should accomplish rather
than how to do it. It often eliminates the need for explicit control flow.

 Example: SQL (for database queries) and Prolog (for logic programming).

b) Logic Programming

Logic programming is based on formal logic. Instead of writing sequences of instructions, the
programmer defines facts and rules, and the system derives conclusions from them.

 Example: Prolog, Datalog.

c) Concurrent Programming

This paradigm focuses on executing multiple computations simultaneously, often to improve


performance or responsiveness.

 Example: Erlang, Go (using Goroutines).

d) Reactive Programming

Reactive programming is designed to handle asynchronous data streams and event-driven


programming. It is commonly used in real-time applications.

 Example: RxJava, ReactiveX.

e) Dataflow Programming

In this paradigm, programs are represented as a network of data flowing between operations.
It is widely used in parallel computing and stream processing.

 Example: LabVIEW, TensorFlow (for AI models).


2)

High-level programming languages need to be translated into machine code before execution.
Different tools help in this process:

a) Assemblers

Assemblers convert assembly language (a low-level representation of machine code) into


machine code (binary instructions). Assembly is closely tied to the processor architecture.

 Example: NASM (Netwide Assembler) for x86 processors.

b) Compilers

Compilers translate the entire source code of a high-level programming language into
machine code or an intermediate language before execution. The generated code is often
optimized for performance.

 Example:
o C Compiler (GCC, Clang) → Compiles C code into machine code.
o Java Compiler (javac) → Translates Java source code into bytecode.

c) Virtual Machines (VMs)

Virtual Machines provide an abstraction layer between the compiled program and the
underlying hardware. They execute an intermediate representation of code, allowing
portability across different systems.

 Example:
o Java Virtual Machine (JVM) → Runs Java bytecode.
o Python Virtual Machine (PVM) → Executes Python bytecode.

d) Interpreters

Interpreters translate and execute code line by line, without producing a separate executable
file. This makes debugging easier but often results in slower execution compared to compiled
programs.

 Example:
o Python Interpreter (CPython) → Executes Python scripts.
o JavaScript Engine (V8, SpiderMonkey) → Executes JavaScript in browsers.

3)

1- Sequence Classwork

Tasks 1
#include <stdio.h>

int main() {

float num1, num2;

float sum, difference, product, quotient;

printf("Enter two numbers: ");

scanf("%f %f", &num1, &num2);

sum = num1 + num2;

difference = num1 - num2;

product = num1 * num2;

quotient = num2 != 0 ? num1 / num2 : 0;

printf("Addition: %.2f\n", sum);

printf("Subtraction: %.2f\n", difference);

printf("Multiplication: %.2f\n", product);

if (num2 != 0) {

printf("Division: %.2f\n", quotient);

} else {

printf("Division: Undefined (division by zero)\n");

return 0;
}

Task 2

#include <stdio.h>

int main() {

float length, width, area;

printf("Enter the length of the rectangle: ");

scanf("%f", &length);

printf("Enter the width of the rectangle: ");

scanf("%f", &width);

area = length * width;

printf("The area of the rectangle is: %.2f\n", area);

return 0;

2- Selection

Task 1

#include <stdio.h>
int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

if (number % 2 == 0) {

printf("The number is even.\n");

} else {

printf("The number is odd.\n");

return 0;

Tasks 2

#include <stdio.h>

int main() {

int score;

char grade;

printf("Enter the student's score: ");

scanf("%d", &score);

if (score >= 90) {


grade = 'A';

} else if (score >= 80) {

grade = 'B';

} else if (score >= 70) {

grade = 'C';

} else if (score >= 60) {

grade = 'D';

} else {

grade = 'F';

printf("The grade is: %c\n", grade);

return 0;

Task 3

#include <stdio.h>

int main() {

int age;

printf("Enter age: ");

scanf("%d", &age);

if (age >= 0 && age <= 12) {


printf("Child\n");

} else if (age >= 13 && age <= 19) {

printf("Teenager\n");

} else if (age >= 20 && age <= 64) {

printf("Adult\n");

} else if (age >= 65) {

printf("Senior\n");

} else {

printf("Invalid age\n");

return 0;

3- Iteration

Task 1

#include <stdio.h>

int main() {

for (int i = 1; i <= 10; i++) {

printf("%d\n", i);

return 0;

Task 2
```c

#include <stdio.h>

int main() {

int number, sum = 0;

printf("Enter a number: ");

scanf("%d", &number);

for (int i = 1; i <= number; i++) {

sum += i;

printf("Sum of numbers from 1 to %d is %d\n", number, sum);

return 0;

Task 3

```c

#include <stdio.h>

int main() {

int num;

printf("Enter a number: ");


scanf("%d", &num);

printf("Multiplication Table for %d:\n", num);

for (int i = 1; i <= 10; i++) {

printf("%d * %d = %d\n", num, i, num * i);

return 0;

You might also like