Skip to content

Commit

Permalink
pre_relese
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Tol3 committed Apr 22, 2024
0 parents commit 4f58146
Show file tree
Hide file tree
Showing 18 changed files with 1,492 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Kate/Fuck_this_lab_im_done",
"program": "c:/Users/Kate/Fuck_this_lab_im_done/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
68 changes: 68 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"stdio.h": "c",
"stdlib.h": "c",
"stddef.h": "c",
"field_info.h": "c",
"complex.h": "c",
"tuple": "c",
"string.h": "c"
}
}
Binary file added a.exe
Binary file not shown.
Binary file added build/Debug/main.o
Binary file not shown.
76 changes: 76 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <string.h>
#include <math.h>
#include "field_info.h"
#include "complex.h"

void complex_sum(const void* v1, const void* v2, void* res){
((Complex*) res)->re = ((Complex*) v1)->re + ((Complex*) v2)->re;
((Complex*) res)->img = ((Complex*) v1)->img + ((Complex*) v2)->img;
}

void complex_mult(const void* v1,const void* v2, void* res){
double re1 = ((Complex*) v1)->re, img1 = ((Complex*) v1)->img, re2 = ((Complex*) v2)->re, img2 = ((Complex*) v2)->img;
((Complex*) res)->re = (re1 * re2) - (img1*img2);
((Complex*) res)->img = re1*img2 + re2*img1;
}

void read_complex_array(const size_t v,const size_t h, void* elems){
Complex *arr;
arr = (Complex*) elems;
printf("type your matrix:\n");
for (size_t i = 0; i < v;i++){
for (size_t j = 0;j < h;j ++){
printf("real: ");
scanf("%lf", &(arr + i*h + j)->re);
printf("img: ");
scanf("%lf", &(arr + i*h + j)->img);
printf("\n");
//printf(" %zu %zu\n", (arr + i*h + j)->re,(arr + i*h + j)->img);
}
}
}

void complex_print(void* el){
Complex* elc = el;
if ((elc->img) > 0){
printf("%.3lf + %.3lfi", elc->re, elc->img);
}
else if (elc->img == 0){
printf("%.3lf + 0i", elc->re);
}
else{
printf("%.3lf - %.3lfi", elc->re, fabs(elc->img));
}

}

void complex_set_zero(void* ptr){
((Complex*) ptr)->re = 0;
((Complex*) ptr)->img = 0;
}

void complex_get_number(void* ptr){
printf("\nre: ");
scanf("%lf", &(((Complex*)ptr)->re));
printf("img: ");
scanf("%lf", &(((Complex*)ptr)->img));
}


static FieldInfo* COMPLEX_FIELD_INFO= NULL;

FieldInfo* get_info_complex(){
if (COMPLEX_FIELD_INFO==NULL){
COMPLEX_FIELD_INFO = (FieldInfo*) malloc(sizeof(FieldInfo)); //!!!!!
COMPLEX_FIELD_INFO->type = "complex";
COMPLEX_FIELD_INFO->el_size = sizeof(Complex);
COMPLEX_FIELD_INFO->sum_el = complex_sum;
COMPLEX_FIELD_INFO->mult_el = complex_mult;
COMPLEX_FIELD_INFO->print_el = complex_print;
COMPLEX_FIELD_INFO->read_array = read_complex_array;
COMPLEX_FIELD_INFO->set_zero = complex_set_zero;
COMPLEX_FIELD_INFO->get_number = complex_get_number;

}
return COMPLEX_FIELD_INFO;
}
9 changes: 9 additions & 0 deletions complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

typedef struct {
double re;
double img;
} Complex ;
25 changes: 25 additions & 0 deletions field_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <stddef.h>

typedef void (*sum_el)(const void* v1,const void* v2, void* res);
typedef void (*mult_el)(const void* v1,const void* v2, void* res);
typedef void (*print_el)(void* el);
typedef void (*read_array)(const size_t v,const size_t h, void* elems);
typedef void (*set_zero)(void* ptr);
typedef void (*get_number)(void* ptr);

typedef struct {
const char* type;
size_t el_size;
sum_el sum_el;
mult_el mult_el;
print_el print_el;
read_array read_array;
set_zero set_zero;
get_number get_number;

} FieldInfo;

FieldInfo* get_info_int();
FieldInfo* get_info_real();
FieldInfo* get_info_complex();
66 changes: 66 additions & 0 deletions int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "field_info.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void int_sum(const void* v1,const void* v2, void* res){
int val;
val = (*((int*) v1) + *((int*) v2));
memcpy(res, &val, sizeof(int));
//free((void*)&val);
}

void int_mult(const void* v1,const void* v2, void* res){
int val;
val = (*((int*) v1) * *((int*) v2));
memcpy(res, &val, sizeof(int));
//free((void*)&val);
}

void read_int_array(const size_t v,const size_t h, void* elems){
int *arr;
arr = (int*)elems;

printf("type your matrix:\n");
for (size_t i = 0; i < v;i++){
for (size_t j = 0;j < h;j ++){
scanf("%d", (arr + i*h + j));

//printf(" %d\n", *(arr + i*h + j));
}
}
}

void int_print(void* el){
printf("%7d", *((int*) el));
}

//static void* INT_ZERO = NULL;

void int_set_zero(void* ptr){
*(int*)ptr = 0;
}

void int_get_number(void* ptr){
scanf("%d", (int*)ptr);
}

static FieldInfo* INT_FIELD_INFO= NULL;

FieldInfo* get_info_int(){
if (INT_FIELD_INFO==NULL){
INT_FIELD_INFO = (FieldInfo*) malloc(sizeof(FieldInfo)); //!!!!!
INT_FIELD_INFO->type = "int";
INT_FIELD_INFO->el_size = sizeof(int);
INT_FIELD_INFO->sum_el = int_sum;
INT_FIELD_INFO->mult_el = int_mult;
INT_FIELD_INFO->print_el = int_print;
INT_FIELD_INFO->read_array = read_int_array;
INT_FIELD_INFO->set_zero = int_set_zero;
INT_FIELD_INFO->get_number = int_get_number;

}
return INT_FIELD_INFO;
}


Loading

0 comments on commit 4f58146

Please sign in to comment.