All that is needed is to fill in that one area that says "Student provides missing code to compare computed hammingCode[] bits to the codeword[] bits to determine the incorrect bit." in the code below. THAT IS ALL THAT IS NEEDED PLUS SCREENSHOT OF COMPILED OUTPUT AFTERWARDS.
Please TAKE SCREENSHOT of the compiled output which should look similar to the sample one provided.

//------------------------------------------------------
// Problem #6
// Problem6.c
//------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define MAXIMUMM 512
#define MAXIMUMR 10
typedef char BITS[MAXIMUMM+MAXIMUMR+1];
typedef enum { EVEN,ODD } PARITY;
//------------------------------------------------------
int main()
//------------------------------------------------------
{
void ComputeCodeWord(const BITS memoryWord,const PARITY parity,int *m,int *r,BITS codeWord);
void SetRandomSeed(void);
int RandomInt(const int LB,const int UB);
void ToggleBit(BITS word,const int bit);
void CorrectSingleBitError(const PARITY parity,const int m,const int r,BITS codeWord);
char fileName[80+1];
FILE *MEMORYWORDS;
BITS memoryWord,codeWord;
PARITY parity;
int m,r,n,bit;
printf("memory-words fileName? "); scanf("%s",fileName);
if ( (MEMORYWORDS = fopen(fileName,"r")) == NULL)
{
printf("Error opening memory-words file "%s"! ",fileName);
system("PAUSE");
exit( 1 );
}
SetRandomSeed();
while ( fgets(&memoryWord[1],MAXIMUMM,MEMORYWORDS) != NULL )
{
// Ignore memoryWord[0], erase ' ' at end of memoryWord[] string (if any)
memoryWord[0] = 'X';
if ( memoryWord[strlen(memoryWord)-1] == ' ' )
memoryWord[strlen(memoryWord)-1] = '';
/*
Determine and erase parity at end of memoryWord[] string (if any)--an 'E' or 'e'
suffix means (E)VEN, 'O' or 'o' suffix means (O)DD, and no suffix defaults to EVEN.
Here's BNF (Backus-Naur Form) that captures the preceding description of a memoryWord[]
<memoryWord> ::= <bit> { <bit> }* [ (( E | e | O | o )) ]
<bit> ::= 0 | 1
*/
if ( toupper(memoryWord[strlen(memoryWord)-1]) == 'E' )
{
parity = EVEN;
memoryWord[strlen(memoryWord)-1] = '';
}
else if ( toupper(memoryWord[strlen(memoryWord)-1]) == 'O' )
{
parity = ODD;
memoryWord[strlen(memoryWord)-1] = '';
}
else
parity = EVEN;
// Compute codeWord[], m, r based on parity, memoryWord[]; display memoryWord[] and codeWord[]
ComputeCodeWord(memoryWord,parity,&m,&r,codeWord);
printf(" ");
printf("Memory word = %s%c ",&memoryWord[1],((parity == EVEN) ? 'E' : 'O'));
printf("Code word = %s original ",&codeWord[1]);
/*
Cause a random, single-bit error then show the erroroneous codeWord[];
correct the single-bit error; display corrected codeWord[]
*/
n = m+r;
bit = RandomInt(1,n);
ToggleBit(codeWord,bit);
printf("Code word = %s with error in bit #%d ",&codeWord[1],bit);
CorrectSingleBitError(parity,m,r,codeWord);
printf("Code word = %s with error corrected ", &codeWord[1]);
}
fclose(MEMORYWORDS);
system("PAUSE");
return( 0 );
}
//------------------------------------------------------
void ComputeCodeWord(const BITS memoryWord,const PARITY parity,int *m,int *r,BITS codeWord)
//------------------------------------------------------
{
int R(const int m);
bool IsPowerOf2(const int x);
int PowerOf2(const int exponent);
void ComputeHammingCode(const BITS codeWord,const PARITY parity,
const int m,const int r,BITS hammingCode);
int n,ri,mi,ci;
BITS hammingCode;
// Computer m, r, n
*m = strlen(memoryWord)-1;
*r = R(*m);
n = *m + *r;
/*
Place memoryWord[] bits into codeWord[] leaving room for the hammingCode[]
bits which are temporarily marked 'H'
*/
mi = 1;
for (ci = 1; ci <= n; ci++)
{
if ( IsPowerOf2(ci) )
codeWord[ci] = 'H';
else
{
codeWord[ci] = memoryWord[mi];
mi++;
}
}
codeWord[n+1] = '';
// Place hammingCode[] bits into codeWord[] thereby overwriting each 'H'
ComputeHammingCode(codeWord,parity,*m,*r,hammingCode);
for (ri = 1; ri <= *r; ri++)
codeWord[PowerOf2(ri-1)] = hammingCode[ri];
}
//------------------------------------------------------
void ComputeHammingCode(const BITS codeWord,const PARITY parity,
const int m,const int r,BITS hammingCode)
//------------------------------------------------------
{
bool IsPowerOf2(const int x);
int PowerOf2(const int exponent);
int n = m+r;
int *sums = (int *) malloc(sizeof(int)*(r+1));
int ri,ci;
// Compute sum-of-bits for each hammingCode[] bit
for (ri = 1; ri <= r; ri++)
sums[ri] = 0;
for (ri = 1; ri <= r; ri++)
for (ci = PowerOf2(ri-1); ci <= n; ci++)
if ( !IsPowerOf2(ci) )
if ( ((ci >> (ri-1)) & 0X1) == 1 ) sums[ri] += (codeWord[ci] == '1') ? 1 : 0;
// Compute hammingCode[] bits for EVEN or ODD parity
for (ri = 1; ri <= r; ri++)
if ( sums[ri]%2 == 0 )
hammingCode[ri] = (parity == EVEN) ? '0' : '1';
else
hammingCode[ri] = (parity == EVEN) ? '1' : '0';
hammingCode[r+1] = '';
free(sums);
}
//------------------------------------------------------
void CorrectSingleBitError(const PARITY parity,const int m,const int r,BITS codeWord)
//------------------------------------------------------
{
void ComputeHammingCode(const BITS codeWord,const PARITY parity,
const int m,const int r,BITS hammingCode);
int PowerOf2(const int exponent);
void ToggleBit(BITS word,const int bit);
int ri,bit;
BITS hammingCode;
// Compute Hamming code bits
ComputeHammingCode(codeWord,parity,m,r,hammingCode);
// Compare computed Hamming code bits to codeWord bits to determine incorrect bit
Student provides missing code to compare computed hammingCode[] bits to the codeword[]
bits to determine the incorrect bit.
// Toggle incorrect bit
ToggleBit(codeWord,bit);
}
//------------------------------------------------------
int R(const int m)
//------------------------------------------------------
{
int PowerOf2(const int exponent);
int r = 1;
while ( (m+r+1) > PowerOf2(r) ) r++;
return( r );
}
//------------------------------------------------------
int PowerOf2(const int exponent)
//------------------------------------------------------
{
return( (int) pow(2,exponent) );
}
//------------------------------------------------------
bool IsPowerOf2(const int x)
//------------------------------------------------------
{
int powerOf2 = 1;
while ( powerOf2 < x )
powerOf2 *= 2;
return( (powerOf2 == x) ? true : false );
}
//------------------------------------------------------
void ToggleBit(BITS word,const int bit)
//------------------------------------------------------
{
word[bit] = (word[bit] == '1') ? '0' : '1';
}
//-----------------------------------------------------
// Functions below are "stolen" from the Dr. Hanna random-related pseudo-library
//-----------------------------------------------------
void SetRandomSeed(void)
//-----------------------------------------------------
{
srand( (unsigned int) time(NULL) );
}
//------------------------------------------------------
int RandomInt(const int LB,const int UB)
//------------------------------------------------------
{
double RandomDouble();
return( (int) ((UB-LB+1)*RandomDouble()) + LB );
}
//--------------------------------------------------
double RandomDouble()
//--------------------------------------------------
{
int R;
do
R = rand();
while ( R == RAND_MAX );
return( (double) R/RAND_MAX );
}
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define MAXIMUMM 512
#define MAXIMUMR 10
typedef char BITS[MAXIMUMM+MAXIMUMR+1];
typedef enum { EVEN,ODD } PARITY;
//------------------------------------------------------
int main()
//------------------------------------------------------
{
void ComputeCodeWord(const BITS memoryWord,const PARITY parity,int
*m,int *r,BITS codeWord);
void SetRandomSeed(void);
int RandomInt(const int LB,const int UB);
void ToggleBit(BITS word,const int bit);
void CorrectSingleBitError(const PARITY parity,const int m,const
int r,BITS codeWord);
char fileName[80+1];
FILE *MEMORYWORDS;
BITS memoryWord,codeWord;
PARITY parity;
int m,r,n,bit;
printf("memory-words fileName? "); scanf("%s",fileName);
if ( (MEMORYWORDS = fopen(fileName,"r")) == NULL)
{
printf("Error opening memory-words file "%s"! ",fileName);
system("PAUSE");
exit( 1 );
}
SetRandomSeed();
while ( fgets(&memoryWord[1],MAXIMUMM,MEMORYWORDS) != NULL
)
{
// Ignore memoryWord[0], erase ' ' at end of memoryWord[] string
(if any)
memoryWord[0] = 'X';
if ( memoryWord[strlen(memoryWord)-1] == ' ' )
memoryWord[strlen(memoryWord)-1] = NULL;
/*
Determine and erase parity at end of memoryWord[] string (if
any)--an 'E' or 'e'
suffix means (E)VEN, 'O' or 'o' suffix means (O)DD, and no suffix
defaults to EVEN.
Here's BNF (Backus-Naur Form) that captures the preceding
description of a memoryWord[]
<memoryWord> ::= <bit> { <bit> }* [ (( E | e | O
| o )) ]
<bit> ::= 0 | 1
*/
if ( toupper(memoryWord[strlen(memoryWord)-1]) == 'E' )
{
parity = EVEN;
memoryWord[strlen(memoryWord)-1] = NULL;
}
else if ( toupper(memoryWord[strlen(memoryWord)-1]) == 'O' )
{
parity = ODD;
memoryWord[strlen(memoryWord)-1] = NULL;
}
else
parity = EVEN;
// Compute codeWord[], m, r based on parity, memoryWord[]; display
memoryWord[] and codeWord[]
ComputeCodeWord(memoryWord,parity,&m,&r,codeWord);
printf(" ");
// int c=1;
char sub[100];
// int length=strlen(&memoryWord[1]);
// while (c < length)
// {
// sub[c] = memoryWord[c];
// c++;
// }
// sub[c] = '';
strncpy(sub,&memoryWord[1],strlen(&memoryWord[1])-1);
printf(" Memory word = %s%c ",sub,((parity == EVEN) ? 'E' :
'O'));
strncpy(sub,&codeWord[1],strlen(&codeWord[1])-2);
printf(" Code word = %s original ",sub);
/*
Cause a random, single-bit error then show the erroroneous
codeWord[];
correct the single-bit error; display corrected codeWord[]
*/
n = m+r;
bit = RandomInt(1,n);
ToggleBit(codeWord,bit);
strncpy(sub,&codeWord[1],strlen(&codeWord[1])-2);
printf(" Code word = %s with error in bit #%d ",sub,bit);
CorrectSingleBitError(parity,m,r,codeWord);
strncpy(sub,&codeWord[1],strlen(&codeWord[1])-2);
printf(" Code word = %s with error corrected ", sub);
}
fclose(MEMORYWORDS);
system("PAUSE");
return( 0 );
}
//------------------------------------------------------
void ComputeCodeWord(const BITS memoryWord,const PARITY parity,int
*m,int *r,BITS codeWord)
//------------------------------------------------------
{
int R(const int m);
bool IsPowerOf2(const int x);
int PowerOf2(const int exponent);
void ComputeHammingCode(const BITS codeWord,const PARITY
parity,
const int m,const int r,BITS hammingCode);
int n,ri,mi,ci;
BITS hammingCode;
// Computer m, r, n
*m = strlen(memoryWord)-1;
*r = R(*m);
n = *m + *r;
/*
Place memoryWord[] bits into codeWord[] leaving room for the
hammingCode[]
bits which are temporarily marked 'H'
*/
mi = 1;
for (ci = 1; ci <= n; ci++)
{
if ( IsPowerOf2(ci) )
codeWord[ci] = 'H';
else
{
codeWord[ci] = memoryWord[mi];
mi++;
}
}
codeWord[n+1] = NULL;
// Place hammingCode[] bits into codeWord[] thereby overwriting
each 'H'
ComputeHammingCode(codeWord,parity,*m,*r,hammingCode);
for (ri = 1; ri <= *r; ri++)
codeWord[PowerOf2(ri-1)] = hammingCode[ri];
}
//------------------------------------------------------
void ComputeHammingCode(const BITS codeWord,const PARITY
parity,
const int m,const int r,BITS hammingCode)
//------------------------------------------------------
{
bool IsPowerOf2(const int x);
int PowerOf2(const int exponent);
int n = m+r;
int *sums = (int *) malloc(sizeof(int)*(r+1));
int ri,ci;
// Compute sum-of-bits for each hammingCode[] bit
for (ri = 1; ri <= r; ri++)
sums[ri] = 0;
for (ri = 1; ri <= r; ri++)
for (ci = PowerOf2(ri-1); ci <= n; ci++)
if ( !IsPowerOf2(ci) )
if ( ((ci >> (ri-1)) & 0X1) == 1 ) sums[ri] +=
(codeWord[ci] == '1') ? 1 : 0;
// Compute hammingCode[] bits for EVEN or ODD parity
for (ri = 1; ri <= r; ri++)
if ( sums[ri]%2 == 0 )
hammingCode[ri] = (parity == EVEN) ? '0' : '1';
else
hammingCode[ri] = (parity == EVEN) ? '1' : '0';
hammingCode[r+1] = NULL;
free(sums);
}
//------------------------------------------------------
void CorrectSingleBitError(const PARITY parity,const int m,const
int r,BITS codeWord)
//------------------------------------------------------
{
void ComputeHammingCode(const BITS codeWord,const PARITY
parity,
const int m,const int r,BITS hammingCode);
int PowerOf2(const int exponent);
void ToggleBit(BITS word,const int bit);
int ri,bit;
BITS hammingCode;
// Compute Hamming code bits
ComputeHammingCode(codeWord,parity,m,r,hammingCode);
// Compare computed Hamming code bits to codeWord bits to determine
incorrect bit
//Student provides missing code to compare computed hammingCode[]
bits to the codeword[]
//bits to determine the incorrect bit.
// Toggle incorrect bit
ToggleBit(codeWord,bit);
}
//------------------------------------------------------
int R(const int m)
//------------------------------------------------------
{
int PowerOf2(const int exponent);
int r = 1;
while ( (m+r+1) > PowerOf2(r) ) r++;
return( r );
}
//------------------------------------------------------
int PowerOf2(const int exponent)
//------------------------------------------------------
{
return( (int) pow(2,exponent) );
}
//------------------------------------------------------
bool IsPowerOf2(const int x)
//------------------------------------------------------
{
int powerOf2 = 1;
while ( powerOf2 < x )
powerOf2 *= 2;
return( (powerOf2 == x) ? true : false );
}
//------------------------------------------------------
void ToggleBit(BITS word,const int bit)
//------------------------------------------------------
{
word[bit] = (word[bit] == '1') ? '0' : '1';
}
//-----------------------------------------------------
// Functions below are "stolen" from the Dr. Hanna random-related
pseudo-library
//-----------------------------------------------------
void SetRandomSeed(void)
//-----------------------------------------------------
{
srand( (unsigned int) time(NULL) );
}
//------------------------------------------------------
int RandomInt(const int LB,const int UB)
//------------------------------------------------------
{
double RandomDouble();
return( (int) ((UB-LB+1)*RandomDouble()) + LB );
}
//--------------------------------------------------
double RandomDouble()
//--------------------------------------------------
{
int R;
do
R = rand();
while ( R == RAND_MAX );
return( (double) R/RAND_MAX );
}

All that is needed is to fill in that one area that says "Student provides missing...
Implement a rabin_hash method to make the following code work: int rabin_karp_batchmatch(int bsz, /* size of bitmap (in bits) to be used */ int k, /* chunk length to be matched */ const char *qs, /* query docoument (X)*/ int m, /* query document length */ const char *ts, /* to-be-matched document (Y) */ int n /* to-be-matched document length*/) { /*if the to-be-matched document is less than k length, return false*/ if (n < k) return 0; /*start our...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
I am having problems with the following assignment. It is done
in the c language. The code is not reading the a.txt file. The
instructions are in the picture below and so is my code. It should
read the a.txt file and print. The red car hit the blue car and
name how many times those words appeared. Can i please get some
help. Thank you.
MY CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char *str;
int...
I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME
OUT AND READ THIS. I just have to explain a lot so you understand
how the program should work.
In C programming, write a simple program to
take a text file as input and encrypt/decrypt it by reading the
text bit by bit, and swap the bits if it is specified by the first
line of the text file to do so (will explain below, and please let
me...
Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...
Name_year_test.c
#include "Name_year.h"
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
void print_name_year(const Name_year * ny)
{
printf("%s,%d\n", ny->name, ny->year);
}
int main()
{
char * ny_format = "%s,%d\n";
#if PHASE >= 1
puts("Phase 1 tests");
// Make sure we can create an object and get the
data back.
// We're creating the name as a local array so that we
can
// make sure that create_name_year() does not merely
make
// a copy of...
Overview: You will be writing classes that implement a playlist simulation for a music streaming app.The Playlist class will contain a dynamic array of Song objects, and the Song class contains several pieces of information about a song. You will need to: 1) Finish the writing of two classes: Song and Playlist. The full header file for the Song class has been provided in a file called Song.h. 2) Write a main program (filename menu.cpp) that creates a single Playlist...