uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit f9a49e6b1d429b688ee4d4b9532ca19607c7eee0
parent 76710e93644a955933553db585b6a3e34dd3938e
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu, 16 Jan 2020 22:03:31 +0200

fixed files

Diffstat:
Massignment-1.5-arrays-pointers-files/combinations/src/combinations.c | 4++--
Massignment-1.5-arrays-pointers-files/fcombinations/Makefile | 2+-
Aassignment-1.5-arrays-pointers-files/fcombinations/bin/fcombs | 0
Aassignment-1.5-arrays-pointers-files/fcombinations/include/arrhandler.h | 28++++++++++++++++++++++++++++
Rassignment-1.5-arrays-pointers-files/fcombinations/include/combinations.h -> assignment-1.5-arrays-pointers-files/fcombinations/include/fcombinations.h | 0
Aassignment-1.5-arrays-pointers-files/fcombinations/obj/arrhandler.o | 0
Aassignment-1.5-arrays-pointers-files/fcombinations/obj/fcombinations.o | 0
Aassignment-1.5-arrays-pointers-files/fcombinations/obj/main.o | 0
Aassignment-1.5-arrays-pointers-files/fcombinations/src/arrhandler.c | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dassignment-1.5-arrays-pointers-files/fcombinations/src/combinations.c | 244-------------------------------------------------------------------------------
Aassignment-1.5-arrays-pointers-files/fcombinations/src/fcombinations.c | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Massignment-1.5-arrays-pointers-files/fcombinations/src/main.c | 3++-
12 files changed, 286 insertions(+), 248 deletions(-)

diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c @@ -29,7 +29,7 @@ void x_pair(int *x1, int *x2) scanf("%d", x1); printf("x2: "); scanf("%d", x2); - } while (*x1 < 0 || *x1 > *x2 || *x2 > 6); // 0 ≤ Χ1 ≤ Χ2 ≤ 6 + } while (*x1 < 0 || *x1 > *x2 || *x2 > 6); } @@ -41,7 +41,7 @@ void y_pair(int *y1, int *y2) scanf("%d", y1); printf("y2: "); scanf("%d", y2); - } while (*y1 < 21 || *y1 > *y2 || *y2 > 279); // 21 ≤ Υ1 ≤ Υ2 ≤ 279 + } while (*y1 < 21 || *y1 > *y2 || *y2 > 279); } diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/Makefile b/assignment-1.5-arrays-pointers-files/fcombinations/Makefile @@ -30,7 +30,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ run: - ./$(BIN_DIR)/$(TARGET) + ./$(BIN_DIR)/$(TARGET) ${ARGS} clean: $(RM) $(OBJ) $(BIN_DIR)/$(TARGET) \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/bin/fcombs b/assignment-1.5-arrays-pointers-files/fcombinations/bin/fcombs Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/include/arrhandler.h b/assignment-1.5-arrays-pointers-files/fcombinations/include/arrhandler.h @@ -0,0 +1,27 @@ +#ifndef ARRHANDLER_H +#define ARRHANDLER_H + +#include <stdbool.h> + +int *fill_array(int); +bool exists_in_array(int *, int, int); + +void quicksort(int *, int, int); +int partition(int *, int, int); +void swap(int *, int *); +void printarray(int *, int); + +void combinations(int *, int, int, int, int); +int even_calc(int *); +bool belongs_x(int, int, int); +int sum_calc(int *); +bool belongs_y(int, int, int); +int sum_comb_calc(); + +void print(); +int not_printed(); +int not_first_condition(); +int not_second_condition_only(); +int frequency(); + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/include/combinations.h b/assignment-1.5-arrays-pointers-files/fcombinations/include/fcombinations.h diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/obj/arrhandler.o b/assignment-1.5-arrays-pointers-files/fcombinations/obj/arrhandler.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/obj/fcombinations.o b/assignment-1.5-arrays-pointers-files/fcombinations/obj/fcombinations.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/obj/main.o b/assignment-1.5-arrays-pointers-files/fcombinations/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/arrhandler.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/arrhandler.c @@ -0,0 +1,161 @@ +#include <stdio.h> +#include <stdlib.h> +#include "arrhandler.h" +//#include "ccolors.h" + +#define COMBSN 6 + + +int *fill_array(int N) +{ + int *arr, num, i = 0; + + arr = (int *)malloc(N * sizeof(int)); + + if (arr == NULL) + { + //set_color(BOLD_RED); + printf("Error! Not enough memory, exiting...\n"); + //set_color(STANDARD); + exit(EXIT_FAILURE); + } + else + { + do + { + printf("arr[%d]: ", i); + scanf("%d", &num); + + if (num >= 1 && num <= 49) + { + if (i == 0) { *(arr + i) = num; i++; } + else + { + if (!exists_in_array(arr, N, num)) { *(arr + i) = num; i++; } + else printf("Give a different number.\n"); + } + } + else printf("Give a number in [1, 49].\n"); + } while (i < N); + } + + return arr; +} + + +bool exists_in_array(int *arr, int N, int num) +{ + int *arrEnd = arr + (N - 1); + while (arr <= arrEnd && *arr != num) arr++; + return (arr <= arrEnd) ? true : false; +} + + +void quicksort(int *arr, int low, int high) +{ + if (low < high) + { + int partIndex = partition(arr, low, high); + quicksort(arr, low, partIndex - 1); + quicksort(arr, partIndex + 1, high); + } +} + + +int partition(int *arr, int low, int high) +{ + int pivot = *(arr + high); + int i = (low - 1), j; + + for (j = low; j <= high - 1; j++) + if (*(arr + j) < pivot) + swap(arr + ++i, arr + j); + + swap(arr + (i + 1), arr + high); + return (i + 1); +} + + +void swap(int *a, int *b) +{ + int temp = *a; + *a = *b; + *b = temp; +} + + +void printarray(int *arr, int N) +{ + for (int i = 0; i < N; i++) + printf("arr[%d] = %d\n", i, *(arr + i)); +} + +int even_calc(int *arr) +{ + +} + + +bool belongs_x(int numEven, int x1, int x2) +{ + +} + + +int sum_calc(int *arr) +{ + +} + + +bool belongs_y(int sumNums, int y1, int y2) +{ + +} + + +void print_combs(int *arr) +{ + int i; + + for (i = 0; i < COMBSN; i++) + printf("%d ", *(arr + i)); + printf("\n"); +} + + +void print(int N) +{ + +} + + + +int sum_comb_calc() +{ + +} + + +int not_printed() +{ + +} + + +int not_first_condition() +{ + +} + + +int not_second_condition_only() +{ + +} + + +int frequency() +{ + +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/combinations.c @@ -1,243 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <string.h> -#include "combinations.h" -#include "ccolors.h" - -#define COMBSN 6 - - -void read_file(char **argv) -{ - FILE *dataFile = fopen(argv[1], "r"); - - if (dataFile == NULL) - { - set_color(BOLD_RED); - printf("Error opening the file, exiting...\n"); - set_color(STANDARD); - exit(EXIT_FAILURE); - } - else - { - printf("Cool\n"); - // fscanf(); - } - - fclose(dataFile); -} - - -int get_k(int N) -{ - int K; - - do - { - printf("N (6 < N <= 49): "); - scanf("%d", &K); - } while (K > N || K < 0); - - return K; -} - - -int *fill_array(int N) -{ - int *arr, num, i = 0; - - arr = (int *)malloc(N * sizeof(int)); - - if (arr == NULL) - { - set_color(BOLD_RED); - printf("Error! Not enough memory, exiting...\n"); - set_color(STANDARD); - exit(EXIT_FAILURE); - } - else - { - do - { - printf("arr[%d]: ", i); - scanf("%d", &num); - - if (num >= 1 && num <= 49) - { - if (i == 0) - { - *(arr + i) = num; - i++; - } - else - { - if (!exists_in_array(arr, N, num)) - { - *(arr + i) = num; - i++; - } - else - printf("Give a different number.\n"); - } - } - else - printf("Give a number in [1, 49].\n"); - - } while (i < N); - } - - return arr; -} - - -bool exists_in_array(int *arr, int N, int num) -{ - int *arrEnd = arr + N - 1; - - while (arr <= arrEnd && *arr != num) - arr++; - - if (arr <= arrEnd) - return true; - else - return false; -} - - -int *sort(int *arr) -{ - -} - - -void x_pair(int *x1, int *x2) -{ - do - { - printf("x1: "); - scanf("%d", x1); - printf("x2: "); - scanf("%d", x2); - } while (*x1 < 0 || *x1 > *x2 || *x2 > 6); // 0 ≤ Χ1 ≤ Χ2 ≤ 6 -} - - -void y_pair(int *y1, int *y2) -{ - do - { - printf("y1: "); - scanf("%d", y1); - printf("y2: "); - scanf("%d", y2); - } while (*y1 < 21 || *y1 > *y2 || *y2 > 279); // 21 ≤ Υ1 ≤ Υ2 ≤ 279 -} - - -void combinations(int *arr, int x1, int x2, int y1, int y2) -{ - int i, j, temp; - - for (i = 1; i <= COMBSN; i++) - { - for (j = 0; j < COMBSN-1; j++) - { - temp = *(arr + j); - *(arr + j) = *(arr + j + 1); - *(arr + j + 1) = temp; - } - } -} - - -int even_calc(int *arr) -{ - -} - - -bool belongs_x(int numEven, int x1, int x2) -{ - -} - - -int sum_calc(int *arr) -{ - -} - - -bool belongs_y(int sumNums, int y1, int y2) -{ - -} - - -void print_combs(int *arr) -{ - int i; - - for (i = 0; i < COMBSN; i++) - printf("%d ", *(arr + i)); - printf("\n"); -} - - -void print(int N) -{ - -} - - - -int combinations_count(int N) -{ - int numCombinations; - - numCombinations = factorial(N) / (factorial(COMBSN) * factorial(N - COMBSN)); - - return numCombinations; -} - - -int factorial(int num) -{ - int i, fac; - - for (i = 1, fac = 1; i <= num; i++) - fac *= i; - - return fac; -} - - -int sum_comb_calc() -{ - -} - - -int not_printed() -{ - -} - - -int not_first_condition() -{ - -} - - -int not_second_condition_only() -{ - -} - - -int frequency() -{ - -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/fcombinations.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/fcombinations.c @@ -0,0 +1,90 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> +#include "fcombinations.h" +#include "ccolors.h" + +#define COMBSN 6 + + +void read_file(char **argv) +{ + FILE *dataFile = fopen(argv[1], "r"); + + if (dataFile == NULL) + { + set_color(BOLD_RED); + printf("Error opening the file, exiting...\n"); + set_color(STANDARD); + exit(EXIT_FAILURE); + } + else + { + printf("Cool\n"); + // fscanf(); + } + + fclose(dataFile); +} + + +void x_pair(int *x1, int *x2) +{ + do + { + printf("x1: "); + scanf("%d", x1); + printf("x2: "); + scanf("%d", x2); + } while (*x1 < 0 || *x1 > *x2 || *x2 > 6); +} + + +void y_pair(int *y1, int *y2) +{ + do + { + printf("y1: "); + scanf("%d", y1); + printf("y2: "); + scanf("%d", y2); + } while (*y1 < 21 || *y1 > *y2 || *y2 > 279); +} + + +void combinations(int *arr, int x1, int x2, int y1, int y2) +{ + int i, j, temp; + + for (i = 1; i <= COMBSN; i++) + { + for (j = 0; j < COMBSN-1; j++) + { + temp = *(arr + j); + *(arr + j) = *(arr + j + 1); + *(arr + j + 1) = temp; + } + } +} + + +int combinations_count(int N) +{ + int numCombinations; + + numCombinations = factorial(N) / (factorial(COMBSN) * factorial(N - COMBSN)); + + return numCombinations; +} + + +int factorial(int num) +{ + int i, fac; + + for (i = 1, fac = 1; i <= num; i++) + fac *= i; + + return fac; +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/main.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/main.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> -#include "combinations.h" +#include "fcombinations.h" +#include "arrhandler.h" int main(int argc, char **argv)