Question

Write the code in C language. Computer communication networks sometimes have noise on them, which can...

Write the code in C language.

Computer communication networks sometimes have noise on them, which can corrupt data being transmitted. It is the responsibility of the computers communicating to confirm data is transmitted accurately. One method to do this is to calculate a checksum of the data and transmit the checksum along with the data to ensure accuracy. In C, we can compute a checksum simply by summing the integer ASCII codes in the message and finding the remainder of this sum divided by 64. For example, consider the message "ABC". To compute the checksum, add 65+66+67 to get 198, then divide by 64 to get a remainder of 6, which is used as your checksum. Now, when the data is transmitted, both the sending and receiving computers can compute a checksum and confirm the data was transmitted precisely.

1. Start by writing the function

int generate_checksum( char c, int so_far );

The parameter c is a character to be added to the checksum. The parameter so_far is the value calculated and returned by previous calls to the generate_checksum( ) function. It will have to be a zero the first time you invoke it. Write a driver function to test your function with a few characters, confirming it is returning the appropriate answers.

Added 'A': generate_checksum returned 1.

Added 'B': generate_checksum returned 3.

Added 'C': generate_checksum returned 6.

Your driver is going to have to make repeated calls to the generate_checksum( ) function, along the lines of:

so_far = generate_checksum( 'A', 0 );

so_far = generate_checksum( 'B', so_far );

so_far = generate_checksum( 'C', so_far );

Each call feeds back in the value calculated in the previous call. Obviously, you can use an appropriate iterator to simply your driver code. Make sure you include the driver when submitting this assignment.

2. Step two, write the function

get_string_and_checksum( )

using an iterator that continues to read in characters from the keyboard until the user enters a period.

Use the C standard

getchar( )

function to read in the individual characters. Each call to this function returns a single character from the keyboard.

After each character is read in, invoke your function generate_checksum ( ) to calculate the current checksum. Your function should not output anything until the user enters a line with a period on it.

When the user enters a period at the end, display the checksum and then prompt for the next string.

Your program should continue prompting for a string until the user enters a line with only a period on it. Common error: Make sure you do not add the period to the checksum

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the Code: (with comments explaining the logic)

Here is the same code: (Without comments, for better readability)

Here is the code(In plain-text format, in order to copy-paste into your compiler)

 #include <stdio.h> int generate_checksum(char c, int so_far) { int Ascii = (int)c; int checkSum = (Ascii + so_far) % 64; return checkSum; } char get_string_and_checksum() { while (1) { return getchar(); } } int main() { char c; int so_far; printf("Enter a string: "); c = get_string_and_checksum(); if (c == '.') { return 0; } else { so_far = generate_checksum(c, 0); while (1) { c = get_string_and_checksum(); if (c == '.') { int checkSum = so_far; if (checkSum == 0) { return 0; } so_far = -10; printf("checkSum = %d\n", checkSum); printf("Enter next string: "); } else { so_far = generate_checksum(c, so_far); } } } return 0; }
Add a comment
Know the answer?
Add Answer to:
Write the code in C language. Computer communication networks sometimes have noise on them, which can...
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 language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • Since communications channels are often noisy, numerous ways have been devised to ensure reliable data transmission....

    Since communications channels are often noisy, numerous ways have been devised to ensure reliable data transmission. One successful method uses a checksum. A checksum for a message can be computed by summing the integer codes of the characters in the message and finding the remainder of this sum divided by 64. The integer code for a space character is added to this result to obtain the checksum. Since this value is within the range of the displayable characters, it is...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • Program Description: A C# app is to be created to produce Morse code. The Morse code...

    Program Description: A C# app is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • Program Description: A Java program is to be created to produce Morse code. The Morse code...

    Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • ** Language Used : Python ** PART 2 : Create a list of unique words This...

    ** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

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