Write a program to translate the English alphabet to binary strings according to the above correspondence and store the result in a file. So ‘c’represented as 00010, ‘d’represented as 00011. So if your input is cd, The output in the file will be 0001000011. Also, read the binary strings from the file and translate it to Alphabet. Use 5 bits to represent your binary data Verify your result that you get the same alphabet from a binary string. It's a C program.
Program Screenshots:


Sample storing file: store.txt

Sample Output:

Code to Copy:
// declare a necessary header files.
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
// start the main function.
int main(void) {
// declare arrays
char arr[50];
char arr1[50];
int i=0;
// declare file pointer and open the file.
FILE *fptr;
fptr = fopen("store.txt","w");
// prompt the user to enter th eword.
printf("Enter a word:\n");
scanf("%s",arr);
// start the for loop.
for(i=0;i<strlen(arr);i++)
{
int n = (int)(arr[i]-97);
int j=0;
// START THE WHILE LOOP
while(n>0)
{
// get the binary equivalent of a number.
int r=n%2;
arr1[j]=r;
n=n/2;
j++;
}
char arr2[5]={0,0,0,0,0};
int k = 4;
int p = 0;
// start the loop.
while (p<j)
{
arr2[k] = arr1[p];
p++;
k--;
}
int l = 0;
// start the for loop
for( l=0;l<5;l++)
{
// store the value in a file.
fprintf(fptr, "%d", arr2[l]);
}
}
fclose(fptr);
char num;
// open the file in read mode.
if ((fptr = fopen("store.txt","r")) == NULL){
printf("Error! opening file");
exit(1);
}
int n=strlen(arr);
int k = 0;
printf("Alphabets after reading the binary strings from the file:");
// start the while loop
while(k<n)
{
int x =0;
char bin_arr[5];
// start the whiel loop.
while(x<5)
{
fscanf(fptr,"%c", &num);
bin_arr[x] = num;
x++;
}
int y = 0;
int num_val = 0;
// start the for loop.
for(y=0;y<5;y++)
{
// check the condition.
if(bin_arr[y] == '1')
{
num_val = num_val + pow(2,4-y);
}
}
char req_char = num_val + 97;
// display the result on console
printf("%c", req_char);
k++;
}
fclose(fptr);
return 0;
}
Write a program to translate the English alphabet to binary strings according to the above correspondence...
Implement a Java method named addBinary() that takes two String arguments (each representing a binary value) and returns a new String corresponding to the result of performing binary addition on those arguments. Before you begin, if one of the arguments is shorter than the other, call your pad() method from the previous step to extend it to the desired length. Note: ped() method is public static String pad(String input, int size) { if(input.length()>=size) { return input; } String a =...
1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...
Write a program that counts the frequency of each letter of the alphabet as they occur in a text contained in a text file. The program should read all the characters from a file and tally the frequency for each letter of the alphabet (case-insensitive), along with white space and total character count. Your program's data structure will eventually contain the 26 numbers that will represent the frequencies of occurrence of all 26 letters of the alphabet in that file....
Write an efficient java program to implement BST. Your java program should read n words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in engtofren.java file To compile: javac engtofren.java To execute: java engtofren< any data file name Your main method should be as follow: public static void main(String args[]) { engtofren bst = new engtofren (); // try{...
Write a C program that prompts the user to enter a binary value, multiplies it by ten, then displays the result in binary. (“Binary” here means that the user communicates with the program in ones and zeros.) Your main function should a) declare a char array, b) call the readLn function to read from the keyboard c) call a function to convert the input text string to an int d) multiply the int by ten e) call a function to...
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
In either Java or Python 3, write a program that simulates a deterministic FSM. It will read from two input files. The first is a file describing an FSM The first line contains the alphabet as a series of characters separated by a single space - The second line contains the number of states as an integer k 2 1; states will be numbered 0,1,..., k -1. The start state is always state O The third line contains a series...
java
Binary files The binary file data.dat contains characters and numbers- it has 16 characters, followed by numbers of type int alternating with numbers of type double -so after the first 16 characters, there will be an int, followed by a double, followed by an int, followed by a double, and so on. Write a program to open the file and until the end of file is reached, read in the values in the appropriate data types (that is, read...
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...