#include <iostream.h>
#include <stdlib.h>
#include<iomanip>
#include<cstring>
using namespace std;
class iter_code {
int inform_num[6][9],
dec_num[4]; // ,
char nomer_zalikovky[8];
public:
iter_code ( char in_num[]);
void form_dec_num ();
void control_rozryad(int r, int s);
void bin_num (); //
void show_code(int c);
void vnesenja_spotvoren ();
void vyjavlennja_spotoren();
int vvod ( char k) ;
};
bool Continue();
iter_code::iter_code ( char in_num[]) {
strcpy(nomer_zalikovky,in_num);
}
void iter_code::form_dec_num () {
int suma=0, k=6 ,j;
char value[1];
value[0]= nomer_zalikovky[k];
suma= atoi(value);
for( int i=0; i<4; i++ ) {
--k;
value[0]= nomer_zalikovky[k];
suma+= atoi(value) ;
dec_num[i]= suma;
}
}
void iter_code::bin_num (){
for(int i=0; i<4; i++) {
int j=6;
while (dec_num[i] >= 2 ) {
inform_num[i][j]= ( dec_num[i] % 2);
dec_num[i] /= 2;
j--;
};
inform_num[i][j]= dec_num[i];
j--;
if ( j>=0 ){
while(j>=0) {
inform_num[i][j]=0;
j--;
}
}
}
}
void iter_code::control_rozryad(int r,int s){ // r - s -
//
int i,j, suma;
for( i=0; i<r; i++){
suma=0;
for( j=0; j<s; j++) {
suma+=inform_num[i][j];
};
suma%2==0 ? inform_num[i][s]=0 : inform_num[i][s]=1;
}
//
for( j=0;j<s;j++){
suma=0;
for(i=0; i<r; i++){
suma+=inform_num[i][j];
}//
suma%2==0 ? inform_num[r][j]=0 : inform_num[r][j]=1;
};
suma=0;
for(i=0; i<r; i++) {
suma+= inform_num[i][s];
}
suma%2==0 ? inform_num[r][s]=0 : inform_num[r][s]=1;
}
void iter_code::show_code(int k){
for(int i=0; i<(4+k); i++) {
for(int j=0;j<(7+k);j++){
cout<<setw(2)<<inform_num[i][j];
// cout<<"\t\t"<<k;
}
cout<<endl;
}
cout<<endl;
}
void iter_code::vnesenja_spotvoren () {
int i,j;
bool choice=true;
cout<<"Vy bazhaete vnesty spotorenja? ";
//cin.ignore(100, '\n');
choice=Continue();
while (choice) {
cout<<"\n\nVVedit nomer rjadka i stovbcya\n";
cout<<"v jakyi vnosytsia spotvorenja\n";
cout<<setw(20)<<" nomer rjdka: (1-5)\n";
cout<<setw(20)<<" nomer stovbcya: (1-8)\n";
while (choice) {
i=vvod('5');
j=vvod('8');
inform_num[i-1][j-1]== 0 ? inform_num[i-1][j-1]= 1 : inform_num[i-1][j-1]= 0;
cout<<" do you wish to continue? ";
choice = Continue();
}
}
}
void iter_code::vyjavlennja_spotoren() {
int i,j,suma_r=0,suma_s=0;
bool result=true;
for (i=0; i<5; i++) {
if(inform_num[i][8]==1) {
result=false;
break;
}
}
for (j=0; j<8; j++) {
if(inform_num[5][j]==1) {
result=false;
break;
}
} ;
if (result)
cout<<setw(20)<<"\nSPOTVOREN NEMA\n";
else
cout<<setw(20)<<"\nVYJAVLENE SPOTVORENNJA\n";
}
int iter_code::vvod ( char k) {
char ch, ch1[2];
char *word;
if (k=='5')
word="rjadka ";
else
word="stovbcya";
do {
cout<<"\n nomer "<<word<<"(1-"<<k<<"): ";
cin.get(ch);
cin.ignore(100,'\n');
} while ( ch < '1' || ch > k);
ch1[0]=ch;
ch1[1]='\0';
return atoi(ch1);
}
bool Continue() {
char ch;
bool choice;
do {
cout<<"(Y/N) ";
cin.get(ch);
cin.ignore(100, '\n');
} while ( ch!='Y' && ch!='y' && ch!= 'N' && ch!='n');
if ( ch=='Y' || ch=='y')
choice = true;
else
choice = false;
return (choice);
}
void enter_num (char num[]){
int k;
bool ok=false;
cout <<"vvedit nomer zalikovoi knyzky\n";
while (ok==false) {
cin>>num;
cin.ignore(100, '\n');
if (strlen(num)!=7 ) {
cout<<"\n\t enter 7 value\n";
continue;
}
ok=true;
for (int i=0; num[i]!= '\0'; i++) {
if (num[i] < '0' || num[i] > '9') {
cout<<"enter value\n" ;
ok=false;
}
}
};
}
int main() {
int i ,k , numbers[4];
char *num_zalikov;
enter_num(num_zalikov);
iter_code o1( num_zalikov );
cout<<endl;
o1.form_dec_num ();
o1.bin_num ();
o1.show_code(0);
o1.control_rozryad(4,7);
o1.show_code(1);
do {
o1.vnesenja_spotvoren ();
o1.control_rozryad(5,8);
cout<<endl;
o1.show_code(2);
cout<<endl;
o1.vyjavlennja_spotoren();
cout<<"\n EXIT PROGRAM? ";
} while (!Continue());
return 0;
};