newrepo/Source1.cpp

266 lines
5.6 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#define MAX_N 8
#define MAX_M 10
int arr[MAX_N][MAX_M];
int arr1[MAX_N][MAX_M*2];
int n = 0;
int m = 0;
int i, j, k, column;
void keyboardInput();
void print();
void fillIx10();
void fillZero();
void randFill0_9();
void NechetX10();
void Krat10();
void save();
void load();
void deleteRow(int delRow);
void ChetNet();
void main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
print();
printf("Âûáåðèòå íóæíóþ âàì îïåðàöèþ:\n");
printf("------------------------------\n");
printf("1: çàïîëíèòü çíà÷åíèÿìè i * 10 + j \n");
printf("2: çàïîëíèòü íóëÿìè\n");
printf("3: çàïîëíèòü ñëó÷àéíûìè çíà÷åíèÿìè\n");
printf("4: âñå íå÷¸òíûå óâåëè÷èòü â 10 ðàç\n");
printf("5: âñå êðàòíûå 10 óìåíüøèòü â 10 ðàç\n");
printf("6: ââåñòè ìàññèâ ñ êëàâèàòóðû\n");
printf("7: ñîõðàíèòü ìàññèâ\n");
printf("8: çàãðóçèòü ìàññèâ\n");
printf("9: óäàëèòü çàäàííóþ ñòðîêó\n");
printf("10: ïðîäóáëèðîâàòü çàäàííûé ñòîëáåö\n");
printf("11: îáíóëèòü ýëåìåíòû òåõ ñòîëáöîâ, â êîòîðûõ íåò íè îäíîãî ÷åòíîãî ýëåìåíòà\n");
printf("\n");
printf("0: Âûéòè èç ïðîãðàììû\n");
printf("Âûáðàííàÿ îïåðàöèÿ >>>>>> ");
scanf_s("%d", &item);
switch (item) {
case 1:
fillIx10();
break;
case 2:
fillZero();
break;
case 3:
{
randFill0_9();
break;
}
break;
case 4:
{
NechetX10();
break;
}
case 5:
{
Krat10();
}break;
case 6:
{
keyboardInput();
break;
}
case 7:
{
save();
break;
}
break;
case 8:
{
load();
break;
}
case 9:
int num;
printf("Íîìåð ñòðîêè, êîòîðóþ íóæíî óäàëèòü: ");
scanf_s("%d", &num);
deleteRow(num);
print();
break;
case 10:
{
int a = 0;
printf("Íîìåð äóáëèðóåìîãî ñòîëáöà = ");
scanf_s("%d", &a);
for (int i = 0; i < n; i++) {
for (int j = a; j < (m + 1); j++) {
arr[i][m] = arr[i][a];
}
}
m++;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
}break;
case 11:
{
ChetNet();
}break;
}
} while (item != 0);
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("m = ");
scanf_s("%d", &m);
printf("input values: ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf_s("%d", &arr[i][j]);
}
}
}
void print() {
printf("!!!! print() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%3d ", arr[i][j]);
}
printf("\n");
}
}
void fillIx10() {
printf("!!!! fillIx10() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = i * 10 + j;
}
}
}
void fillZero() {
printf("!!!! fillZero() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = 0;
}
}
}
void randFill0_9() {
printf("!!!! randFill0_9() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = rand() % 10;
}
}
}
void NechetX10() {
printf("!!!! NechetX10() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] % 2 != 0)
{
arr[i][j] *= 10;
}
}
}
}
void Krat10() {
printf("!!!! Krat10() !!!!\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] % 10 == 0)
{
arr[i][j] /= 10;
}
}
}
}
// Ñîõðàíåíèå ñîñòîÿíèÿ
void save() {
FILE* fout = fopen("d:\\zagryzka s interneta\\arr1.txt", "wt");
if (fout == NULL) {
printf("Âûõîäíîé ôàéë íå ñîçäàëñÿ");
return;
}
fprintf(fout, "%d ", n);
fprintf(fout, "%d\n", m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
fprintf(fout, "%d ", arr[i][j]);
}
fprintf(fout, "\n");
}
fclose(fout);
}
// Çàãðóçêà ñîñòîÿíèÿ
void load() {
FILE* fin = fopen("d:\\zagryzka s interneta\\arr1.txt", "rt");
if (fin == NULL) {
printf("Âõîäíîé ôàéë íå íàéäåí");
return;
}
fscanf(fin, "%d", &n);
fscanf(fin, "%d", &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
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++) {
// for (int j = 0; j < m; j++) {
// arr[i][j] = arr[i + 1][j];
// }
// }
// n--;
//}
//
//void ChetNet() {
// printf("!!!! ChetNet() !!!!\n");
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// if (arr[i][j] % 2 == 1) {
// arr[i][j] = 0;
// }
//
// }
// }
//}