Added A3 code and updated link in README.
This commit is contained in:
parent
256eedb1db
commit
7312bdabf9
32
Codes/Group A/Assignment-A3/A3.c
Normal file
32
Codes/Group A/Assignment-A3/A3.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "A3.h"
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_A3_add(JNIEnv *env, jobject obj, jint a, jint b) {
|
||||||
|
jint result = a + b;
|
||||||
|
printf("\n%d + %d = %d\n", a, b, result);
|
||||||
|
return result; // Return the result
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_A3_sub(JNIEnv *env, jobject obj, jint a, jint b) {
|
||||||
|
jint result = a - b;
|
||||||
|
printf("\n%d - %d = %d\n", a, b, result);
|
||||||
|
return result; // Return the result
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_A3_mult(JNIEnv *env, jobject obj, jint a, jint b) {
|
||||||
|
jint result = a * b;
|
||||||
|
printf("\n%d * %d = %d\n", a, b, result);
|
||||||
|
return result; // Return the result
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_A3_div(JNIEnv *env, jobject obj, jint a, jint b) {
|
||||||
|
if (b == 0) {
|
||||||
|
printf("Error: Division by zero.\n");
|
||||||
|
return 0; // Return 0 or handle error appropriately
|
||||||
|
}
|
||||||
|
jint result = a / b;
|
||||||
|
printf("\n%d / %d = %d\n", a, b, result);
|
||||||
|
return result; // Return the result
|
||||||
|
}
|
||||||
|
|
45
Codes/Group A/Assignment-A3/A3.java
Normal file
45
Codes/Group A/Assignment-A3/A3.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
class A3 {
|
||||||
|
static {
|
||||||
|
System.loadLibrary("A3");
|
||||||
|
}
|
||||||
|
|
||||||
|
private native int add(int a, int b);
|
||||||
|
private native int sub(int a, int b);
|
||||||
|
private native int mult(int a, int b);
|
||||||
|
private native int div(int a, int b);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int a, b, ch;
|
||||||
|
|
||||||
|
System.out.println("\nEnter value of a : ");
|
||||||
|
a = sc.nextInt();
|
||||||
|
System.out.println("\nEnter value of b : ");
|
||||||
|
b = sc.nextInt();
|
||||||
|
|
||||||
|
do {
|
||||||
|
System.out.println("\nENTER YOUR CHOICE : ");
|
||||||
|
ch = sc.nextInt();
|
||||||
|
switch (ch) {
|
||||||
|
case 1:
|
||||||
|
new A3().add(a, b);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
new A3().sub(a, b);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
new A3().mult(a, b);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
new A3().div(a, b);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Your choice is wrong.");
|
||||||
|
}
|
||||||
|
} while (ch < 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
36
Codes/Group A/Assignment-A3/README.md
Normal file
36
Codes/Group A/Assignment-A3/README.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
## Steps to run this code
|
||||||
|
|
||||||
|
These are the steps to run code for Assignment-A3.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> I've tested this on Linux, thus I've included instructions for the same.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
1. open-jdk (version 11 or higher)
|
||||||
|
2. gcc
|
||||||
|
3. Common sense
|
||||||
|
|
||||||
|
### Steps
|
||||||
|
|
||||||
|
1. Compile `A3.java`:
|
||||||
|
```shell
|
||||||
|
javac A3.java
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Generate header file:
|
||||||
|
```shell
|
||||||
|
javac -h . A3.java
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Compile C code:
|
||||||
|
```shell
|
||||||
|
gcc -shared -o libA3.so -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" A3.c
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Run program:
|
||||||
|
```shell
|
||||||
|
java -Djava.library.path=. A3
|
||||||
|
```
|
@ -12,6 +12,7 @@ This repository serves as a comprehensive resource for the Systems Programming a
|
|||||||
- [Code](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A1/Code-A1.py)
|
- [Code](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A1/Code-A1.py)
|
||||||
- [Source file](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A1/source.txt)
|
- [Source file](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A1/source.txt)
|
||||||
2. [Code-A2 - Pass 1 and Pass 2 of 2-Pass Macroprocessor](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Code-A2.py)
|
2. [Code-A2 - Pass 1 and Pass 2 of 2-Pass Macroprocessor](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Code-A2.py)
|
||||||
|
3. [Code-A3 - DLL](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A3/)
|
||||||
|
|
||||||
##### Group B
|
##### Group B
|
||||||
5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205)
|
5. [CPU Scheduling Algorithms: FCFS, SJF (Preemptive), Priority (Non-Preemptive) and Round Robin (Preemptive)](https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20B/Assignment%20-%205)
|
||||||
|
Loading…
Reference in New Issue
Block a user