Question

C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu...

C++ Program with 2 functions

1. Hamming Functions Tester Write a function that displays a menu to test the functions from 2 - 4. You must call the functions from 2 - 4 and cannot reimplement their functionality in this function. The menu is displayed as follows: 1) Enter a 4-bit message to encode into a 7-bit Hamming message. 2) Enter a 7-bit Hamming message to transmit through a noisy channel. 3) Enter a 7-bit Hamming message to receive and correct. 4) Quit. If the user selects 1, the function from Problem 2 is used and so on. All requests for input from the user should be handled inside of this function, and all output to the screen should also be handled inside of this function. Use a while loop to implement the quitting mechanism.

2. Hamming Transmitter Write a function that takes as input a 4-bit string of 0’s and 1’s. Output the 7-bit encoded message. For example, if the passed parameter is 1011, the output should be 0110011.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
int hamming(int ar1[],int ar2[]){
        int i,count;
        int res[BITS];
        for(i=0;i<n;i++){
                if((ar1[i]==1 && ar2[i]==0)||(ar1[i]==0 && ar2[i]==1)){
                        res[i] = 1;
                }
                else{
                        res[i] = 0;     
                }       
        }
        count = count_ham(res);
        printf("Hamming distance will be: %d",count);
        printf("\n");
}
#include<stdio.h>
#define BITS 8
int hamming(int ar1[],int ar2[]);
int input(int ar1[]);
int count_ham(int ar[]);
int n;
int main(){
        int ar1[BITS],ar2[BITS];
        printf("Enter the number of bits(max 8-bits):");
        scanf("%d",&n);
        printf("Enter a binary number(space between each bit and MAX 8-bit):");
        input(ar1);
        printf("Enter a binary number(space between each bit and MAX 8-bit):");
        input(ar2);
        hamming(ar1,ar2);
        return 0;
}

int input(int ar1[]){
        int i;  
        for(i=0;i<n;i++){
                scanf("%d",&ar1[i]);
        }
        
}
int count_ham(int ar[]){
        int i,count=0;
        for(i=0;i<n;i++){
                if(ar[i]==1)
                        count++;
        }
        return count;
        
}
int hamming(int ar1[],int ar2[]){
        int i,count;
        int res[BITS];
        for(i=0;i<n;i++){
                if((ar1[i]==1 && ar2[i]==0)||(ar1[i]==0 && ar2[i]==1)){
                        res[i] = 1;
                }
                else{
                        res[i] = 0;     
                }       
        }
        count = count_ham(res);
        printf("Hamming distance will be: %d",count);
        printf("\n");
}
Add a comment
Know the answer?
Add Answer to:
C++ Program with 2 functions 1. Hamming Functions Tester Write a function that displays a menu...
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
  • In C++ write a simple menu program that displays a menu for the user in an...

    In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...

  • Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

    Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition. • The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition until the user wishes to stop the program. •For encoding, the program needs to...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Write a C++ program that will display the following menu and work accordingly. A menu that...

    Write a C++ program that will display the following menu and work accordingly. A menu that will display the following choices and uses functions to carry out the calculations: 1. Call a function named classInfo() to ask the user the number of students and exams in a course. 2. Call a function getGrade() that will get the information from classInfo() and asks the user to enter the grades for each student. 3. Call a function courseGrade() to display the average...

  • Write a program that displays a menu on the screen. The menu will give the user...

    Write a program that displays a menu on the screen. The menu will give the user four options - enter two integers, enter two decimal numbers (#.#), enter one integer and one decimal number, or quit. The inputs should be labelled a, b, c, or d, and you should enter in the letter to choose the appropriate option. Once the user selects the option, two numbers will be read in from the user. The numbers will be added together and...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Write a complete C++ program that is made of functions main() and rShift(). The rShift() function...

    Write a complete C++ program that is made of functions main() and rShift(). The rShift() function must be a function without return with 6 parameters. rShift() should do following. Shift the first 4 formal parameters' value one place to right circularly and send the updated values out to the caller function, i.e. main. Furthermore, after calling this function with first 4 actual parameters, say a1, a2, a3, a4, and these actual parameters should shift their value one place to right...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

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
ADVERTISEMENT