Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "encoder.h"
using namespace std;
encoder::encoder()
{
Reg[0] = 0;
Reg[1] = 0;
Reg[2] = 0;
}
encoder::~encoder()
{}
void encoder::inputKey() {
cout << "select yes/no for text file" << endl;
cin >> begin;
while (begin != "yes"&& begin != "Yes" && begin != "no"&& begin != "NO")
{
cout << "select Yes/No" << endl;
cin >> begin;
}
if (begin == "yes" || begin == "YES")
{
cout << " Enter input file name" << endl;
cin >> inputFile;
input.open(inputFile);
if (input.good())
{
cout << " input file opening...... " << endl;
while (!input.eof())
{
getline(input, integer, ';');
if (integer.length() == 0)
{
break;
}
if (integer != "\n")
{
try { digit = stoi(integer); }
catch (const std::invalid_argument)
{
cout << "invalid input" << endl;
exit(EXIT_FAILURE);
}
catch (const std::out_of_range)
{
cout << "too big to fit buffer" << endl;
exit(EXIT_FAILURE);
}
if (digit < 0 || digit>1)
{
cout << "1/0 only" << endl;
exit(EXIT_FAILURE);
return;
}
}
action.buffer(digit);
}
}
else {
cout << "File not found" << endl;
exit(EXIT_FAILURE);
return;
}
}
else if (begin == "no" || begin == "NO")
{
cout << "select quantity of input" << endl;
cin >> quantity;
while (cin.fail()) {
cin.clear();
cin.ignore(INT_MAX, '\n');
cout << "Enter Number.\n";
cin >> quantity;
}
while (digit == 0)
{
cin.clear();
cin.ignore(INT_MAX, '\n');
cout << "select number different from 0.\n";
cin >> digit;
}
cout << "select 0 or 1";
for (int x = 0; x < quantity; x++)
{
cin >> digit;
while (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
cout << "Enter input 1 and 0 only.\n";
cout << "input number again.\n";
cin >> digit;
}
if (digit == 0 || digit == 1)
{
action.history(digit);
}
else {
cout << "0 and 1 only" << endl;
if (x > 0) {
x--;
}
}
}
}
input.close();
}
void encoder::calculate() {
for (int y = 0; y < action.under(); y++) {
Reg[2] = Reg[1];
Reg[1] = Reg[0];
Reg[0] = action.good(y);
action.buffer(Reg[0]);
action.buffer(Reg[1]);
action.buffer(Reg[2]);
action.build(Reg[0] ^ Reg[2]);
action.build(Reg[1] ^ Reg[2]);
action.build(Reg[0]);
}
}
void encoder::output() {
if ((action.under() == 0))
{
cout << "input file missing" << endl;
}
else {
cout << endl;
}
Trellis << "input: n/a, ";
for (int z = 0; z < action.under(); z++)
{
Trellis << action.good(z);
if (z < (action.under()) - 1)
{
Trellis << ", ";
}
}
Trellis << endl;
Trellis << "output: n/a";
for (int z = 0; z < action.out(); z++) {
if (z % 3 == 0)
{
Trellis << ", ";
}
Trellis << action.over(z);
}
Trellis << endl;
Trellis << "Current State" << endl;
for (int counter = 0; counter <= 7;counter++)
{
bitset<3>binary = counter;
Trellis << binary << "(" << counter << ") :";
for (int z = 0; z < action.out() + 1; z++) {
if (counter % 3 == 0)
{
int mode = action.currentState(counter) * 4 + action.currentState(counter + 1) * 2 + action.currentState(counter + 2);
if (mode == counter) {
Trellis << "X:";
}
else
{
Trellis << " :";
}
}
}
Trellis << endl;
}
string data = Trellis.str();
cout << data;
cout<<"output the file yes or no"<<endl;
string reset;
cin >> reset;
if (reset == "yes" || reset == "YES")
{
ofstream Final;
Final.open("trellis.txt");
Final << data;
Final.close();
}
else {
cout << "error output file" << endl;
}
}