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
  • Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices....

    Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices. 1. Find the number of digits in an integer. 2. Find the nth digit in an integer. 3. Find the sum of all digits of an integer. 4. Is the integer a palindrome? 5. Quit Enter a choice: Page 1 of 4 For each of the choices (1, 3, 4), Read a positive integer number and call a function that processes the menu choice...

  • 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...

  • Create a c++ program which: 1. Displays a menu: 1) Decimal to Binary • 2) Binary...

    Create a c++ program which: 1. Displays a menu: 1) Decimal to Binary • 2) Binary to Decimal • 3) Decimal to Hex • 4) Hex to Decimal • 9) Exit Program 2. For Menu item #1: Ask the user for a Decimal number. If they type a negative number, go back to step #1 1. Convert the Decimal number to binary and display it. 3. For Menu item #2: Ask the user for a binary number (1's and 0's)....

  • 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...

  • 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 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 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 C++ program, program should include at least the following functions:  getComputerGuess(): this function should...

    Write C++ program, program should include at least the following functions:  getComputerGuess(): this function should return a random value generated by the computer using rand function ( read more about random numbers in Chapter 3 pages 126 – 128 ).  getUsersChoice(): this function will ask the user to enter a choice using a menu. It then returns the user’s selected choice. Here is the menu: “1) Rock 2)Paper 3) Scissors 4) Quit” You should allow the game to...

  • 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...

  • (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...

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