lab9
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,7 @@
|
||||
// GET
|
||||
int mainget(void);
|
||||
int numget(void);
|
||||
int getsymb(int *b,wchar_t *buff);
|
||||
|
||||
// MASSIVE
|
||||
void seeMassive(wchar_t (*massive)[COL]);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef FUNC
|
||||
#define FUNC
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
#define COL 10
|
||||
#define ROW 10
|
||||
|
||||
// GET
|
||||
int mainget(void);
|
||||
int numget(void);
|
||||
int getsymb(wchar_t *buff);
|
||||
|
||||
// MASSIVE
|
||||
void seeMassive(wchar_t (*massive)[COL]);
|
||||
void setMassive(int x, wchar_t (*massive)[COL]);
|
||||
void func(int x, wchar_t (*massive)[COL]);
|
||||
|
||||
// MENU
|
||||
void helpMenu(void);
|
||||
void setMenu(void);
|
||||
void funcMenu(void);
|
||||
|
||||
// SPECIAL
|
||||
void clear(void);
|
||||
int flush(void);
|
||||
int end(int c);
|
||||
|
||||
#endif
|
||||
@@ -1,17 +1,18 @@
|
||||
#include "func.h"
|
||||
|
||||
int mainget(void){
|
||||
int t,x,y=0,num=0;
|
||||
int t=0,x,y=0,num=0;
|
||||
unsigned long input = 0;
|
||||
while(
|
||||
((x=getchar())>=32 && t<100)
|
||||
&& ((x>='a' && x<='z')
|
||||
|| (x>='0' && x<= '9')
|
||||
|| (x>='A' && x<='Z'))){
|
||||
// printf("%d %lu ",x,input);
|
||||
if(x>='a' && x<='z') {x -=('a'-'A');t--;}
|
||||
if(x>='A' && x<='Z') {input = (input*100)+(x);t--;}
|
||||
// printf("%d %lu\n",x,input);
|
||||
if(input>1000000000000000000){printf("input err\n\n");flush();input=0;t--;}
|
||||
|
||||
if(x>='0' && x<='9'&&num<147483647){num = (num*10)+(x-'0');t--;}
|
||||
else if(num>147483647){printf("num is too big!\n\n");num = 0;t--;}
|
||||
if(t<0)t=0;
|
||||
@@ -25,7 +26,6 @@ int mainget(void){
|
||||
int help = 72697680;
|
||||
|
||||
int show = 83727987;
|
||||
int see = 836969;
|
||||
|
||||
int set = 836984;
|
||||
|
||||
@@ -51,8 +51,32 @@ int mainget(void){
|
||||
if(y==3&&(num>=10&&num<=21)) y = 300+num;
|
||||
|
||||
y=(input == show)?4:y;
|
||||
y=(input == see)?4:y;
|
||||
y=(input == 'C')?4:y;
|
||||
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int getsymb(int *b,wchar_t *buff){
|
||||
int t;
|
||||
*b=0;
|
||||
wchar_t x;
|
||||
while((x=getchar())!=end(x)&&x!='\n'&&x!=' '&&*b<5){
|
||||
if(x=='/n')x=' ';
|
||||
*(buff+*b) = x;
|
||||
*b++;
|
||||
}
|
||||
//if(end(x)){flush();return -1;}
|
||||
|
||||
t=0;
|
||||
if(*buff=='-'){
|
||||
for(int i = 1; i<4;i++){
|
||||
if(*(buff+i)>='0'&&*(buff+i)<='9')t++;
|
||||
}
|
||||
if(*(buff+4)=='-')
|
||||
if(t==4)return 1;
|
||||
}
|
||||
t=0;
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "func.h"
|
||||
|
||||
int mainget(void){
|
||||
int t=0,x,y=0,num=0;
|
||||
unsigned long input = 0;
|
||||
while(
|
||||
((x=getchar())>=32 && t<100)
|
||||
&& ((x>='a' && x<='z')
|
||||
|| (x>='0' && x<= '9')
|
||||
|| (x>='A' && x<='Z'))){
|
||||
// printf("%d %lu ",x,input);
|
||||
if(x>='a' && x<='z') {x -=('a'-'A');t--;}
|
||||
if(x>='A' && x<='Z') {input = (input*100)+(x);t--;}
|
||||
// printf("%d %lu\n",x,input);
|
||||
if(input>1000000000000000000){printf("input err\n\n");flush();input=0;t--;}
|
||||
if(x>='0' && x<='9'&&num<147483647){num = (num*10)+(x-'0');t--;}
|
||||
else if(num>147483647){printf("num is too big!\n\n");num = 0;t--;}
|
||||
if(t<0)t=0;
|
||||
t++;
|
||||
if(end(x))return -1;
|
||||
}
|
||||
|
||||
if(end(x))return -1;
|
||||
|
||||
int exit = 69887384;
|
||||
int help = 72697680;
|
||||
|
||||
int show = 83727987;
|
||||
|
||||
int set = 836984;
|
||||
|
||||
int func = 70857867;
|
||||
|
||||
|
||||
y=(input == exit)?-1:y;
|
||||
y=(input == 'Q')?-1:y;
|
||||
|
||||
y=(input == help)?1:y;
|
||||
y=(input == 'H')?1:y;
|
||||
|
||||
|
||||
y=(input == set)?2:y;
|
||||
y=(input == 'S')?2:y;
|
||||
if(y==2&&(num>=1&&num<=9)) y = 20+num;
|
||||
if(y==2&&(num==10)) y = 200+num;
|
||||
|
||||
|
||||
y=(input == func)?3:y;
|
||||
y=(input == 'F')?3:y;
|
||||
if(y==3&&(num>=1&&num<=9)) y = 30+num;
|
||||
if(y==3&&(num>=10&&num<=21)) y = 300+num;
|
||||
|
||||
y=(input == show)?4:y;
|
||||
y=(input == 'C')?4:y;
|
||||
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int getsymb(int *b,wchar_t *buff){
|
||||
int t;
|
||||
*b=0;
|
||||
wchar_t x;
|
||||
while((x=getchar())!=end(x)&&x!='\n'&&x!=' '&&*b<5){
|
||||
if(x=='/n')x=' ';
|
||||
*(buff+*b) = x;
|
||||
*b++;
|
||||
}
|
||||
//if(end(x)){flush();return -1;}
|
||||
|
||||
t=0;
|
||||
if(*buff=='-'){
|
||||
for(int i = 1; i<4;i++){
|
||||
if(*(buff+i)>='0'&&*(buff+i)<='9')t++;
|
||||
}
|
||||
if(*(buff+4)=='-')
|
||||
if(t==4)return 1;
|
||||
}
|
||||
t=0;
|
||||
printf("\nx ");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
@@ -13,17 +13,67 @@ void seeMassive(wchar_t (*massive)[COL]){
|
||||
}
|
||||
putchar('\n');putchar('\n');
|
||||
}
|
||||
|
||||
printf("\n\nInput: ");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void setMassive(int x, wchar_t (*massive)[COL]){
|
||||
int b,c,o,e,cell=0;
|
||||
wchar_t buff[5];
|
||||
switch(x){
|
||||
case 21:
|
||||
for(int col = 0;col<COL;col++){
|
||||
for(int row = 0;row<ROW;row++){
|
||||
o = *(*(massive+col)+row);
|
||||
*(*(massive+col)+row) = 'X';
|
||||
seeMassive(massive);
|
||||
printf("Massive Input: ");
|
||||
|
||||
e=getsymb(&b,buff);
|
||||
if(e==-1)c=' ';
|
||||
|
||||
if(e==1){
|
||||
for(int i = 1;i<4;i++)
|
||||
cell = (cell*10)+(buff[i]-'0');
|
||||
if(cell>ROW*COL-1)
|
||||
printf("Error cell cannot be bigger %d",ROW*COL-1);
|
||||
else while(cell>0){
|
||||
col = row = 0;
|
||||
if(col<COL)col++;
|
||||
else {row++;col=0;}
|
||||
}
|
||||
}
|
||||
|
||||
if(e==0){
|
||||
for(int i = 0;i<b;i++){
|
||||
if(col<COL){
|
||||
printf("Z");
|
||||
*(*(massive+col)+row)=buff[i];
|
||||
col++;
|
||||
getchar();
|
||||
}
|
||||
else if(row<ROW){
|
||||
col=0;
|
||||
row++;
|
||||
*(*(massive+col)+row)=buff[i];
|
||||
}
|
||||
else c = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if(c==' '){*(*(massive+col)+row) = o;break;}
|
||||
}
|
||||
if(c==' ')break;
|
||||
}
|
||||
helpMenu();
|
||||
break;
|
||||
default:printf("Eror setmassive-%d\n",x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void func(int x, wchar_t (*massive)[COL]){
|
||||
switch(x){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "func.h"
|
||||
|
||||
void seeMassive(wchar_t (*massive)[COL]){
|
||||
printf("\t\t\tMassive\n\n[ ] ");
|
||||
for(int i = 0;i<COL;i++)
|
||||
printf("[%d] ",i);
|
||||
putchar('\n');putchar('\n');
|
||||
|
||||
for(int i = 0;i<ROW;i++){
|
||||
printf("[%d] ",i);
|
||||
for(int j = 0;j<COL;j++){
|
||||
printf("[%lc] ",*(*(massive+i)+j));
|
||||
}
|
||||
putchar('\n');putchar('\n');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void setMassive(int x, wchar_t (*massive)[COL]){
|
||||
int b,c,o,e,cell=0;
|
||||
wchar_t buff[5];
|
||||
switch(x){
|
||||
case 21:
|
||||
for(int col = 0;col<COL;col++){
|
||||
for(int row = 0;row<ROW;row++){
|
||||
o = *(*(massive+col)+row);
|
||||
*(*(massive+col)+row) = 'X';
|
||||
seeMassive(massive);
|
||||
printf("Massive Input: ");
|
||||
|
||||
e=getsymb(&b,buff);
|
||||
if(e==-1)c=' ';
|
||||
|
||||
if(e==1){
|
||||
for(int i = 1;i<4;i++)
|
||||
cell = (cell*10)+(buff[i]-'0');
|
||||
if(cell>ROW*COL-1)
|
||||
printf("Error cell cannot be bigger %d",ROW*COL-1);
|
||||
else while(cell>0){
|
||||
col = row = 0;
|
||||
if(col<COL)col++;
|
||||
else {row++;col=0;}
|
||||
}
|
||||
}
|
||||
|
||||
if(e==0){
|
||||
for(int i = 0;i<b;i++){
|
||||
if(col<COL){
|
||||
printf("Z");
|
||||
*(*(massive+col)+row)=buff[i];
|
||||
col++;
|
||||
}
|
||||
else if(row<ROW){
|
||||
col=0;
|
||||
row++;
|
||||
*(*(massive+col)+row)=buff[i];
|
||||
}
|
||||
else c = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if(c==' '){*(*(massive+col)+row) = o;break;}
|
||||
}
|
||||
if(c==' ')break;
|
||||
}
|
||||
helpMenu();
|
||||
break;
|
||||
default:printf("Eror setmassive-%d\n",x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void func(int x, wchar_t (*massive)[COL]){
|
||||
switch(x){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ void helpMenu(void){
|
||||
clear();
|
||||
printf("Command [alias] - what it does.\n\n");
|
||||
printf("\thelp [h] - Show this info.\n\n");
|
||||
printf("\tshow [see] - Show the 2d array\n\n");
|
||||
printf("\tshow [c] - Show the 2d array\n\n");
|
||||
printf("\tset [s] - Show all methods to fill the 2d array.\n");
|
||||
printf("\tset* [s*] - Choose how to fill the 2d array\n\n");
|
||||
printf("\tfunc [f] - Show all functions\n");
|
||||
@@ -14,8 +14,42 @@ void helpMenu(void){
|
||||
|
||||
void setMenu(void){
|
||||
clear();
|
||||
printf("Fill 2d massive methods\n");
|
||||
printf("\t [1] - Row‑wise left‑to‑right input.\n");
|
||||
printf("\t [2] - Row‑wise right‑to‑left input.\n\n");
|
||||
printf("\t *[3] - Column‑wise top‑to‑bottom input.\n");
|
||||
printf("\t [4] - Column‑wise bottom‑to‑top input.\n\n");
|
||||
printf("\t [5] - Spiral from outer edge toward centre.\n");
|
||||
printf("\t [6] - Spiral from centre outward.\n\n");
|
||||
printf("\t [7] - Diagonal input starting at bottom‑left corner.\n");
|
||||
printf("\t [8] - Diagonal input starting at top‑right corner.\n");
|
||||
printf("\t [9] - Diagonal input starting at top‑left corner.\n");
|
||||
printf("\t[10] - Diagonal input starting at bottom‑right corner.\n\n\n");
|
||||
}
|
||||
|
||||
void funcMenu(void){
|
||||
clear();
|
||||
printf("Functions\n");
|
||||
printf("\t [1] - Find the maximum and minimum elements of the matrix.\n");
|
||||
printf("\t [2] - Find the maximum value in each row and in each column of the matrix.\n\n");
|
||||
printf("List elements\n");
|
||||
printf("\t [3] - ... whose values are greater than a given k.\n");
|
||||
printf("\t [4] - ... whose values are less than a given k.\n");
|
||||
printf("\t [5] - ... greater than k in columns m through l.\n");
|
||||
printf("\t [6] - ... greater than k in rows m through l.\n");
|
||||
printf("\t [7] - ... less than k in columns m through l.\n");
|
||||
printf("\t [8] - ... less than k in rows m through l.\n");
|
||||
printf("\t [9] - ... whose values lie between the matrix's minimum and maximum values.\n");
|
||||
printf("\t*[10] - ... that are multiples of the entered number k\n\t\t(k < matrix max; also display the matrix's maximum value).\n\n");
|
||||
printf("Compute the sum of\n");
|
||||
printf("\t[11] - ... all even elements of the matrix.\n");
|
||||
printf("\t[12] - ... odd elements of the matrix.\n");
|
||||
printf("\t[13] - ... elements that are multiples of k.\n");
|
||||
printf("\t[14] - ... elements in even‑indexed columns of the matrix.\n");
|
||||
printf("\t[15] - ... elements in odd‑indexed columns of the matrix.\n");
|
||||
printf("\t*[16] - ... elements in even‑indexed rows of the matrix.\n");
|
||||
printf("\t[17] - ... elements in odd‑indexed rows of the matrix.\n");
|
||||
printf("\t[18] - ... elements on and above the main diagonal (inclusive).\n");
|
||||
printf("\t[19] - ... elements on and below the main diagonal (inclusive).\n");
|
||||
printf("\t[20] - ... elements on both the main and secondary diagonals of the matrix.\n\n\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "func.h"
|
||||
|
||||
void helpMenu(void){
|
||||
clear();
|
||||
printf("Command [alias] - what it does.\n\n");
|
||||
printf("\thelp [h] - Show this info.\n\n");
|
||||
printf("\tshow [c] - Show the 2d array\n\n");
|
||||
printf("\tset [s] - Show all methods to fill the 2d array.\n");
|
||||
printf("\tset* [s*] - Choose how to fill the 2d array\n\n");
|
||||
printf("\tfunc [f] - Show all functions\n");
|
||||
printf("\tfunc* [f*] - Choose a function.\n\n");
|
||||
printf("\texit [q] - Quite the program.\n\n\n");
|
||||
}
|
||||
|
||||
void setMenu(void){
|
||||
clear();
|
||||
printf("Fill 2d massive methods\n");
|
||||
printf("\t [1] - Row‑wise left‑to‑right input.\n");
|
||||
printf("\t [2] - Row‑wise right‑to‑left input.\n\n");
|
||||
printf("\t *[3] - Column‑wise top‑to‑bottom input.\n");
|
||||
printf("\t [4] - Column‑wise bottom‑to‑top input.\n\n");
|
||||
printf("\t [5] - Spiral from outer edge toward centre.\n");
|
||||
printf("\t [6] - Spiral from centre outward.\n\n");
|
||||
printf("\t [7] - Diagonal input starting at bottom‑left corner.\n");
|
||||
printf("\t [8] - Diagonal input starting at top‑right corner.\n");
|
||||
printf("\t [9] - Diagonal input starting at top‑left corner.\n");
|
||||
printf("\t[10] - Diagonal input starting at bottom‑right corner.\n\n\n");
|
||||
}
|
||||
|
||||
void funcMenu(void){
|
||||
clear();
|
||||
printf("Functions\n");
|
||||
printf("\t [1] - Find the maximum and minimum elements of the matrix.\n");
|
||||
printf("\t [2] - Find the maximum value in each row and in each column of the matrix.\n\n");
|
||||
printf("List elements\n");
|
||||
printf("\t [3] - ... whose values are greater than a given k.\n");
|
||||
printf("\t [4] - ... whose values are less than a given k.\n");
|
||||
printf("\t [5] - ... greater than k in columns m through l.\n");
|
||||
printf("\t [6] - ... greater than k in rows m through l.\n");
|
||||
printf("\t [7] - ... less than k in columns m through l.\n");
|
||||
printf("\t [8] - ... less than k in rows m through l.\n");
|
||||
printf("\t [9] - ... whose values lie between the matrix's minimum and maximum values.\n");
|
||||
printf("\t*[10] - ... that are multiples of the entered number k\n\t\t(k < matrix max; also display the matrix's maximum value).\n\n");
|
||||
printf("Compute the sum of\n");
|
||||
printf("\t[11] - ... all even elements of the matrix.\n");
|
||||
printf("\t[12] - ... odd elements of the matrix.\n");
|
||||
printf("\t[13] - ... elements that are multiples of k.\n");
|
||||
printf("\t[14] - ... elements in even‑indexed columns of the matrix.\n");
|
||||
printf("\t[15] - ... elements in odd‑indexed columns of the matrix.\n");
|
||||
printf("\t*[16] - ... elements in even‑indexed rows of the matrix.\n");
|
||||
printf("\t[17] - ... elements in odd‑indexed rows of the matrix.\n");
|
||||
printf("\t[18] - ... elements on and above the main diagonal (inclusive).\n");
|
||||
printf("\t[19] - ... elements on and below the main diagonal (inclusive).\n");
|
||||
printf("\t[20] - ... elements on both the main and secondary diagonals of the matrix.\n\n\n");
|
||||
}
|
||||
Reference in New Issue
Block a user