Lab4_n/Project7/Source.cpp

244 lines
4.3 KiB
C++
Raw Normal View History

2024-11-07 08:41:32 +04:00
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#define MAX_N 8
#define MAX_M 12
int arr[MAX_N][MAX_M] = {
{10, 11, 12, 13},
{20, 21, 9, 23},
{30, 31, 32, 33}
};
int n = 3;
int m = 4;
void print() {
printf("//// print() ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
printf("%3d", arr[i][j]);
}
printf("\n");
}
}
void fillx10() {
printf("//// fillx10 ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
arr[i][j] = i * 10 + j;
}
}
}
void fillzero() {
printf("//// fillzero ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
arr[i][j] = 0;
}
}
}
void randfill() {
printf("//// randfill ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
arr[i][j] = rand() % 10;
}
}
}
void nch10() {
printf("//// nch10 ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
if (arr[i][j] % 2 == 1) {
arr[i][j] *= 10;
}
}
}
}
void kr10() {
printf("//// kr10 ////\n");
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
if (arr[i][j] % 10 == 0) {
arr[i][j] /= 10;
}
}
}
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("m = ");
scanf_s("%d", &m);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d:\n", n);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d:\n", m);
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
scanf_s("%d", &arr[i][j]);
}
}
}
void save() {
FILE* fout = fopen("c:\\Temp\\arr1.txt", "wtt");
if (fout == NULL) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return;
}
fprintf(fout, "%d", n);
fprintf(fout, "&%d\n", m);
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
fprintf(fout, "%d", arr[i][j]);
}
fprintf(fout, "\n");
}
fclose(fout);
}
void load() {
FILE* fin = fopen("c:\\Temp\\arr1.txt", "rt");
if (fin == NULL) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return;
}
fprintf(fin, "%d", &n);
fprintf(fin, "&%d\n", &m);
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
fscanf(fin, "%d", &arr[i][j]);
}
}
fclose(fin);
}
void deleteRow(int delRow) {
printf("//// deleteRow(%d) ////\n", delRow);
for (int i = delRow; i < n - 1; i += 1) {
for (int j = 0; j < m; j += 1) {
arr[i][j] = arr[i + 1][j];
}
}
n -= 1;
}
void dubCollum(int dubcol) {
printf("//// dubCollum() ////\n", dubcol);
for (int i = 0; i < n; i += 1) {
for (int j = m; j > dubcol; j -= 1) {
arr[i][j] = arr[i][j - 1];
}
}
m += 1;
}
void func() {
int max = arr[0][0], min = arr[0][0];
int maxRow = 0, maxCol = 0;
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
if (arr[i][j] > max) {
max = arr[i][j];
maxRow = i;
maxCol = j;
}
if (arr[i][j] < min) {
min = arr[i][j];
}
}
}
for (int i = maxRow; i < n; i += 1) {
for (int j = 0; j <= maxCol; j += 1) {
arr[i][j] = min;
}
}
}
void main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
print();
printf("_____________________\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> i * 10 + j\n");
printf("2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("4: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> 10 <20><><EFBFBD>\n");
printf("5: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 10 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> 10 <20><><EFBFBD>\n");
printf("6: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("7: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("8: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("9: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("10: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n");
printf("\n");
printf("0: <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >>>>>> ");
scanf_s("%d", &item);
switch (item) {
case 1:
fillx10();
break;
case 2:
fillzero();
break;
case 3:
randfill();
break;
case 4:
nch10();
break;
2024-11-07 08:45:54 +04:00
/*case 5:
2024-11-07 08:41:32 +04:00
kr10();
2024-11-07 08:45:54 +04:00
break;*/
2024-11-07 08:41:32 +04:00
case 6:
keyboardInput();
break;
case 7:
save();
load();
break;
case 8:
int num;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf_s("%d", &num);
deleteRow(num);
break;
case 9:
int nnum;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf_s("%d", &nnum);
dubCollum(nnum);
break;
case 10:
func();
break;
}
} while (item != 0);
}