commit cce0228b4f5561ae11b06e8abc1bd530cf23ac2a
parent a8b94c811e9242936c187a2a0dacd311ad889fa5
Author: Christos Margiolis <christos@margiolis.net>
Date: Sat, 17 Apr 2021 02:07:57 +0300
foo
Diffstat:
22 files changed, 682 insertions(+), 392 deletions(-)
diff --git a/c-os2/ex1/ex1.c b/c-os2/ex1/ex1.c
@@ -10,40 +10,40 @@
int
main(int argc, char *argv[])
{
- pid_t pid1, pid2, pid3, pid4, pid5;
+ pid_t pid1, pid2, pid3, pid4, pid5;
- /*
- * Το παρακάτω πρόγραμμα παράγει 7 διεργασίες. Το παρακάτω διάγραμμα
- * περιγράφει την συγγένεια μεταξύ των διεργασιών που δημιουργήθηκαν.
- *
- * P0
- * / | \
- * P2 P1 P3
- * / |
- * P3 P4
- * |
- * P5
- *
- * Πιο αναλυτικά, το πρόγραμμα λειτουργεί ως εξής:
- * - pid1 = fork(): δημιουργείται από την αρχική διεργασία ένα
- * child.
- * - Αν βρισκόμαστε στον πατέρα, τότε
- * - pid2 = fork();
- * - pid3 = fork();
- * Δηλαδή δημιουργούμε άλλες 3 διεργασίες.
- * - Αν βρισκόμαστε στο παιδί, δημιουργούμε άλλη μία διεργασία
- * με την pid4 = fork().
- * - Το παιδί που δημιουργεί η παραπάνω διεργασία, παράγει άλλη
- * μία διεργασία με την pid5 = fork().
- */
+ /*
+ * Το παρακάτω πρόγραμμα παράγει 7 διεργασίες. Το παρακάτω διάγραμμα
+ * περιγράφει την συγγένεια μεταξύ των διεργασιών που δημιουργήθηκαν.
+ *
+ * P0
+ * / | \
+ * P2 P1 P3
+ * / |
+ * P3 P4
+ * |
+ * P5
+ *
+ * Πιο αναλυτικά, το πρόγραμμα λειτουργεί ως εξής:
+ * - pid1 = fork(): δημιουργείται από την αρχική διεργασία ένα
+ * child.
+ * - Αν βρισκόμαστε στον πατέρα, τότε
+ * - pid2 = fork();
+ * - pid3 = fork();
+ * Δηλαδή δημιουργούμε άλλες 3 διεργασίες.
+ * - Αν βρισκόμαστε στο παιδί, δημιουργούμε άλλη μία διεργασία
+ * με την pid4 = fork().
+ * - Το παιδί που δημιουργεί η παραπάνω διεργασία, παράγει άλλη
+ * μία διεργασία με την pid5 = fork().
+ */
- if ((pid1 = fork()) != 0) {
- pid2 = fork();
- pid3 = fork();
- } else {
- if ((pid4 = fork()) == 0)
- pid5 = fork();
- }
+ if ((pid1 = fork()) != 0) {
+ pid2 = fork();
+ pid3 = fork();
+ } else {
+ if ((pid4 = fork()) == 0)
+ pid5 = fork();
+ }
- return 0;
+ return 0;
}
diff --git a/c-os2/ex1/ex2.c b/c-os2/ex1/ex2.c
@@ -12,7 +12,7 @@
* Τρόπος μεταγλώττισης: `cc ex2.c -o ex2`
*/
-static char *argv0;
+static char *argv0; /* Program name */
/*
* Print a process' info. `n` indicates which process is being
@@ -21,83 +21,89 @@ static char *argv0;
static void
printproc(int n)
{
- printf("p: %d\tpid: %d\tppid: %d\n", n, getpid(), getppid());
+ printf("p: %d\tpid: %d\tppid: %d\n", n, getpid(), getppid());
}
+/* Die. */
static void
die(const char *str)
{
- fprintf(stderr, "%s: ", argv0);
- perror(str);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "%s: ", argv0);
+ perror(str);
+ exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
- char buf[32]; /* message buffer */
- int fd[2]; /* pipe(2) file descriptors */
- int n; /* bytes returned from read(2) */
- int i = 3; /* P2 will create 3 child procs */
+ char buf[32]; /* Message buffer */
+ int fd[2]; /* Pipe(2) file descriptors */
+ int n; /* Bytes returned from read(2) */
+ int i = 3; /* P2 will create 3 child procs */
- argv0 = *argv;
+ argv0 = *argv;
- /* create pipe */
- if (pipe(fd) < 0)
- die("pipe");
+ /* Create pipe */
+ if (pipe(fd) < 0)
+ die("pipe");
- printproc(0);
+ printproc(0);
- /* create P1 */
- switch (fork()) {
- case -1:
- die("fork");
- case 0:
- printproc(1);
- (void)strcpy(buf, "Hello from your first child\n");
- /* close read fd and send message to P0 */
- (void)close(fd[0]);
- if (write(fd[1], buf, sizeof(buf)) != sizeof(buf))
- die("write");
- exit(EXIT_SUCCESS);
- default:
- /* close write fd and receive message from P1 */
- (void)close(fd[1]);
- if ((n = read(fd[0], buf, sizeof(buf))) != sizeof(buf))
- die("read");
- if (write(STDOUT_FILENO, buf, n) != n)
- die("write");
- if (wait(NULL) == -1)
- die("wait");
- /* create P2 */
- switch (fork()) {
- case -1:
- die("fork");
- case 0:
- printproc(2);
- /* create P3, P4 and P5 */
- while (i--) {
- switch (fork()) {
- case -1:
- die("fork");
- case 0:
- printproc(2 + i + 1);
- exit(EXIT_SUCCESS);
- default:
- /* wait for all children to exit first */
- if (wait(NULL) == -1)
- die("wait");
- }
- }
- exit(EXIT_SUCCESS);
- default:
- /* wait for P2 to exit */
- if (wait(NULL) == -1)
- die("wait");
- }
- if (execl("/bin/ps", "ps", NULL) == -1)
- die("execl");
- }
+ /* Create P1 */
+ switch (fork()) {
+ case -1:
+ die("fork");
+ case 0:
+ printproc(1);
+ (void)strcpy(buf, "Hello from your first child\n");
+ /* Close the read fd and send message to P0 */
+ (void)close(fd[0]);
+ if (write(fd[1], buf, sizeof(buf)) != sizeof(buf))
+ die("write");
+ exit(EXIT_SUCCESS);
+ default:
+ /* Close the write fd and receive message from P1 */
+ (void)close(fd[1]);
+ if ((n = read(fd[0], buf, sizeof(buf))) != sizeof(buf))
+ die("read");
+ /* Print the message to stdout */
+ if (write(STDOUT_FILENO, buf, n) != n)
+ die("write");
+ if (wait(NULL) == -1)
+ die("wait");
+ /* Create P2 */
+ switch (fork()) {
+ case -1:
+ die("fork");
+ case 0:
+ printproc(2);
+ /* create P3, P4 and P5 */
+ while (i--) {
+ switch (fork()) {
+ case -1:
+ die("fork");
+ case 0:
+ printproc(2 + i + 1);
+ exit(EXIT_SUCCESS);
+ default:
+ /* Wait for all children to exit first */
+ if (wait(NULL) == -1)
+ die("wait");
+ }
+ }
+ exit(EXIT_SUCCESS);
+ default:
+ /* wait for P2 to exit */
+ if (wait(NULL) == -1)
+ die("wait");
+ }
+ /*
+ * Finally, the parent process executes ps(1) after
+ * everything else has exited
+ */
+ if (execl("/bin/ps", "ps", NULL) == -1)
+ die("execl");
+ }
- return 0;
+ return 0;
}
diff --git a/c-os2/ex1/ex3.c b/c-os2/ex1/ex3.c
@@ -1,24 +1,34 @@
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
/*
* Εργαστήριο ΛΣ2 (Δ6) / Εργασία 1: Άσκηση 3 / 2020-2021
* Ονοματεπώνυμο: Χρήστος Μαργιώλης
* ΑΜ: 19390133
- * Τρόπος μεταγλώττισης: `cc ex3.c -lpthread -o ex3`
+ * Τρόπος μεταγλώττισης: `cc ex3.c -lpthread -DLLIM=x -DULIM=y -o ex3`
+ * Όπου `x` και `y` το κάτω και πάνω όριο αντίστοιχα.
*/
+/* No globals allowed :-) */
+struct foo {
+ int *sums; /* Sums for each thread */
+ int *arr; /* Global vector */
+ int n; /* `arr`'s length */
+ int ntd; /* Number of threads */
+ int tid; /* Thread ID */
+ pthread_mutex_t mutex; /* Protect critical parts */
+};
+
+/* Function declarations */
static void *calc(void *);
+static void *emalloc(size_t);
static void die(const char *);
-static char *argv0; /* Program name */
-static int *sums; /* Sums for each thread */
-static int *arr; /* Global vector */
-static int n; /* `arr`'s length */
-static int ntd; /* Number of threads */
-static pthread_mutex_t mutex; /* Mutex to prevent race conditions */
+/* Global variable */
+static char *argv0; /* Program name */
/*
* Each thread calculates the sum of the squares of each element in a specified
@@ -27,122 +37,134 @@ static pthread_mutex_t mutex; /* Mutex to prevent race conditions */
* `arr`'s length is a multiple of `ntd`, we can calculate the number of elements
* each thread will compute by doing `n / ntd`.
*
- * For example, `ntd = 2` and `n = 4`, and `arr [1, 2, 3, 4]`.
+ * For example, `ntd = 2` and `n = 4`, and `arr = [1, 2, 3, 4]`.
* Each thread will compute `n / ntd = 2` elements.
*
* Thread 0 will operate in the region:
- * `td * (n / ntd) = 0 * 2 = 0` to
- * `(td + 1) * (n / ntd) - 1 = (0 + 1) * 2 - 1 = 1`
+ * `td * (n / ntd) = 0 * 2 = 0` to
+ * `(td + 1) * (n / ntd) - 1 = (0 + 1) * 2 - 1 = 1`
*
* Thread 1 will operate in the region:
- * `1 * 2 = 2` to `(1 + 1) * 2 - 1 = 3`
+ * `1 * 2 = 2` to `(1 + 1) * 2 - 1 = 3`
*
* So effectively, each thread will be assigned to compute an equal amount of
* elements.
*/
static void *
-calc(void *tid)
+calc(void *foo)
{
- long td;
- int localsum;
- int i;
-
- if (pthread_mutex_lock(&mutex) != 0)
- die("pthread_mutex_lock");
-
- td = (long)tid;
- localsum = 0;
- for (i = td * (n / ntd); i < (td + 1) * (n / ntd); i++) {
- printf("td: %ld | arr[%d]: %d\n", td, i, arr[i]);
- sums[td] += arr[i] * arr[i];
- }
- if (pthread_mutex_unlock(&mutex) != 0)
- die("pthread_mutex_unlock");
-
- return NULL;
+ struct foo *f;
+ int localsum;
+ int tid, n, i;
+
+ f = (struct foo *)foo;
+ tid = f->tid;
+ n = f->n / f->ntd;
+ f->sums[tid] = 0;
+ localsum = 0;
+
+ for (i = tid * n; i < (tid + 1) * n; i++) {
+ localsum += f->arr[i] * f->arr[i];
+ printf("tid: %d\tarr[%d]: %d\n", tid, i, f->arr[i]);
+ }
+ /*
+ * Lock the mutex so that no other thread can write
+ * to f->sums at the same time.
+ */
+ if (pthread_mutex_lock(&f->mutex) != 0)
+ die("pthread_mutex_lock");
+ f->sums[tid] = localsum;
+ if (pthread_mutex_unlock(&f->mutex) != 0)
+ die("pthread_mutex_unlock");
+
+ return NULL;
}
+/* Error checking malloc(2) */
+static void *
+emalloc(size_t nb)
+{
+ void *p;
+
+ if ((p = malloc(nb)) == NULL)
+ die("malloc");
+ return p;
+}
+
+/* Die. */
static void
die(const char *str)
{
- fprintf(stderr, "%s: ", argv0);
- perror(str);
- exit(EXIT_FAILURE);
+ fprintf(stderr, "%s: ", argv0);
+ perror(str);
+ exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
- pthread_t *tds; /* Threads */
- FILE *fp; /* Either stdin or a text file */
- int totalsum; /* Total sum */
- long i; /* Counter */
-
- argv0 = *argv++;
-
- /*
- * If an argument was passed, use it as a file to read from,
- * otherwise read from stdin.
- */
- if (*argv == NULL)
- fp = stdin;
- else if ((fp = fopen(*argv, "r")) == NULL)
- die("fopen");
-
- /*
- * We do error checking for `n` and `ntd` but in case we read from a
- * file the program might break if the data is wrong (i.e fails the
- * error checks at least once) since it will keep going further down
- * into the file. The same doesn't apply for when reading from stdin --
- * we can just give it a new number until it's correct.
- */
- do {
- printf("p: ");
- fscanf(fp, "%d", &ntd);
- /* Cannot have < 0 threads. */
- } while (ntd < 0);
-
- do {
- printf("n: ");
- fscanf(fp, "%d", &n);
- /* Make sure `n` is positive and also a multiple of `ntd`. */
- } while (n < 0 || n % ntd != 0);
-
- if ((tds = malloc(ntd * sizeof(pthread_t))) == NULL)
- die("malloc");
- if ((arr = malloc(n * sizeof(int))) == NULL)
- die("malloc");
- if ((sums = malloc(ntd * sizeof(int))) == NULL)
- die("malloc");
-
- /* Read the vector. */
- for (i = 0; i < n; i++)
- fscanf(fp, "%d", &arr[i]);
- (void)fclose(fp);
-
- if (pthread_mutex_init(&mutex, NULL) != 0)
- die("pthread_mutex_init");
- /*
- * Start multithreading. For each thread we assign `calc`
- * to be the callback function that each thread will call.
- */
- for (i = 0; i < ntd; i++) {
- if (pthread_create(&tds[i], NULL, calc, (void *)i) != 0)
- die("pthread_create");
- if (pthread_join(tds[i], NULL) != 0)
- die("pthread_join");
- }
-
- totalsum = 0;
- while (ntd--)
- totalsum += *sums++;
- printf("total sum: %d\n", totalsum);
-
- free(tds);
- free(arr);
- free(sums);
- (void)pthread_mutex_destroy(&mutex);
- pthread_exit(NULL);
-
- return 0;
+ struct foo *f; /* Each callback will receive this */
+ pthread_t *tds; /* Threads */
+ pthread_t fin; /* Will calculate the total sum */
+ int totalsum; /* What its name says */
+ int i; /* Counter */
+
+ argv0 = *argv;
+ f = emalloc(sizeof(struct foo));
+ /*
+ * We do error checks for `n` and `ntd` but in case we read from a
+ * file the program might break if the data is wrong (i.e fails the
+ * error checks at least once) since it will keep going further down
+ * into the file. The same doesn't apply for when reading from stdin --
+ * we can just give it a new number until it's correct.
+ */
+ do {
+ printf("p: ");
+ scanf("%d", &f->ntd);
+ /* Cannot have < 0 threads. */
+ } while (f->ntd < 0);
+
+ do {
+ printf("n: ");
+ scanf("%d", &f->n);
+ /* Make sure `n` is positive and also a multiple of `ntd`. */
+ } while (f->n < 0 || f->n % f->ntd != 0);
+
+ tds = emalloc(f->ntd * sizeof(pthread_t));
+ f->arr = emalloc(f->n * sizeof(int));
+ f->sums = emalloc(f->ntd * sizeof(int));
+
+ /* Fill the vector. */
+ srand(time(NULL));
+ for (i = 0; i < f->n; i++)
+ f->arr[i] = rand() % (ULIM - LLIM) + LLIM;
+
+ if (pthread_mutex_init(&f->mutex, NULL) != 0)
+ die("pthread_mutex_init");
+ /*
+ * Start multithreading. For each thread we assign `calc`
+ * to be the callback function that each thread will call
+ * and we pass it the `foo` struct as an argument to avoid
+ * declaring globals.
+ */
+ for (i = 0; i < f->ntd; i++) {
+ f->tid = i;
+ if (pthread_create(&tds[i], NULL, calc, (void *)f) != 0)
+ die("pthread_create");
+ if (pthread_join(tds[i], NULL) != 0)
+ die("pthread_join");
+ }
+ totalsum = 0;
+ while (f->ntd--)
+ totalsum += *f->sums++;
+ printf("total sum: %d\n", totalsum);
+
+ (void)pthread_mutex_destroy(&f->mutex);
+ pthread_exit(NULL);
+ free(tds);
+ free(f->arr);
+ free(f->sums);
+ free(f);
+
+ return 0;
}
diff --git a/c-os2/lab3.c b/c-os2/lab3.c
@@ -0,0 +1,14 @@
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+
+ return 0;
+}
diff --git a/java-development/CopyPaste.java b/java-development/CopyPaste.java
@@ -0,0 +1,28 @@
+import java.io.*;
+
+class CopyPaste {
+ public static void main(String args[]) {
+ FileInputStream fis;
+ FileOutputStream fos;
+ int c;
+
+ try {
+ fis = new FileInputStream(args[0]);
+ fos = new FileOutputStream(args[1]);
+
+ while ((c = fis.read()) != -1)
+ fos.write(c);
+ fis.close();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ System.err.println("file not found");
+ return;
+ } catch (IOException e) {
+ System.err.println("IO Exception");
+ return;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.err.println("usage: java CopyPaste src dst");
+ return;
+ }
+ }
+}
diff --git a/java-development/ReadLines.java b/java-development/ReadLines.java
@@ -0,0 +1,32 @@
+import java.io.*;
+
+class ReadLines {
+ public static void main(String args[]) {
+ BufferedReader br;
+ File f;
+ String str;
+ int ln = 0;
+
+ try {
+ f = new File(args[0]);
+ br = new BufferedReader(new FileReader(f));
+
+ while ((str = br.readLine()) != null) {
+ System.out.println(str);
+ ln++;
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ System.err.println("file not found");
+ return;
+ } catch (IOException e) {
+ System.err.println("IO Exception");
+ return;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.err.println("usage: java ReadLines file");
+ return;
+ }
+
+ System.out.println("Lines read: " + ln);
+ }
+}
diff --git a/java-development/csv/Main.java b/java-development/csv/Main.java
@@ -0,0 +1,47 @@
+import java.io.*;
+import java.util.ArrayList;
+
+class Main {
+ public static void main(String[] args) {
+ ArrayList<Movie> movies = new ArrayList<Movie>();
+ BufferedReader br;
+ File f;
+ String fields[] = new String[3];
+ String str;
+ String sortby;
+
+ try {
+ sortby = args[0];
+ f = new File(args[1]);
+ br = new BufferedReader(new FileReader(f));
+
+ while ((str = br.readLine()) != null) {
+ fields = str.split("\\|");
+ movies.add(new Movie(fields[0],
+ Integer.parseInt(fields[1]),
+ Float.parseFloat(fields[2])));
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ System.err.println("file not found");
+ return;
+ } catch (IOException e) {
+ System.err.println("IO Excetion");
+ return;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.err.println("usage: java Main sortby file\n");
+ System.err.println("You can sort by:\n\ttitle\n\tyear\n\tprice");
+ return;
+ }
+
+ if (sortby.equals("title"))
+ movies.sort((o1, o2) -> o1.get_title().compareTo(o2.get_title()));
+ else if (sortby.equals("year"))
+ movies.sort((o1, o2) -> o1.get_year().compareTo(o2.get_year()));
+ else if (sortby.equals("price"))
+ movies.sort((o1, o2) -> o1.get_price().compareTo(o2.get_price()));
+
+ for (Movie m : movies)
+ System.out.println(m);
+ }
+}
diff --git a/java-development/csv/Movie.java b/java-development/csv/Movie.java
@@ -0,0 +1,28 @@
+class Movie {
+ private String title;
+ private Integer year;
+ private Float price;
+
+ Movie(String title, Integer year, Float price) {
+ this.title = title;
+ this.year = year;
+ this.price = price;
+ }
+
+ public String get_title() {
+ return title;
+ }
+
+ public Integer get_year() {
+ return year;
+ }
+
+ public Float get_price() {
+ return price;
+ }
+
+ @Override
+ public String toString () {
+ return String.format("%-20s\t", title) + year + "\t" + price;
+ }
+}
diff --git a/java-development/lol/Main.java b/java-development/rect/Main.java
diff --git a/java-development/lol/Pixel.java b/java-development/rect/Pixel.java
diff --git a/java-development/lol/Point.java b/java-development/rect/Point.java
diff --git a/java-development/lol/Rectangle.java b/java-development/rect/Rectangle.java
diff --git a/octave-signals-systems/ex3/doc.pdf b/octave-signals-systems/ex3/doc.pdf
Binary files differ.
diff --git a/octave-signals-systems/ex3/doc.tex b/octave-signals-systems/ex3/doc.tex
@@ -16,16 +16,16 @@
\begin{document}
\begin{titlepage}
- \maketitle
- \begin{figure}[t!]
- \begin{center}
- \includegraphics[scale=0.3]{./res/uniwalogo.png} \\
- \Large
- \textbf{Πανεπιστήμιο Δυτικής Αττικής} \\
- \large
- Τμήμα Μηχανικών Πληροφορικής και Ηλεκτρονικών Υπολογιστών
- \end{center}
- \end{figure}
+ \maketitle
+ \begin{figure}[t!]
+ \begin{center}
+ \includegraphics[scale=0.3]{./res/uniwalogo.png} \\
+ \Large
+ \textbf{Πανεπιστήμιο Δυτικής Αττικής} \\
+ \large
+ Τμήμα Μηχανικών Πληροφορικής και Ηλεκτρονικών Υπολογιστών
+ \end{center}
+ \end{figure}
\end{titlepage}
\renewcommand{\contentsname}{Περιεχόμενα}
@@ -34,20 +34,20 @@
\section{'Ασκηση 1}
\begin{itemize}
- \item 'Εστω το σήμα ολοκληρωτή που φαίνεται στο παρκάτω
- σχήμα (φυλλάδιο άσκηση σελίδα 12). 'Ενα τέτοιο
- σύστημα δέχεται ως είσοδο ένα σήμα $x(t)$ και η έξοδος
- $y(t)$ δίνεται από την σχέση:
- \[y(t) = \int_{-\infty}^{t} x(τ)dτ\]
- Σας ζητείται να μελετήσετε αυτό το σύστημα και να
- απαντήσετε ως προς τις ιδιότητες:
- \begin{itemize}
- \item Γραμμικό ή μηγραμμικό.
- \item Δυναμικό ή στατικό.
- \item Αιτιατό ή μη αιτιατό.
- \item Χρονικά αμετάβλητο ή χρονικά μεταβαλλόμενο.
- \item Ευσταθές ή ασταθές.
- \end{itemize}
+ \item 'Εστω το σύστημα ολοκληρωτή που φαίνεται στο παρκάτω
+ σχήμα (φυλλάδιο άσκηση σελίδα 12). 'Ενα τέτοιο
+ σύστημα δέχεται ως είσοδο ένα σήμα $x(t)$ και η έξοδος
+ $y(t)$ δίνεται από την σχέση:
+ \[y(t) = \int_{-\infty}^{t} x(τ)dτ\]
+ Σας ζητείται να μελετήσετε αυτό το σύστημα και να
+ απαντήσετε ως προς τις ιδιότητες:
+ \begin{itemize}
+ \item Γραμμικό ή μη γραμμικό.
+ \item Δυναμικό ή στατικό.
+ \item Αιτιατό ή μη αιτιατό.
+ \item Χρονικά αμετάβλητο ή χρονικά μεταβαλλόμενο.
+ \item Ευσταθές ή ασταθές.
+ \end{itemize}
\end{itemize}
<++>
@@ -55,8 +55,8 @@
\section{'Ασκηση 2}
\begin{itemize}
- \item Να εξετάσετε ως προς την ευστάθεια το σύστημα με σχέση
- εισόδου-εξόδου $y(t) = e^{x(t)}$.
+ \item Να εξετάσετε ως προς την ευστάθεια το σύστημα με σχέση
+ εισόδου-εξόδου $y(t) = e^{x(t)}$.
\end{itemize}
<++>
@@ -64,8 +64,8 @@
\section{'Ασκηση 3}
\begin{itemize}
- \item Να εξεταστεί εάν το σύστημα που διέπεται από την σχέση
- εισόδου-εξόδου $y(t) = x(t/4)$ είναι αιτιατό.
+ \item Να εξεταστεί εάν το σύστημα που διέπεται από την σχέση
+ εισόδου-εξόδου $y(t) = x(t/4)$ είναι αιτιατό.
\end{itemize}
<++>
diff --git a/sql-databases/ex1/new_personnel.sql b/sql-databases/ex1/new_personnel.sql
@@ -1,58 +1,132 @@
CREATE TABLE DEPT (
- DEPTNO INT(2) NOT NULL,
- DNAME VARCHAR,
- LOC VARCHAR,
- PRIMARY KEY(DEPTNO)
+ DEPTNO INT(2) NOT NULL,
+ DNAME VARCHAR,
+ LOC VARCHAR,
+ PRIMARY KEY(DEPTNO)
);
CREATE TABLE EMP (
- EMPNO INT(2) NOT NULL,
- ENAME VARCHAR,
- JOB VARCHAR,
- HIERDATE DATE,
- MGR INT(2),
- SAL FLOAT(7,2),
- COMM FLOAT(7,2),
- DEPTNO INT(2) NOT NULL,
- PRIMARY KEY(EMPNO),
- FOREIGN KEY(DEPTNO) REFERENCES DEPT(DEPTNO)
+ EMPNO INT(2) NOT NULL,
+ ENAME VARCHAR,
+ JOB VARCHAR,
+ HIERDATE DATE,
+ MGR INT(2),
+ SAL FLOAT(7,2),
+ COMM FLOAT(7,2),
+ DEPTNO INT(2) NOT NULL,
+ PRIMARY KEY(EMPNO),
+ FOREIGN KEY(DEPTNO) REFERENCES DEPT(DEPTNO)
);
CREATE TABLE PROJ (
- PROJ_CODE INT(3) NOT NULL,
- DESCRIPTION VARCHAR,
- PRIMARY KEY(PROJ_CODE)
+ PROJ_CODE INT(3) NOT NULL,
+ DESCRIPTION VARCHAR,
+ PRIMARY KEY(PROJ_CODE)
);
CREATE TABLE ASSIGN (
- EMPNO INT(2) NOT NULL,
- PROJ_CODE INT(3),
- A_TIME INT(3),
- PRIMARY KEY(EMPNO, PROJ_CODE),
- FOREIGN KEY(EMPNO) REFERENCES EMP(EMPNO),
- FOREIGN KEY(PROJ_CODE) REFERENCES PROJ(PROJ_CODE)
+ EMPNO INT(2) NOT NULL,
+ PROJ_CODE INT(3),
+ A_TIME INT(3),
+ PRIMARY KEY(EMPNO, PROJ_CODE),
+ FOREIGN KEY(EMPNO) REFERENCES EMP(EMPNO),
+ FOREIGN KEY(PROJ_CODE) REFERENCES PROJ(PROJ_CODE)
);
INSERT INTO DEPT VALUES
- (10, 'ACCOUNTING', 'ATHENS'),
- (20, 'SALES', 'LONDON'),
- (30, 'RESEARCH', 'ATHENS'),
- (40, 'PAYROLL', 'LONDON');
+ (10, 'ACCOUNTING', 'ATHENS'),
+ (20, 'SALES', 'LONDON'),
+ (30, 'RESEARCH', 'ATHENS'),
+ (40, 'PAYROLL', 'LONDON');
INSERT INTO EMP VALUES
- (10, 'CODD', 'ANALYST', '1/1/89', 15, 3000, NULL, 10),
- (15, 'ELMASRI', 'ANALYST', '2/5/95', 15, 1200, 150, 10),
- (20, 'NAVATHE', 'SALESMAN', '7/7/77', 20, 2000, NULL, 20),
- (30, 'DATE', 'PROGRAMMER', '4/5/04', 15, 1800, 200, 10);
+ (10, 'CODD', 'ANALYST', '1/1/89', 15, 3000, NULL, 10),
+ (15, 'ELMASRI', 'ANALYST', '2/5/95', 15, 1200, 150, 10),
+ (20, 'NAVATHE', 'SALESMAN', '7/7/77', 20, 2000, NULL, 20),
+ (30, 'DATE', 'PROGRAMMER', '4/5/04', 15, 1800, 200, 10);
INSERT INTO PROJ VALUES
- (100, 'PAYROLL'),
- (200, 'PERSONELL'),
- (300, 'SALES');
+ (100, 'PAYROLL'),
+ (200, 'PERSONELL'),
+ (300, 'SALES');
INSERT INTO ASSIGN VALUES
- (10, 100, 40),
- (10, 200, 60),
- (15, 100, 100),
- (20, 200, 100),
- (30, 100, 100);
+ (10, 100, 40),
+ (10, 200, 60),
+ (15, 100, 100),
+ (20, 200, 100),
+ (30, 100, 100);
+
+/* Using SQLite3 syntax*/
+
+/* .schema -> DESCRIBE */
+.schema
+/* Make output pretty */
+.header on
+.mode column
+/* Show contents of every table */
+SELECT * FROM DEPT;
+SELECT * FROM EMP;
+SELECT * FROM PROJ;
+SELECT * FROM ASSIGN;
+
+
+/*
+ * Output after execution (`sqlite3 -init new_personnel.sql`):
+ *
+ * CREATE TABLE DEPT (
+ * DEPTNO INT(2) NOT NULL,
+ * DNAME VARCHAR,
+ * LOC VARCHAR,
+ * PRIMARY KEY(DEPTNO)
+ * );
+ * CREATE TABLE EMP (
+ * EMPNO INT(2) NOT NULL,
+ * ENAME VARCHAR,
+ * JOB VARCHAR,
+ * HIERDATE DATE,
+ * MGR INT(2),
+ * SAL FLOAT(7,2),
+ * COMM FLOAT(7,2),
+ * DEPTNO INT(2) NOT NULL,
+ * PRIMARY KEY(EMPNO),
+ * FOREIGN KEY(DEPTNO) REFERENCES DEPT(DEPTNO)
+ * );
+ * CREATE TABLE PROJ (
+ * PROJ_CODE INT(3) NOT NULL,
+ * DESCRIPTION VARCHAR,
+ * PRIMARY KEY(PROJ_CODE)
+ * );
+ * CREATE TABLE ASSIGN (
+ * EMPNO INT(2) NOT NULL,
+ * PROJ_CODE INT(3),
+ * A_TIME INT(3),
+ * PRIMARY KEY(EMPNO, PROJ_CODE),
+ * FOREIGN KEY(EMPNO) REFERENCES EMP(EMPNO),
+ * FOREIGN KEY(PROJ_CODE) REFERENCES PROJ(PROJ_CODE)
+ * );
+ * DEPTNO DNAME LOC
+ * ------ ---------- ------
+ * 10 ACCOUNTING ATHENS
+ * 20 SALES LONDON
+ * 30 RESEARCH ATHENS
+ * 40 PAYROLL LONDON
+ * EMPNO ENAME JOB HIERDATE MGR SAL COMM DEPTNO
+ * ----- ------- ---------- -------- --- ------ ----- ------
+ * 10 CODD ANALYST 1/1/89 15 3000.0 10
+ * 15 ELMASRI ANALYST 2/5/95 15 1200.0 150.0 10
+ * 20 NAVATHE SALESMAN 7/7/77 20 2000.0 20
+ * 30 DATE PROGRAMMER 4/5/04 15 1800.0 200.0 10
+ * PROJ_CODE DESCRIPTION
+ * --------- -----------
+ * 100 PAYROLL
+ * 200 PERSONELL
+ * 300 SALES
+ * EMPNO PROJ_CODE A_TIME
+ * ----- --------- ------
+ * 10 100 40
+ * 10 200 60
+ * 15 100 100
+ * 20 200 100
+ * 30 100 100
+ */
diff --git a/vhdl-digital-design/ex2/ff.vhd b/vhdl-digital-design/ex2/ff.vhd
@@ -1,15 +1,15 @@
entity ff is port (
- d: in bit;
- clk: in bit;
- q: out bit
+ d: in bit;
+ clk: in bit;
+ q: out bit
);
end ff;
architecture behav of ff is
begin
- process (clk) begin
- if (clk 'event and clk = '1') then
- q <= d;
- end if;
- end process;
+ process (clk) begin
+ if (clk 'event and clk = '1') then
+ q <= d;
+ end if;
+ end process;
end behav;
diff --git a/vhdl-digital-design/ex2/ff_tb.vhd b/vhdl-digital-design/ex2/ff_tb.vhd
@@ -8,56 +8,46 @@ signal clk1: bit;
signal q1: bit;
component ff is port (
- d: in bit;
- clk: in bit;
- q: out bit
+ d: in bit;
+ clk: in bit;
+ q: out bit
);
end component;
begin
- uut: ff port map (
- d => d1,
- clk => clk1,
- q => q1
- );
-
- process begin
- clk1 <= '1';
- wait for 150 ns;
-
- clk1 <= '0';
- wait for 250 ns;
-
- clk1 <= '1';
- wait for 150 ns;
-
- clk1 <= '0';
- wait for 250 ns;
-
- clk1 <= '1';
- wait for 150 ns;
-
- clk1 <= '0';
- wait for 250 ns;
- end process;
-
- process begin
- d1 <= '1';
- wait for 280 ns;
-
- d1 <= '0';
- wait for 300 ns;
-
- d1 <= '1';
- wait for 250 ns;
-
- d1 <= '0';
- wait for 150 ns;
-
- d1 <= '1';
- wait for 75 ns;
-
- d1 <= '0';
- wait for 150 ns;
- end process;
+ uut: ff port map (
+ d => d1,
+ clk => clk1,
+ q => q1
+ );
+
+ process begin
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ end process;
+
+ process begin
+ d1 <= '1';
+ wait for 280 ns;
+ d1 <= '0';
+ wait for 300 ns;
+ d1 <= '1';
+ wait for 250 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ d1 <= '1';
+ wait for 75 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ end process;
end behav;
diff --git a/vhdl-digital-design/ex2/ffrst.vhd b/vhdl-digital-design/ex2/ffrst.vhd
@@ -1,18 +1,18 @@
entity ffrst is port (
- d: in bit;
- clk: in bit;
- rst: in bit;
- q: out bit
+ d: in bit;
+ clk: in bit;
+ rst: in bit;
+ q: out bit
);
end ffrst;
architecture behav of ffrst is
begin
- process (clk, rst) begin
- if (rst = '0') then
- q <= '0';
- elsif (clk 'event and clk = '1') then
- q <= d;
- end if;
- end process;
+ process (clk, rst) begin
+ if (rst = '0') then
+ q <= '0';
+ elsif (clk 'event and clk = '1') then
+ q <= d;
+ end if;
+ end process;
end behav;
diff --git a/vhdl-digital-design/ex2/ffrst_tb.vhd b/vhdl-digital-design/ex2/ffrst_tb.vhd
@@ -0,0 +1,59 @@
+entity ffrst_tb is
+end ffrst_tb;
+
+architecture behav of ffrst_tb is
+
+signal d1: bit;
+signal clk1: bit;
+signal rst1: bit;
+signal q1: bit;
+
+component ffrst is port (
+ d: in bit;
+ clk: in bit;
+ rst: in bit;
+ q: out bit
+);
+end component;
+
+begin
+ uut: ffrst port map (
+ d => d1,
+ clk => clk1,
+ rst => rst1,
+ q => q1
+ );
+
+ process begin
+ rst1 <= '1';
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ rst1 <= '0'; -- reset now is 0 so q is always 0 now
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ rst1 <= '1';
+ clk1 <= '1';
+ wait for 150 ns;
+ clk1 <= '0';
+ wait for 250 ns;
+ end process;
+
+ process begin
+ d1 <= '1';
+ wait for 280 ns;
+ d1 <= '0';
+ wait for 300 ns;
+ d1 <= '1';
+ wait for 250 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ d1 <= '1';
+ wait for 75 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ end process;
+end behav;
diff --git a/vhdl-digital-design/ex2/latch.vhd b/vhdl-digital-design/ex2/latch.vhd
@@ -1,15 +1,15 @@
entity latch is port (
- d: in bit;
- en: in bit;
- q: out bit
+ d: in bit;
+ en: in bit;
+ q: out bit
);
end latch;
architecture behav of latch is
begin
- process (d, en) begin
- if (en = '1') then
- q <= d;
- end if;
- end process;
+ process (d, en) begin
+ if (en = '1') then
+ q <= d;
+ end if;
+ end process;
end behav;
diff --git a/vhdl-digital-design/ex2/latch_tb b/vhdl-digital-design/ex2/latch_tb
Binary files differ.
diff --git a/vhdl-digital-design/ex2/latch_tb.vhd b/vhdl-digital-design/ex2/latch_tb.vhd
@@ -8,56 +8,46 @@ signal en1: bit;
signal q1: bit;
component latch is port (
- d: in bit;
- en: in bit;
- q: out bit
+ d: in bit;
+ en: in bit;
+ q: out bit
);
end component;
begin
- uut: latch port map (
- d => d1,
- en => en1,
- q => q1
- );
-
- process begin
- en1 <= '1';
- wait for 150 ns;
-
- en1 <= '0';
- wait for 250 ns;
-
- en1 <= '1';
- wait for 150 ns;
-
- en1 <= '0';
- wait for 250 ns;
-
- en1 <= '1';
- wait for 150 ns;
-
- en1 <= '0';
- wait for 250 ns;
- end process;
-
- process begin
- d1 <= '1';
- wait for 280 ns;
-
- d1 <= '0';
- wait for 300 ns;
-
- d1 <= '1';
- wait for 250 ns;
-
- d1 <= '0';
- wait for 150 ns;
-
- d1 <= '1';
- wait for 75 ns;
-
- d1 <= '0';
- wait for 150 ns;
- end process;
+ uut: latch port map (
+ d => d1,
+ en => en1,
+ q => q1
+ );
+
+ process begin
+ en1 <= '1';
+ wait for 150 ns;
+ en1 <= '0';
+ wait for 250 ns;
+ en1 <= '1';
+ wait for 150 ns;
+ en1 <= '0';
+ wait for 250 ns;
+ en1 <= '1';
+ wait for 150 ns;
+ en1 <= '0';
+ wait for 250 ns;
+ end process;
+
+ process begin
+ d1 <= '1';
+ wait for 280 ns;
+ d1 <= '0';
+ wait for 300 ns;
+ d1 <= '1';
+ wait for 250 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ d1 <= '1';
+ wait for 75 ns;
+ d1 <= '0';
+ wait for 150 ns;
+ end process;
end behav;