Question

In C please : The tasks in this exam review exercise are structured in levels. You...

In C please :

The tasks in this exam review exercise are structured in levels. You can see the point distribution for the levels at the end. It is strongly recommended that you ensure you have passed all test cases of lower levels before moving up to a higher level. For example, ensure you have completed all Level 0 and 1 tasks before even looking at Level 2 Tasks.

MESSAGE ENCODER

LEVEL 0: (test cases - 50 points)

Start by printing out your name and lab time:

My Name: Dr. Reckinger
My Lab Time: 9:00 AM

Then your code should prompt the user to enter a string of at least 3 characters long:

Enter a string of at least 3 characters (no whitespace):

Make sure strings of up to 200 characters are allowed.

LEVEL 1: (test cases - 25 points)

Ensure the string inputted by the user is at least 3 characters long. If not, repeatedly prompt the user until a valid string has been entered:

Enter a string of at least 3 characters (no whitespace):
Enter a string of at least 3 characters (no whitespace):
Enter a string of at least 3 characters (no whitespace):
.
.
.
Enter a string of at least 3 characters (no whitespace):

Convert the characters in the user's inputted string to a list of integers following the character encoding using the ASCII standard (see Table 2.10.1 for reference, although you do not need any of the details from the table to complete this task). Print the list of integers to the screen (the following is the output if the user had enter "Hello!"):

Your message in ints: 72 101 108 108 111 33 

Next, prompt the user to enter a positive integer representing the integer shift that will be applied to the encoded characters. If the user's string has an odd number of characters, convert the inputted shift to a negative number of the same absolute value.

LEVEL 2: (test cases - 10 points)

Apply the shift to the list of integers and print the shifted list of integers to the screen. For example, the following is the output if the user had entered the 6-character string "Hello!" and a shift of 3:

Your message in ints shifted by 3: 75 104 111 111 114 36 

And, the following is the output if the user had entered the 5-character string "Hello" (no exclamation point) and a shift of 3:

Your message in ints shifted by -3: 69 98 105 105 108 

LEVEL 3: (test cases - 10 points)

Print to screen another string that is the fully encoded message by converting the list of shifted integers back to characters. Here is the full output expected when the user enters the string "Hello!" and a shift of 3:

My Name: Dr. Reckinger
My Lab: 9:00 AM
Enter a string of at least 3 characters (no whitespace):

Your message in ints: 72 101 108 108 111 33 
Enter a positive integer to shift: 

Your message in ints shifted by 3: 75 104 111 111 114 36 
Your encoded message: Khoor$

LEVEL 3+: (test cases - 5 points)

From ASCII Table 2.10.1, notice that only integers between 32 and 126 are valid, so you need to be careful with your shifted integers by wrapping the ASCII table. Thus, an integer of 31 should be assigned to the character '~' (which is #126) and an integer of 128 should be assigned to character '!' (which is #33).

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

CODE:

#include <stdio.h>
#include<string.h>
int main()
{
    printf("My Name: Dr.Reckinger\nMy Lab Time: 9:00 AM");
    char string[200];
    printf("\nEnter a string of at least 3 characters (no whitespace):");
    scanf("%s",string);
    //printf("%d",strlen(string));
    //Taking input while length less than 3
    while(strlen(string)<3){
        printf("\nEnter a string of at least 3 characters (no whitespace):");
        scanf("%s",string);
    }
    int len=strlen(string),shift;
    int integerArray[len],i=0;
    //Converting to integers
    for(i=0;i<len;i++){
        integerArray[i]=string[i];
    }
    printf("\nYour message in ints:");
    for(i=0;i<len;i++){
        printf("%d ",integerArray[i]);
    }
    printf("\nEnter a positive integer to shift: ");
    scanf("%d",&shift);
    //Changing shift value based on length of the string
    if(len%2==1){
        shift=-shift;
    }
    printf("\nYour message in ints shifted by %d: ",shift);
    for(i=0;i<len;i++){
        integerArray[i]=integerArray[i]+shift;
        printf("%d ",integerArray[i]);
    }
    printf("\nYour encoded message:");
    for(i=0;i<len;i++){
        //Checking whether ASCII value exeeds the max i.e.,, 126
        if(integerArray[i]>126){
            integerArray[i]=integerArray[i]%126;
            integerArray[i]+=31;
        }
        //Checking whether ASCII value decreases the min i.e.,, 32
        if(integerArray[i]<32){
            integerArray[i]=127-(32- integerArray[i]);
        }
        printf("%c",(char)integerArray[i]);
    }
    return 0;
}

//Follow Line number to get correct code

Output:

Add a comment
Know the answer?
Add Answer to:
In C please : The tasks in this exam review exercise are structured in levels. You...
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 this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

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

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • In C programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) 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 'O' You will compule 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 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

  • C++ Program, Decode a Secret Message.

    Your country is at war and your enemies are using a secret code to communicate with each other.You have managed to intercept a message that reads asfollows::mmZdxZmx]ZpgyThe message is obviously encrypted using the enemy's secret code.You have just learned that their encryption method is based upon the ASCII code.Appendix 3 of your book shows the ACII character set.Individual characters in a string are encoded using this system. For example, the letter "A" isencoded using the number 65 and "B" is...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise...

    Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Descripition : For this problem you will be implementing a Caesarin Cipher. A Caesarin Cipher takes a string and a shift amount and shift the characters in the string by the shift amount. Specifications: Only characters should be ciphered If a character is shifted beyond the end of the aphabet it should wrap back around For example if the letter 'y' is shifted 3...

  • ior new tr k%2005%281 %29, You are just hired by Google as a senior software developer...

    ior new tr k%2005%281 %29, You are just hired by Google as a senior software developer and your supervisor assigns you the following task: You are responsible for the development of a program that encrypts and decrypts text messages using the Caesar shift, which is one of the oldest and widely known forms of encryption Caesar shift is a type of substitution encryption method in which each letter in the text is 'shifted' a fixed mumber of positions down the...

  • C++ please! In this program you will be outputting the characters that map to the ASCIl...

    C++ please! In this program you will be outputting the characters that map to the ASCIl codes 32 through 126. You will need a loop to iterate through the input values and output the corresponding character. This mapping is shown in appendix A in your Gaddis text book. Your program will be reading in two unsigned integer values. The prompt for read will be Enter lower and upper values You need to check that both values are in the range...

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