Question

If the name of your program is ENCODE and the data file name is INPUT.DATA, then executing ENCODE INPUT.DATA” will encode th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ManchesterEncoding.cpp File (Program with comments for understanding):

#include<iostream>
#include<stdlib.h>
#include<fstream>
#include<vector>
#include<string>
using namespace std;
//function to encode argument string into manchester encoding
string manchesterEncoding(string data){
string encString = "", zero="|+V-V", one="|-V+V";
for(char i=0;i<data.size();i++){   //traverse char by char
if(((int)data[i] - '0')==0){   //if 0 then write high to low
encString.append(zero);
}else if(((int)data[i] - '0')==1){   //if 1 then write low to high
encString.append(one);
}else{   //otherwise exit and return invalid data string
return "Invalid Data";
}
}
encString.append("|");
return encString;   //return the converted string
}
int main(int argc, char* argv[]){
string line;
if(argc!=2){   //if no input filename is given then exit
       cout<<"No File name given or Invalid Filename given";
       exit(0);
   }
  
ifstream fread(argv[1]);   //open and read the input file
ofstream fwrite("OUTPUT.SIGNAL");   //open output file for writing
if(fread && fwrite){   //if files opened successfully
while(fread){
getline(fread, line); //read input line
fwrite<<manchesterEncoding(line)<<endl;   //write encoded signal into output file
}
}else{   //if input or output file couldnt be opened
!fread?(cout<<"Read error"):(cout<<"Write error");
}
   //close the files
fread.close();
fwrite.close();
   cout<<"File written successfully";   //output the message
return 0;
}

INPUT.DATA file:

1001011 21010111010100111101001 3 100111010111000110OUTPUT.SIGNAL file:

1 2 3 4 5 | +V-V] +V-VI-V+V| +V-VI-V+VI-V+V| |-V+V+V-VI-V+VI+V-VI-V+VI-V+VI-V+V | +V-VI-V+V+V-VI-V+VI+V-VI +V-VI-V+VI-V+VI-V+

CONSOLE OUTPUT:

C:H. Command Prompt C:\Users\achar OneDrive\Documents\C++>g++ ManchesterEncoding.cpp -o ENCODE C:\Users\achar\OneDrive\Docume

Add a comment
Know the answer?
Add Answer to:
If the name of your program is ENCODE and the data file name is INPUT.DATA, then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • . Huffman Encoding (a.) (6 points) Suppose a certain file contains only the following letters with the corresponding frequencies 1 AİB 73 9 30 44 130 28 16 In a fixed-length encoding scheme, cach...

    . Huffman Encoding (a.) (6 points) Suppose a certain file contains only the following letters with the corresponding frequencies 1 AİB 73 9 30 44 130 28 16 In a fixed-length encoding scheme, cach character is given a binary representation with the same number of bits. What is the minimum number of bits required to represent each letter of this file under fixed-length encoding scheme? Describe how to encode all seven letters in this file using the number of bits...

  • (b.) Huffman code is a way to encode information using variable-length binary strings to represent symbols depending on the frequency of each individual letter. Specifically, letters that appear more...

    (b.) Huffman code is a way to encode information using variable-length binary strings to represent symbols depending on the frequency of each individual letter. Specifically, letters that appear more frequently can be encoded into strings of shorter lengths, while rarer letters can be turned into longer binary strings. On average, Huffman code is a more efficient way to encode a message as the number of bits in the output string will be shorter than if a fixed-length code was used....

  • PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set...

    PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is a run of 10 A’s. We could encode this run using a notation like *A10, where the * is a special flag character that indicates a run, A is the symbol in the run, and 10 is the length of the run. As another example, the string KKKKKKKKKKKKKBCCDDDDDDDDDDDDDDDKKKKKMNUUUGGGGG would be encoded...

  • C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file....

    C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file. To use records (an instance of a struct) To use Dynamic Memory Allocation To create and use a dynamically allocated array of structs To use enumerated types in a useful manner (more info given on Discussion board!) The Problem Bad economic times has forced the UCF administration to think outside the box for alternative methods of income. Specifically, we now have a UCF lottery,...

  • I need one file please (C++)(Stock Market) Write a program to help a local stock trading...

    I need one file please (C++)(Stock Market) Write a program to help a local stock trading company automate its systems. The company invests only in the stock market. At the end of each trading day, the company would like to generate and post the listing of its stocks so that investors can see how their holdings performed that day. We assume that the company invests in, say, 10 different stocks. The desired output is to produce two listings, one sorted...

  • Here are the data needed for the program. SanFrancisco.csv station_id,name,lat,long,dockcount,landmark,installation 41,Clay at Battery,37.795001,-122.39997,15,San Francisco,8/19/2013 42,Davis at Jac...

    Here are the data needed for the program. SanFrancisco.csv station_id,name,lat,long,dockcount,landmark,installation 41,Clay at Battery,37.795001,-122.39997,15,San Francisco,8/19/2013 42,Davis at Jackson,37.79728,-122.398436,15,San Francisco,8/19/2013 45,Commercial at Montgomery,37.794231,-122.402923,15,San Francisco,8/19/2013 46,Washington at Kearney,37.795425,-122.404767,15,San Francisco,8/19/2013 47,Post at Kearney,37.788975,-122.403452,19,San Francisco,8/19/2013 48,Embarcadero at Vallejo,37.799953,-122.398525,15,San Francisco,8/19/2013 49,Spear at Folsom,37.790302,-122.390637,19,San Francisco,8/20/2013 50,Harry Bridges Plaza (Ferry Building),37.795392,-122.394203,23,San Francisco,8/20/2013 SanJose.csv station_id,name,lat,long,dockcount,landmark,installation 2,San Jose Diridon Caltrain Station,37.329732,-121.901782,27,San Jose,8/6/2013 3,San Jose Civic Center,37.330698,-121.888979,15,San Jose,8/5/2013 4,Santa Clara at Almaden,37.333988,-121.894902,11,San Jose,8/6/2013 5,Adobe on Almaden,37.331415,-121.8932,19,San Jose,8/5/2013 6,San Pedro Square,37.336721,-121.894074,15,San Jose,8/7/2013 7,Paseo de San Antonio,37.333798,-121.886943,15,San Jose,8/7/2013 8,San Salvador at 1st,37.330165,-121.885831,15,San Jose,8/5/2013...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT