├── .gitignore ├── Lab 10 └── Lab10.c ├── Lab 11 ├── Lab11.c ├── rectangle.c └── rectangle.h ├── Lab 12 └── Lab12.c ├── Lab 13 └── Lab13.c ├── Lab 14 ├── Lab14.c └── README.md ├── Lab 15 ├── Lab15.c └── README.md ├── Lab 3 └── Lab3.c ├── Lab 4 └── Lab4.c ├── Lab 5 └── Lab5.c ├── Lab 6 └── Lab6.c ├── Lab 7 └── Lab7.c ├── Lab 8 └── Lab8.c ├── Lab 9 └── Lab9.c └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /Lab 10/Lab10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int LCM(int a, int b){ 5 | int i = 2; 6 | while(((a % i) && (b % i)) != 0) 7 | i++; 8 | return i; 9 | } 10 | 11 | int GCD(int a, int b){ 12 | while(a && b) 13 | if(a >= b) 14 | a %= b; 15 | else 16 | b %= a; 17 | return a | b; 18 | } 19 | 20 | struct Coords{ 21 | float x; 22 | float y; 23 | }; 24 | 25 | float Matrix(float x1, float y1, float x2, float y2){ 26 | return sqrt(pow((x2 - x1),2) + pow((y2 - y1),2)); 27 | }; 28 | 29 | int main(){ 30 | printf(" ___ L - A - B - A - 10 ___ \n\n"); 31 | printf("\n - + - + - + - Exercise 1 - + - + - + - \n"); 32 | 33 | int a, b; 34 | printf("Enter values: "); 35 | scanf("%d %d", &a, &b); 36 | printf("LCM: %d", LCM(a, b)); 37 | printf("\nGCD: %d", GCD(a, b)); 38 | 39 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 40 | 41 | int n; 42 | printf("Enter number of points: "); 43 | scanf("%d", &n); 44 | struct Coords point[n]; 45 | printf("\n"); 46 | for(int i = 0; i < n; i++){ 47 | printf("Enter %d coords: ", i + 1); 48 | scanf("%f %f", &point[i].x, &point[i].y); 49 | } 50 | 51 | printf("\nFrom|To "); 52 | for(int i = 0; i < n; i++) 53 | printf("%d\t", i + 1); 54 | 55 | for(int i = 0; i < n; i++){ 56 | printf("\n%d\t", i + 1); 57 | for(int j = 0; j < n; j++){ 58 | if(i == j) 59 | printf("X\t"); 60 | else if(i < j) 61 | printf("%.2f\t", Matrix(point[i].x, point[i].y, point[j].x, point[j].y)); 62 | else 63 | printf("%.2f\t", -Matrix(point[i].x, point[i].y, point[j].x, point[j].y)); 64 | } 65 | } 66 | 67 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Lab 11/Lab11.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rectangle.h" 3 | 4 | int main() 5 | { 6 | printf(" ___ L - A - B - A - 11 ___ \n\n"); 7 | printf("\n - + - + - + - Exercise 1 - + - + - + - \n"); 8 | 9 | struct Rectangle rect; 10 | 11 | printf("Add first coords: "); 12 | scanf("%f %f", &rect.x1, &rect.y1); 13 | printf("Add second coords: "); 14 | scanf("%f %f", &rect.x2, &rect.y2); 15 | printf("Perimeter: %f\n", rectanglePerimeter(rect)); 16 | printf("Area: %f\n", rectangleArea(rect)); 17 | 18 | printf("\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Lab 11/rectangle.c: -------------------------------------------------------------------------------- 1 | #include "rectangle.h" 2 | 3 | float rectanglePerimeter(struct Rectangle rect){ 4 | return 2 * ((rect.x2 - rect.x1) + (rect.y2 - rect.y1)); 5 | } 6 | 7 | float rectangleArea(struct Rectangle rect){ 8 | return pow((rect.x2 - rect.x1), 2); 9 | } 10 | -------------------------------------------------------------------------------- /Lab 11/rectangle.h: -------------------------------------------------------------------------------- 1 | #ifndef H_RECTANGLE 2 | #define H_RECTANGLE 3 | #include "math.h" 4 | 5 | struct Rectangle{ 6 | float x1, y1; 7 | float x2, y2; 8 | }; 9 | 10 | float rectanglePerimeter(struct Rectangle rect); 11 | float rectangleArea(struct Rectangle rect); 12 | #endif 13 | -------------------------------------------------------------------------------- /Lab 12/Lab12.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]){ 5 | char* filename = argv[1]; 6 | freopen(filename, "w", stdout); 7 | time_t timer = time(NULL); 8 | for (int i = 0; i < 10; i++){ 9 | struct tm* dateTime = localtime(&timer); 10 | char strDate[40] = {0}; 11 | strftime(strDate, 40, "%d.%m.%Y", dateTime); 12 | printf("%s\n", strDate); 13 | timer += 24 * 60 * 60; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Lab 13/Lab13.c: -------------------------------------------------------------------------------- 1 | #include "stdlib.h" 2 | #include "stdio.h" 3 | #include "string.h" 4 | #define _CRT_SECURE_NO_WARNINGS 5 | 6 | unsigned int reverseBytes(unsigned int n) 7 | { 8 | return ((n >> 24) & 0x000000ff) | 9 | ((n >> 8) & 0x0000ff00) | 10 | ((n << 8) & 0x00ff0000) | 11 | ((n << 24) & 0xff000000); 12 | } 13 | 14 | typedef union tagTAGHEADER 15 | { 16 | char buffer[12]; // 12 total 17 | 18 | struct { 19 | unsigned short empty; // 2 20 | unsigned char version[3]; // 3 21 | unsigned char v1; // 1 22 | unsigned char v2; // 1 23 | unsigned char flags; // 1 24 | unsigned int size; // 4 25 | } data; 26 | } TAGHEADER; 27 | 28 | typedef union tagFRAMEHEADER 29 | { 30 | char buffer[10]; // 10 total 31 | 32 | struct { 33 | unsigned char name[4]; // 4 34 | unsigned int size; // 4 35 | unsigned short flags; // 2 36 | } data; 37 | } FRAMEHEADER; 38 | 39 | void copyFile(FILE* inp, FILE* outp) { 40 | int c; 41 | while ((c = getc(inp)) != EOF) 42 | putc(c, outp); 43 | } 44 | 45 | void show(char* fileName) 46 | { 47 | FILE* file; 48 | file = fopen(fileName, "rb"); 49 | if (file == NULL) 50 | { 51 | printf("Read file error ocured!\n"); 52 | exit(404); 53 | } 54 | 55 | fseek(file, 0, SEEK_SET); 56 | 57 | TAGHEADER tagHeader; 58 | fread(tagHeader.buffer + 2, sizeof(char), 10, file); 59 | 60 | unsigned int tagSize = reverseBytes(tagHeader.data.size); 61 | 62 | printf("%sv%d.%d\n", tagHeader.data.version, 63 | tagHeader.data.v1, 64 | tagHeader.data.v2); 65 | 66 | while (ftell(file) < tagSize + 10) 67 | { 68 | FRAMEHEADER frameHeader; 69 | fread(frameHeader.buffer, sizeof(char), 10, file); 70 | if (frameHeader.data.name[0] == 0) 71 | break; 72 | printf("%s: ", frameHeader.data.name); 73 | 74 | unsigned int frameSize = reverseBytes(frameHeader.data.size); 75 | 76 | unsigned char* frameContent; 77 | frameContent = malloc(sizeof(char) * frameSize); 78 | fread(frameContent, sizeof(char), frameSize, file); 79 | unsigned int i; 80 | for ( i = 0; i < frameSize; ++i) 81 | { 82 | printf("%c", frameContent[i]); 83 | } 84 | printf("\n"); 85 | free(frameContent); 86 | } 87 | fclose(file); 88 | } 89 | 90 | void get(char* fileName, char frameName[4]) 91 | { 92 | FILE* file; 93 | file = fopen(fileName, "rb"); 94 | 95 | TAGHEADER tagHeader; 96 | fread(tagHeader.buffer + 2, sizeof(char), 10, file); 97 | 98 | unsigned int tagSize = reverseBytes(tagHeader.data.size); 99 | 100 | while (ftell(file) < tagSize + 10) 101 | { 102 | FRAMEHEADER frameHeader; 103 | fread(frameHeader.buffer, sizeof(char), 10, file); 104 | 105 | unsigned int frameSize = reverseBytes(frameHeader.data.size); 106 | 107 | if (strcmp(frameHeader.data.name, frameName) == 0) 108 | { 109 | printf("%s: ", frameHeader.data.name); 110 | 111 | unsigned char* frameContent; 112 | frameContent = malloc(sizeof(char) * frameSize); 113 | fread(frameContent, sizeof(char), frameSize, file); 114 | unsigned int i; 115 | for (i = 0; i < frameSize; ++i) 116 | { 117 | printf("%c", frameContent[i]); 118 | } 119 | printf("\n"); 120 | free(frameContent); 121 | fclose(file); 122 | return; 123 | } 124 | 125 | fseek(file, frameSize, SEEK_CUR); 126 | } 127 | fclose(file); 128 | printf("No value found for %s!", frameName); 129 | } 130 | 131 | void set(char* fileName, char frameName[4], char* frameValue) 132 | { 133 | FILE* file; 134 | file = fopen(fileName, "rb"); 135 | 136 | TAGHEADER tagHeader; 137 | fread(tagHeader.buffer + 2, sizeof(char), 10, file); 138 | 139 | unsigned int tagSize = reverseBytes(tagHeader.data.size); 140 | 141 | unsigned int oldFramePos = 0; 142 | unsigned int oldFrameSize = 0; 143 | 144 | while (ftell(file) < tagSize + 10) 145 | { 146 | FRAMEHEADER frameHeader; 147 | fread(frameHeader.buffer, sizeof(char), 10, file); 148 | 149 | unsigned int frameSize = reverseBytes(frameHeader.data.size); 150 | 151 | if (strcmp(frameHeader.data.name, frameName) == 0) 152 | { 153 | oldFramePos = ftell(file) - 10; 154 | oldFrameSize = frameSize; 155 | break; 156 | } 157 | fseek(file, frameSize, SEEK_CUR); 158 | } 159 | 160 | unsigned int valueSize = strlen(frameValue); 161 | 162 | unsigned int newTagSize = tagSize - oldFrameSize + valueSize + 10 * (oldFramePos != 0); 163 | 164 | if (oldFramePos == 0) 165 | { 166 | oldFramePos = ftell(file); 167 | } 168 | if (valueSize == 0) 169 | { 170 | newTagSize -= 10; 171 | } 172 | 173 | FILE* fileCopy; 174 | fileCopy = fopen("temp.mp3", "wb"); 175 | 176 | fseek(file, 0, SEEK_SET); 177 | fseek(fileCopy, 0, SEEK_SET); 178 | copyFile(file, fileCopy); 179 | 180 | fclose(file); 181 | fclose(fileCopy); 182 | 183 | fileCopy = fopen("temp.mp3", "rb"); 184 | file = fopen(fileName, "wb"); 185 | 186 | tagHeader.data.size = reverseBytes(newTagSize); 187 | 188 | fwrite(tagHeader.buffer + 2, sizeof(char), 10, file); 189 | 190 | fseek(fileCopy, 10, SEEK_SET); 191 | unsigned int i; 192 | for (i = 0; i < oldFramePos - 10; ++i) 193 | { 194 | int c; 195 | c = getc(fileCopy); 196 | putc(c, file); 197 | } 198 | 199 | if (valueSize > 0) 200 | { 201 | FRAMEHEADER frameHeader; 202 | unsigned int i; 203 | for (i = 0; i < 4; ++i) 204 | { 205 | frameHeader.data.name[i] = frameName[i]; 206 | } 207 | frameHeader.data.size = reverseBytes(valueSize); 208 | frameHeader.data.flags = 0; 209 | fwrite(frameHeader.buffer, sizeof(char), 10, file); 210 | } 211 | 212 | fwrite(frameValue, sizeof(char), valueSize, file); 213 | 214 | fseek(fileCopy, oldFramePos + 10 + oldFrameSize, SEEK_SET); 215 | for (i = ftell(file); i < newTagSize; ++i) 216 | { 217 | unsigned short int c; 218 | c = getc(fileCopy); 219 | putc(c, file); 220 | } 221 | 222 | printf("New value for frame %s: %s\n", frameName, frameValue); 223 | 224 | copyFile(fileCopy, file); 225 | 226 | fclose(file); 227 | fclose(fileCopy); 228 | remove("temp.mp3"); 229 | } 230 | 231 | int main(int argc, char* argv[]) { 232 | char* fileName; 233 | char* frameName; 234 | char* value; 235 | char showFlag = 0; 236 | char setFlag = 0; 237 | char getFlag = 0; 238 | int i; 239 | for (i = 1; i < argc; i++) { 240 | if (strcmp(argv[i], "--show") == 0) { 241 | showFlag = 1; 242 | continue; 243 | } 244 | if (argv[i][2] == 'f') 245 | { 246 | fileName = strpbrk(argv[i], "=") + 1; 247 | } 248 | if (argv[i][2] == 'g') { 249 | getFlag = 1; 250 | frameName = strpbrk(argv[i], "=") + 1; 251 | continue; 252 | } 253 | if (argv[i][2] == 's') { 254 | setFlag = 1; 255 | frameName = strpbrk(argv[i], "=") + 1; 256 | continue; 257 | } 258 | if (argv[i][2] == 'v') { 259 | value = strpbrk(argv[i], "=") + 1; 260 | continue; 261 | } 262 | } 263 | if (showFlag) 264 | { 265 | show(fileName); 266 | } 267 | if (getFlag) 268 | { 269 | get(fileName, frameName); 270 | } 271 | if (setFlag) 272 | { 273 | set(fileName, frameName, value); 274 | } 275 | return 0; 276 | } -------------------------------------------------------------------------------- /Lab 14/Lab14.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void GameLife(int** life, int hei, int wid){ 6 | int N; 7 | int tmp[hei][wid]; 8 | int x, y; 9 | int inf = 0; 10 | for(y = 0; y < hei; y++) 11 | for(x = 0; x < wid; x++) 12 | tmp[y][x] = life[y][x]; 13 | for(y = 1; y < hei - 1; y++){ 14 | for(x = 1; x < wid - 1; x++){ 15 | N = life[y + 1][x - 1] + life[y + 1][x] + life[y + 1][x + 1] + life[y][x - 1] + life[y][x + 1] + life[y - 1][x - 1] + life[y - 1][x] + life[y - 1][x + 1]; 16 | if(tmp[y][x] == 1){ 17 | if(N == 2) tmp[y][x] = life[y][x]; 18 | if(N == 3) tmp[y][x] = life[y][x]; 19 | if(N > 3) tmp[y][x] = 0; 20 | if(N < 2) tmp[y][x] = 0; 21 | } 22 | else{ 23 | if(N == 3) tmp[y][x] = 1; 24 | } 25 | N = 0; 26 | } 27 | } 28 | for(y = 0; y < hei; y++) 29 | for(x = 0; x < wid; x++){ 30 | if(life[y][x] == tmp[y][x]) 31 | inf++; 32 | life[y][x] = tmp[y][x]; 33 | } 34 | if(inf == hei * wid) 35 | exit(0); 36 | } 37 | 38 | struct Bmp{ 39 | int Width; 40 | int Height; 41 | int Size; 42 | }; 43 | 44 | int main(int argc, char* argv[]){ 45 | struct Bmp Image; 46 | unsigned char header[54]; 47 | int i, j, k, l, m; 48 | int maxiter, dumpfreq = 1; 49 | char* dirname; 50 | FILE* file; 51 | 52 | //GAME SETTING 53 | 54 | for(i = 0; i < argc; i++){ 55 | if(!strcmp("--input", argv[i])){ 56 | file = fopen(argv[1 + 1], "rb"); 57 | } 58 | if(!strcmp("--output", argv[i])){ 59 | dirname = argv[i + 1]; 60 | mkdir(dirname); 61 | } 62 | if(!strcmp("--max_iter", argv[i])){ 63 | maxiter = strtol(argv[i + 1], 0, 10); 64 | } 65 | if(!strcmp("--dump_freq", argv[i])){ 66 | dumpfreq = strtol(argv[i + 1], 0, 10); 67 | } 68 | } 69 | 70 | //READ IMAGE SIZE, HEIGHT, WIDTH, BYTE 71 | fread(header, 1, 54, file); 72 | Image.Width = header[21] * 256 * 256 * 256 + header[20] * 256 * 256 + header[19] * 256 + header[18]; 73 | Image.Height = header[25] * 256 * 256 * 256 + header[24] * 256 * 256 + header[23] * 256 + header[22]; 74 | Image.Size = header[5] * 256 * 256 * 256 + header[4] * 256 * 256 + header[3] * 256 + header[2]; 75 | unsigned char imagebyte[Image.Size - 54]; 76 | fread(imagebyte, 1, Image.Size, file); 77 | 78 | int** img = (int**)malloc(Image.Height * sizeof(int*)); 79 | for(i = 0; i < Image.Height; i++) 80 | img[i] = (int*)malloc(Image.Width * sizeof(int)); 81 | 82 | //MAKE TO ONE-ZERO ARRAY 83 | k = -(Image.Width % 4); 84 | for(i = Image.Height - 1; i >= 0; i--){ 85 | k += (Image.Width % 4); 86 | for(j = 0; j < Image.Width; j++){ 87 | if(imagebyte[k] == 255) 88 | img[i][j] = 0; 89 | else 90 | img[i][j] = 1; 91 | k += 3; 92 | } 93 | } 94 | 95 | for (l = 1; l <= maxiter; l++){ 96 | if(l % dumpfreq == 0){ 97 | char filename[l]; 98 | char way[20]; 99 | strcpy(way, dirname); 100 | strcat(strcat(way, "\\"), strcat(itoa(l, filename, 10), ".bmp")); 101 | FILE* life = fopen(way, "w"); 102 | fwrite(header, 1, 54, life); 103 | m = 0; 104 | // MAKE BITMAP 105 | for (i = Image.Height - 1; i >= 0; i--){ 106 | for (j = 0; j < Image.Width; j++){ 107 | for (k = 0; k < 3; k++) { 108 | if (img[i][j] == 1) 109 | imagebyte[m] = 0; 110 | else 111 | imagebyte[m] = 255; 112 | m++; 113 | } 114 | } 115 | while (m % 4 != 0) { 116 | imagebyte[m] = 0; 117 | m++; 118 | } 119 | } 120 | fwrite(imagebyte, 1, Image.Size, life); 121 | fclose(life); 122 | } 123 | //GAME 124 | GameLife(img, Image.Height, Image.Width); 125 | } 126 | free(img); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /Lab 14/README.md: -------------------------------------------------------------------------------- 1 | # Игра «Жизнь» 2 | 3 | Параметры: 4 | 5 | | Параметр | Описние | 6 | |---|---| 7 | |**--input** *YourImage.bmp*|Картинка в формате bmp, хранящая начальную ситуация (первое поколение) игры| 8 | |**--output** *DirictoryName*|Название директории для хранения поколений игры| 9 | |**--max_iter** *N*|Максимальное число поколений которое может эмулировать программа. (по умолчанию бессконечность)| 10 | |**--dump_freq** *N*|Частота с которой программа должно сохранять поколения виде картинки. (по умолчанию - 1)| 11 | 12 | ### Примеры работы программы 13 | 14 | *Результируюший набор .bmp файлов собран в .gif с промощью онлайн утилит* 15 | 16 | | ITMO | Gun | 17 | |---|---| 18 | 19 | -------------------------------------------------------------------------------- /Lab 15/Lab15.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Extract(char* arcname){ 4 | FILE* arch = fopen(arcname, "rb+wb"); 5 | unsigned long long int now_position = 0; 6 | unsigned long long int start_position = 0; 7 | int c; 8 | while ((c = getc(arch)) != EOF) { 9 | start_position++; 10 | if (c == '\n') 11 | break; 12 | } 13 | fseek(arch, 0, SEEK_SET); 14 | char filename[128] = {0}; 15 | unsigned long long int filesize; 16 | FILE *file; 17 | while (fscanf(arch, "< %s : %llu >", filename, &filesize) != 0) { 18 | file = fopen(filename, "wb"); 19 | if (file == NULL) 20 | break; 21 | now_position = ftell(arch); 22 | fseek(arch, start_position, SEEK_SET); 23 | start_position += filesize; 24 | while (filesize-- > 0) 25 | putc((c = getc(arch)), file); 26 | fseek(arch, now_position, SEEK_SET); 27 | fclose(file); 28 | } 29 | printf("\n + Unzipping sucssess + \n"); 30 | } 31 | 32 | void List(char* arcname){ 33 | FILE* arcfile = fopen(arcname, "rb"); 34 | char filename[128] = {0}; 35 | unsigned long long int filesize; 36 | printf("File list:\n"); 37 | while (fscanf(arcfile, "< %s : %llu >", filename, &filesize) != 0) { 38 | printf("\t%s\n", filename); 39 | } 40 | fclose(arcfile); 41 | } 42 | 43 | void Create(char* arcname, int filecount, char* files[]){ 44 | int i; 45 | int temp; 46 | FILE* arcfile = fopen(arcname, "wb"); 47 | FILE* file; 48 | unsigned long long int nameandsize[128]; 49 | for (i = 5; i < filecount; i++){ 50 | file = fopen(files[i], "rb"); 51 | if (file == NULL) 52 | continue; 53 | fseek(file, 0, SEEK_END); 54 | nameandsize[i - 5] = ftell(file); 55 | fseek(file, 0, SEEK_SET); 56 | fclose(file); 57 | } 58 | for (i = 0; i < filecount - 5; i++) 59 | fprintf(arcfile, "< %s : %llu >", files[i + 5], nameandsize[i]); 60 | fprintf(arcfile, "\n"); 61 | for (i = 5; i < filecount; i++){ 62 | file = fopen(files[i], "rb"); 63 | if (file == NULL){ 64 | printf("File not added. ERROR. You're trying use a non-existent file\n"); 65 | continue; 66 | } 67 | else{ 68 | printf("File added\n"); 69 | } 70 | while ((temp = getc(file)) != EOF) 71 | putc(temp, arcfile); 72 | fclose(file); 73 | } 74 | printf("\n + Zipping sucssess + \n"); 75 | } 76 | 77 | int main(int argc, char* argv[]){ 78 | FILE* arcfile; 79 | int i; 80 | char* arcname; 81 | printf("\n"); 82 | for (i = 0; i < argc; i++){ 83 | if(!strcmp("--file", argv[i])){ 84 | arcname = argv[i + 1]; 85 | } 86 | if(!strcmp("--create", argv[i])){ 87 | Create(arcname, argc, argv); 88 | break; 89 | } 90 | if(!strcmp("--extract", argv[i])){ 91 | Extract(arcname); 92 | } 93 | if(!strcmp("--list", argv[i])){ 94 | List(arcname); 95 | } 96 | } 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /Lab 15/README.md: -------------------------------------------------------------------------------- 1 | # Архиватор 2 | 3 | Параметры: 4 | 5 | | Параметр | Описние | 6 | |---|---| 7 | |**--file** *FILENAME*|Имя файлового архива с которым будет работать архиватор| 8 | |**--create** *FILE1 FILE2 …. FILEN*|Команда для создания файлового архива| 9 | |**--extract**|Команда для извлечения из файлового архива файлов| 10 | |**--list**|Команда для предоставления списка файлов, хранящихся в архиве| 11 | 12 | Пример ввода в консоль: 13 | + programm.exe ser --file archive.ser --create a.txt b.bin c.bmp - создает файл archive.ser, который состоит из a.txt b.bin c.bmp 14 | + programm.exe ser --file archive.ser --extract - извлекает все файлы в архиве archive.ser 15 | + programm.exe ser --file archive.ser --list - выводит в консоль содержимое архива archive.ser 16 | -------------------------------------------------------------------------------- /Lab 3/Lab3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int oct_num, dec_num; 5 | int oct_num_buff, dec_num_buff; 6 | int dis=0; 7 | 8 | int main(){ 9 | printf(" ___ L - A - B - A - 3 ___ \n\n"); 10 | printf(" - + - + - + - Exercise 1 and 2 - + - + - + - \n\n"); 11 | 12 | printf("Enter the oct number: "); 13 | scanf("%d", &oct_num); 14 | oct_num_buff = oct_num; 15 | while(oct_num_buff > 0){ 16 | dec_num += oct_num_buff % 10 * pow(8, dis); 17 | oct_num_buff /= 10; 18 | dis++; 19 | } 20 | printf("Your dec number: %d", dec_num); 21 | 22 | printf("\n\n - + - + - + - Exercise 3 - + - + - + - \n\n"); 23 | 24 | printf("Your oct number: %d", oct_num); 25 | dec_num_buff = dec_num; 26 | dis = oct_num_buff = 0; 27 | dec_num_buff <<= 1; 28 | while(dec_num_buff > 0){ 29 | oct_num_buff += dec_num_buff % 8 * pow(10, dis); 30 | dis++; 31 | dec_num_buff /= 8; 32 | } 33 | printf("\nYour oct number with a shift: %d", oct_num_buff); 34 | 35 | printf("\n\n - + - + - + - Exercise 4 - + - + - + - \n\n"); 36 | 37 | printf("Your oct number: %d", oct_num); 38 | dec_num_buff = ~dec_num; 39 | dis = oct_num_buff = 0; 40 | while(abs(dec_num_buff) > 0){ 41 | oct_num_buff += dec_num_buff % 8 * pow(10, dis); 42 | dis++; 43 | dec_num_buff /= 8; 44 | } 45 | printf("\nYour oct number with a revers: %d", oct_num_buff); 46 | 47 | printf("\n\n - + - + - + - Exercise 5 - + - + - + - \n\n"); 48 | 49 | int sec_oct_num; 50 | int sec_dec_num; 51 | dis = 0; 52 | printf("Enter the second oct number: "); 53 | scanf("%d", &sec_oct_num); 54 | while(oct_num_buff > 0){ 55 | sec_dec_num += sec_oct_num % 10 * pow(8, dis); 56 | sec_oct_num /= 10; 57 | dis++; 58 | } 59 | dis = 0; 60 | dec_num &= sec_dec_num; 61 | while(dec_num > 0){ 62 | oct_num += dec_num % 8 * pow(10, dis); 63 | dis++; 64 | dec_num /= 8; 65 | } 66 | printf("Your new oct number: %d\n\n", oct_num); 67 | 68 | printf(" ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /Lab 4/Lab4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int num; 4 | int result; 5 | 6 | int main(){ 7 | printf(" ___ L - A - B - A - 4 ___ \n\n"); 8 | printf(" - + - + - + - Exercise 1 - + - + - + - \n\n"); 9 | 10 | printf("Enter the number: "); 11 | scanf("%d", &num); 12 | result = ( num >= 1 ) && ( num <= 10); 13 | printf("Result: %d\n\n", result); 14 | 15 | printf(" - + - + - + - Exercise 2 - + - + - + - \n\n"); 16 | 17 | printf("Enter the number: "); 18 | scanf("%d", &num); 19 | 20 | printf("First bite is: %d\n\n", num%2); 21 | printf(" ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Lab 5/Lab5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int num[7] = {10, 20, 30, 40, 50, 60, 70}; 4 | int A[2][2] = {1, 2, 5 | 3, 4}; 6 | int B[2][2] = {1, 0, 7 | 0, 1}; 8 | int C[2][2] = {0}; 9 | 10 | 11 | int main(){ 12 | printf(" ___ L - A - B - A - 5 ___ \n\n"); 13 | printf(" - + - + - + - Exercise 1 - + - + - + - \n"); 14 | 15 | for(int i = 0; i < 7; i++) 16 | printf("\nElement number: %d Value: %d",i,num[i]); 17 | 18 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 19 | 20 | printf("\nResult: "); 21 | for(int i = 0; i < 2; i++) 22 | for(int j = 0; j < 2; j++) 23 | for(int k = 0; k < 2; k++) 24 | C[i][j] += A[i][k] * B[k][j]; 25 | for(int i = 0; i < 2; i++){ 26 | printf("\n"); 27 | for(int j = 0; j < 2; j++) 28 | printf(" %d ", C[i][j]); 29 | } 30 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Lab 6/Lab6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | const int n = 4; 6 | char a[n]; 7 | int i, j; 8 | 9 | printf(" ___ L - A - B - A - 6 ___ \n\n"); 10 | printf(" - + - + - + - Exercise 1 - + - + - + - \n"); 11 | printf("\nAdd values: "); 12 | 13 | for (i = 0; i < n; i++) 14 | scanf("%c", &a[i]); 15 | 16 | printf("Your values: "); 17 | for(i = 0; i < n; i++) 18 | printf("%c", *(a + i)); 19 | 20 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 21 | char *b; 22 | b = (char*)malloc(n * sizeof(char)); 23 | 24 | printf("\nAdd values: "); 25 | for (j = 0; j < n; j++) 26 | scanf("%c", &b[j]); 27 | 28 | printf("Your values: "); 29 | for (j = 0; j < n; j++) 30 | printf("%c", *(a + j)); 31 | 32 | free(b); 33 | 34 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Lab 7/Lab7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum DaysOfWeek{ 5 | Monday = 1, 6 | Tuesday, 7 | Wednesday, 8 | Thursday, 9 | Friday, 10 | Saturday, 11 | Sunday 12 | }; 13 | 14 | struct Obj{ 15 | int x0, y0, x1, y1, x2, y2, x3, y3; 16 | int S; 17 | int P; 18 | }; 19 | 20 | struct MP3{ 21 | unsigned Play : 1; 22 | unsigned Pause: 1; 23 | unsigned REC : 1; 24 | }; 25 | 26 | int main(){ 27 | printf(" ___ L - A - B - A - 7 ___ \n\n"); 28 | printf(" - + - + - + - Exercise 1 - + - + - + - \n"); 29 | 30 | int day; 31 | day = Monday; 32 | printf("\nYour day is: %d - it is Monday", day); 33 | 34 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 35 | 36 | struct Obj Rect; 37 | printf("\nYour figure is a rectangle: "); 38 | printf("\nAdd coordinates:\n"); 39 | printf(" "); 40 | scanf(" %d %d", &(Rect.x0), &(Rect.y0)); 41 | printf(" "); 42 | scanf(" %d %d", &(Rect.x1), &(Rect.y1)); 43 | printf(" "); 44 | scanf(" %d %d", &(Rect.x2), &(Rect.y2)); 45 | printf(" "); 46 | scanf(" %d %d", &(Rect.x3), &(Rect.y3)); 47 | Rect.P = 2 * (sqrt((Rect.x0 - Rect.x1)*(Rect.x0 - Rect.x1) + (Rect.y0 - Rect.y1)*(Rect.y0 - Rect.y1)) + sqrt((Rect.x1 - Rect.x2)*(Rect.x1 - Rect.x2) + (Rect.y1 - Rect.y2)*(Rect.y1 - Rect.y2))); 48 | Rect.S = sqrt((Rect.x0 - Rect.x1)*(Rect.x0 - Rect.x1) + (Rect.y0 - Rect.y1)*(Rect.y0 - Rect.y1)) * sqrt((Rect.x1 - Rect.x2)*(Rect.x1 - Rect.x2) + (Rect.y1 - Rect.y2)*(Rect.y1 - Rect.y2)); 49 | printf("Perimeter: %d", Rect.P); 50 | printf("\nArea: %d", Rect.S); 51 | 52 | printf("\n\n - + - + - + - Exercise 3 - + - + - + - \n"); 53 | 54 | struct MP3 Status; 55 | printf("\nAdd hex number: "); 56 | scanf("%x", &(Status)); 57 | printf("MP3 status:"); 58 | printf("\n Play: %s", (Status.Play) ? "ON" : "OFF"); 59 | printf("\n Pause: %s", (Status.Pause) ? "ON" : "OFF"); 60 | printf("\n REC: %s", (Status.REC) ? "ON" : "OFF"); 61 | 62 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /Lab 8/Lab8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | printf(" ___ L - A - B - A - 8 ___ \n\n"); 5 | 6 | char str1[100]; 7 | char str2[100]; 8 | printf("Enter first string: "); 9 | gets(str1); 10 | printf("Enter second string: "); 11 | gets(str2); 12 | 13 | printf("\n - + - + - + - Exercise 1 - + - + - + - \n"); 14 | 15 | char buffstr[100]; 16 | strcpy(buffstr, str1); 17 | printf("\nConcatenation: %s", strcat(buffstr, str2)); 18 | 19 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 20 | 21 | printf("\nStrings are %s", (strcmp(str1, str2)) ? "different" : "same"); 22 | 23 | printf("\n\n - + - + - + - Exercise 3 - + - + - + - \n"); 24 | 25 | strcpy(str2, str1); 26 | printf("\nCopying completed"); 27 | printf("\nFirst string: %s", str1); 28 | printf("\nSecond string: %s", str2); 29 | 30 | printf("\n\n - + - + - + - Exercise 4 - + - + - + - \n"); 31 | 32 | printf("\nString length is %d", strlen(str1)); 33 | 34 | printf("\n\n - + - + - + - Exercise 5 - + - + - + - \n"); 35 | 36 | char key; 37 | printf("\nWhat symbol will we find?"); 38 | printf("\nAdd symbol: "); 39 | scanf("%c", &key); 40 | printf("Your symbol in %d position", strrchr(str1, key) - str1 + 1); 41 | 42 | 43 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Lab 9/Lab9.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | printf(" ___ L - A - B - A - 9 ___ \n\n"); 5 | 6 | printf("\n - + - + - + - Exercise 1 - + - + - + - \n"); 7 | 8 | int upper = 0, lower = 0, digit = 0, i = 0; 9 | char str[100]; 10 | printf("\nAdd string: "); 11 | gets(str); 12 | for(i = 0; i < strlen(str); i++){ 13 | if(isdigit(str[i])) 14 | digit++; 15 | else if(isupper(str[i])) 16 | upper++; 17 | else if(islower(str[i])) 18 | lower++; 19 | } 20 | printf("\nNumber of numbers: %d", digit); 21 | printf("\nNumber of upper register: %d", upper); 22 | printf("\nNumber of lower register: %d", lower); 23 | 24 | printf("\n\n - + - + - + - Exercise 2 - + - + - + - \n"); 25 | 26 | int tariff_price, minutes, cost_per_minute; 27 | printf("Add tariff price: "); 28 | scanf("%d", &tariff_price); 29 | printf("Add number of minutes: "); 30 | scanf("%d", &minutes); 31 | printf("Add cost per 1 minute: "); 32 | scanf("%d", &cost_per_minute); 33 | int full_price = tariff_price; 34 | if(minutes > 499) 35 | full_price += (minutes - 499) * cost_per_minute; 36 | printf("Full price id: %d", full_price); 37 | 38 | printf("\n\n ___ E - N - D - - P - R - O - G - R - A - M - M ___ \n\n"); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ITMO-Programming-1-sem 2 | Lab. works on programming 1 sem. in ITMO University 3 | 4 | 1. [x] 1. [Console application develop \ Разработка консольного приложения](#) 5 | 2. [x] 2. [Calculation of function values at a given point \ Расчёт значения функции в заданной точке](#) 6 | 3. [x] 3. [Representation of numbers in various number systems and bit operations \ Представление чисел в различных системах счисления и битовые операции](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%203) 7 | 4. [x] 4. [Logic operations \ Логические операции](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%204) 8 | 5. [x] 5. [Arrays \ Массивы](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%205) 9 | 6. [x] 6. [Pointers and dynamic memory \ Указатели и динамическая память](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%206) 10 | 7. [x] 7. [Data types \ Типы данных, определяемые пользователем](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%207) 11 | 8. [x] 8. [Strings \ Работа со строками](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%208) 12 | 9. [x] 9. [Loops and branches \ Циклы и ветвления](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%209) 13 | 10. [x] 10. [Functions \ Функции](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2010) 14 | 11. [x] 11. [Using header files \ Использование заголовочных файлов](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2011) 15 | 12. [x] 12. [Input - output operations \ Операции ввода-вывода](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2012) 16 | 13. [x] 13. [MP3 file meta-information editor \ Редактор метаинформации mp3-файла](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2013) 17 | 14. [x] 14. [Conway's Game of Life \ Игра жизнь](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2014) 18 | 15. [x] 15. [Archiver \ Архиватор](https://github.com/geySerP/ITMO-Programming-1-sem/tree/master/Lab%2015) 19 | --------------------------------------------------------------------------------