C ++ uses two basic parameters for arithmetic coding: the probability of a symbol and Its Encoding interval. The probability of a source symbol determines the compression encoding efficiency and the interval of the source symbol in the coding process, the encoding interval determines the output after the compressed symbol.
In C ++ arithmetic coding, the input is a symbol. The probability of each symbol also has a symbolic sequence to be encoded. The initial encoding interval can be calculated based on the probability. First, several variables are available at the end: high -- upper limit of the current encoding, Low -- lower limit of the current encoding, and high -- intermediate variable, used to calculate the upper limit of the current interval of the next encoding symbol, low -- intermediate variable, used to calculate the lower limit of the current interval of the next encoding symbol, d -- the distance between the current intervals.
The current interval of the 1st encoding symbols is its initial encoding interval, and the current interval of the I encoding symbol is [Low, High) after the I-1 ), the current interval algorithm for the I + 1 encoding symbol is as follows: high = Low + d * the upper limit corresponding to the I + 1 Initial encoding symbol, low = Low + d * lower limit corresponding to the I + 1 encoding symbol, and then the probability of High = high, Low = low, d = d * encoding symbol I.
The encoding procedure is as follows:
- #include <iostream.h>
- #define M 100
- #define N 4
- class suanshu
- {
- int count,length;
- char number[N],n;
- long double chance[N],c;
- char code[M];
- long double High,Low,high,low,d;
- public:
- suanshu()
- {High=0;Low=0;}
- void get_number();
- void get_code();
- void coding();
- ~suanshu(){}
- };
-
- void suanshu::get_number()
- {
- cout<<"please input the number and its chance."<<endl;
- for(int i=0;i<N;i++)
- {
- cin>>n>>c;
- number[i]=n;
- chance[i]=c;
- }
- if(i==20)
- cout<<"the number is full."<<endl;
- count=i;
- }
This C ++ arithmetic code is run in VC6.0 and xp Professional Edition. This is my first time to write a complete program in c ++, but it is still somewhat unsatisfactory, for example, variable and function names are not very professional, so you will pay attention to them later.
- Differences between standard input implementation methods in C and C ++
- How does the C ++ compiler allocate storage space for Const constants?
- Basic Conception and method of C ++ Class Library Design
- Several Methods for converting C ++ Language
- How to better compile C ++ code