|
#include <conio.h>
#include <io.h>
#include <fstream.h>
#include <iostream.h>
#include "koran\krnclass.h"
#include <time.h>
#include <dos.h>
short tabl[10][7]=
{ {0,0,0,1,0,0,1},
{0,0,1,0,0,0,1},
{0,0,1,0,1,1,1},
{0,0,1,1,0,1,1},
{0,0,1,1,1,0,1},
{0,1,0,0,1,1,1},
{0,1,0,1,0,1,1},
{0,1,0,1,1,0,1},
{0,1,1,0,0,1,1},
{0,1,1,0,1,0,1}};
short checktabl[56][6]=
{
{1,1,1,1,1,1}, //*
{0,0,0,0,0,0},
{1,0,0,0,0,0},
{0,1,0,0,0,0},//1
{0,0,1,0,0,0},
{0,0,0,1,0,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{0,0,0,0,1,0},
{0,0,0,0,0,1},
{1,1,0,0,0,0},//2
{1,0,1,0,0,0},
{1,0,0,1,0,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{1,0,0,0,1,0},
{1,0,0,0,0,1},
{0,1,1,0,0,0},//3
{0,1,0,1,0,0},
{0,1,0,0,1,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{0,1,0,0,0,1},
{0,0,1,1,0,0},
{0,0,1,0,1,0},//4
{0,0,1,0,0,1},
{0,0,0,1,1,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{0,0,0,1,0,1},
{0,0,0,0,1,1},
{1,1,1,0,0,0},//5
{1,1,0,1,0,0},
{1,1,0,0,1,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{1,1,0,0,0,1},
{1,0,1,1,0,0},
{1,0,1,0,1,0},//6
{1,0,1,0,0,1},
{1,0,0,1,1,0},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{1,0,0,1,0,1},
{1,0,0,0,1,1},
{0,1,1,1,0,0},//7
{0,1,1,0,1,0},
{0,1,1,0,0,1},
{1,1,1,1,1,1}, //*
{1,1,1,1,1,1}, //*
{0,1,0,1,1,0},
{0,1,0,1,0,1},
{0,1,0,0,1,1},//8
{0,0,1,1,1,0},
{0,0,1,1,0,1},
{1,1,1,1,1,1}, //*
};
void titul()
{
clrscr();
cout<< "Der Diplomprojekt v.1.2 'Koran' Mishel Kozak\n\n";
}
//----------------------------------------------
//
// Methode fur Klasse
//
//----------------------------------------------
void BarCode::init(char* mas,char fl)
{
int i;
flag=fl;
f1=1;
f2=2;
for(i=0;i<7;i++)
{cod[i]=mas[i]-48;
pcode[i]=mas[i];
};
cod[7]=0;
err=0;
ferr=0;
nferr=0;
warning=0;
}
//----------------------------------------------
void BarCode::getmytime()
{
struct tm mytm;
struct time tt;
struct date dd;
char* sss;
gettime(&tt);
getdate(&dd);
mytm.tm_sec=0;
mytm.tm_wday=0;
mytm.tm_year=0;
mytm.tm_isdst=0;
mytm.tm_min=tt.ti_min;
mytm.tm_hour=tt.ti_hour;
mytm.tm_mday=dd.da_day;
mytm.tm_mon=dd.da_mon-1;
mytm.tm_year=dd.da_year-1900;
int ii,jj;
sss=asctime(&mytm);
for(ii=3,jj=0;jj<25;ii++,jj++)
textdata[jj]=sss[ii];
// textdata[jj++]='\n';
// textdata[jj++]='\0';
}
//----------------------------------------------
void BarCode::save(char* pstr,BarCode* bco)
{
ofstream rootf(pstr,ios::binary);
if(rootf)
{
rootf.write((char*)bco,sizeof(*bco));
// rootf.write((char*)&bcode,sizeof(bcode));
}
else
{
cout<<"Error open file: "<<pstr;
}
}
//----------------------------------------------
void BarCode::read(char* pstr,BarCode* bco)
{
ifstream rootf(pstr,ios::binary);
if(rootf)
{
rootf.read((char*)bco,sizeof(*bco));
}
else
{
cout<<"Error open file: "<<pstr;
}
}
//----------------------------------------------
void BarCode::checksum()
{
cod[7]=(cod[0]+cod[2]+cod[4]+cod[6]+3*(cod[1]+cod[3]+cod[5]))%10;
pcode[7]=cod[7]+48;
// titul();
// cout<<"\n Code: "<<pcode[0]<<" "<<pcode[1]<<" "<<pcode[2]<<" "<<pcode[3]<<" "<<pcode[4];
// cout<<" "<<pcode[5]<<" "<<pcode[6]<<" "<<pcode[7]<<"\n\n";
}
//----------------------------------------------
short BarCode::next()
{
if(cod[6]!=9) { cod[6]++; pcode[6]++;}
else
{
if(cod[5]!=9) { cod[5]++; pcode[5]++; }
else
{
if(cod[4]!=9) {cod[4]++;pcode[4]++;}
else
{
if(cod[3]!=9) {cod[3]++;pcode[3]++;}
else
{
if(cod[2]!=9) {cod[2]++;pcode[2]++;}
else
{
if(cod[1]!=9) {cod[1]++;pcode[1]++;}
else
{
if(cod[0]!=9) {cod[0]++;pcode[0]++;}
else return(0);
cod[1]=0;
pcode[1]='0';
};
cod[2]=0;
pcode[2]='0';
};
cod[3]=0;
pcode[3]='0';
};
cod[4]=0;
pcode[4]='0';
};
cod[5]=0;
pcode[5]='0';
};
cod[6]=0;
pcode[6]='0';
};
return(1);
}
//----------------------------------------------
void BarCode::info()
{
{
titul();
getmytime();
cout<<" "<<textdata;
cout<<"\n Code: "<<pcode[0]<<" "<<pcode[1]<<" "<<pcode[2]<<" "<<pcode[3]<<" "<<pcode[4];
cout<<" "<<pcode[5]<<" "<<pcode[6]<<" "<<pcode[7]<<"\n\n";
cout<<"\n Code: "<<ecode[0]<<" "<<ecode[1]<<" "<<ecode[2]<<" "<<ecode[3]<<" "<<ecode[4];
cout<<" "<<ecode[5]<<" "<<ecode[6]<<" "<<ecode[7]<<"\n\n";
cout<<"\n Type error: "<<flag;
int i;
cout<<"\n - 1- 1- 1- 1- 1- 1- 1- 1-1 -1 -1 -1-\n ";
cout<<"\n Real";
for(i=0;i<71;i++)
{
char ch;
if(masbit[i]==0) ch=219;
else ch=0;
cout<<ch;
};
cout<<"\nerror";
for(i=0;i<71;i++)
{
char ch;
if(errbit[i]==0) ch=219;
else ch=0;
cout<<ch;
};
cout<<"\n\n Total error: "<<err;
cout<<"\n = fatal error: "<<ferr<<" "<<ferr/(err/100)<<"%";
cout<<"\n = corectly error: "<<nferr<<" "<<nferr/(err/100)<<"%";
cout<<"\n = warning error: "<<warning<<" "<<warning/(err/100)<<"%";
cout<<"\n\n\n\n For exit press 'q'... ";
}
}
//----------------------------------------------
void BarCode::bitcode()
{
unsigned int i,j,s;
short tmpmas[6];
for(i=0;i<8;i++)
{
for(j=0;j<7;j++)
{
masbit[i*7+j]=tabl[(cod[i])][j];
};
};
for(i=0;i<6;i++)
{
s=0;
for(j=0;j<56;j++)
{
if(checktabl[j][i]==0)
{
s+=masbit[j];
};
};
tmpmas[i]=s%2;
};
masbit[56]=0;
masbit[57]=1;
masbit[58]=tmpmas[0];
masbit[59]=tmpmas[1];
masbit[60]=0;
masbit[61]=1;
masbit[62]=tmpmas[2];
masbit[63]=tmpmas[3];
masbit[64]=0;
masbit[65]=1;
masbit[66]=tmpmas[4];
masbit[67]=tmpmas[5];
masbit[68]=0;
masbit[69]=1;
masbit[70]=0;
for(i=0;i<71;i++) errbit[i]=masbit[i];
}
//------------------------------------------
void BarCode::gen_error()
{
if(flag=='1')
{
f1=1;
do
{
if(errbit[f1]==0) errbit[f1]=1;
else if(errbit[f1]==1) errbit[f1]=0;
test();
if(errbit[f1]==0) errbit[f1]=1;
else if(errbit[f1]==1) errbit[f1]=0;
f1++;
} while(f1<72);
};
if(flag=='2')
{
f1=1;
do
{
f2=f1+1;
do
{
if(errbit[f1]==0) errbit[f1]=1;
else if(errbit[f1]==1) errbit[f1]=0;
if(errbit[f2]==0) errbit[f2]=1;
else if(errbit[f2]==1) errbit[f2]=0;
test();
if(errbit[f1]==0) errbit[f1]=1;
else if(errbit[f1]==1) errbit[f1]=0;
if(errbit[f2]==0) errbit[f2]=1;
else if(errbit[f2]==1) errbit[f2]=0;
f2++;
} while(f2<72);
f1++;
} while(f1<71);
};
}
//----------------------------------------------
void BarCode::test()
{
short tmpmas[6];
short i,j,s;
short check[6]={1,1,1,1,1,1};
char testcod[8];
char test[71];
char testtab[7];
err++;
for(i=0;i<71;i++)
test[i]=errbit[i];
for(i=0;i<8;i++)
{
test[i*7]=0;
test[i*7+6]=1;
};
test[56]=0;
test[57]=1;
test[60]=0;
test[61]=1;
test[64]=0;
test[65]=1;
test[68]=0;
test[69]=1;
test[70]=0;
for(i=0;i<6;i++)
{
s=0;
for(j=0;j<56;j++)
{
if(checktabl[j][i]==0)
{
s+=test[j];
};
};
tmpmas[i]=s%2;
};
for(j=0;j<3;j++)
{
if(tmpmas[j*2]!=test[58+j*4]) check[j*2]=0;
if(tmpmas[j*2+1]!=test[59+j*4]) check[j*2+1]=0;
};
short n=0;
for(i=0;i<6;i++)
{
if(check[i]==0)
{
n++;
};
};
if(n>1) n=0;
else n=1;
switch (n)
{
case 0://якщо контрольна сума не спiвпадае
{
for(i=0;i<56;i++)
{
short eq=1;
for(j=0;j<6;j++)
{
if(check[j]!=checktabl[i][j])
{
eq=0;
break;
};
};
if(eq==1)
{
if(test[i]==1) test[i]=0;
else test[i]=1;
break;
};
};
};
case 1: //якщо контрольна сума спiвпадае
{
for(i=0;i<8;i++)
{
for(j=0;j<7;j++)
{
testtab[j]=test[i*7+j];
};
short eq2;
for(j=0;j<10;j++)
{
short eq=1;
eq2=0;
for(s=0;s<7;s++)
{
if(testtab[s]!=tabl[j][s])
{
eq=0;
break;
};
};
if(eq==1)
{
testcod[i]=j;
eq2=1;
break;
}
};
if(eq2==0)
{
ferr++;
return;
}
};
short t;
t=(testcod[0]+testcod[2]+testcod[4]+testcod[6]+3*(testcod[1]+testcod[3]+testcod[5]))%10;
if(t!=testcod[7])
{
ferr++;
return;
};
for(i=0;i<8;i++)
{
if(testcod[i]!=cod[i])
{
for(j=0;j<8;j++) ecode[j]=testcod[j]+48;
warning++;
info();
return;
};
};
nferr++;
return;
};
};
}
Дата добавления: 2015-07-21; просмотров: 41 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
KORAN.CPP | | | Опис програми |