Knowee
Questions
Features
Study Tools

Betty is exploring character encryption using a program. She wants to encrypt a given character based on specific rules:Encrypt a given character by adding 2 to the ASCII value for uppercase Subtract 2 for lowercase letters. For non-alphabetic characters, add 5 to the ASCII value.Create a program that takes Betty's input character, converts it to a signed char, and prints the encrypted result.

Question

Betty is exploring character encryption using a program. She wants to encrypt a given character based on specific rules:Encrypt a given character by adding 2 to the ASCII value for uppercase Subtract 2 for lowercase letters. For non-alphabetic characters, add 5 to the ASCII value.Create a program that takes Betty's input character, converts it to a signed char, and prints the encrypted result.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C++ program that implements the encryption rules Betty wants:

#include <iostream>
#include <cctype>

int main() {
    char inputChar;
    std::cout << "Enter a character: ";
    std::cin >> inputChar;

    signed char encryptedChar;

    if (isalpha(inputChar)) {
        if (isupper(inputChar)) {
            encryptedChar = inputChar + 2;
        } else {
            encryptedChar = inputChar - 2;
        }
    } else {
        encryptedChar = inputChar + 5;
    }

    std::cout << "Encrypted character: " << encryptedChar << std::endl;

    return 0;
}

This program first asks the user to input a character. It then checks if the character is alphabetic. If it is, it checks if it's uppercase or lowercase and adds or subtracts 2 from the ASCII value accordingly. If the character is not alphabetic, it adds 5 to the ASCII value. The result is then printed to the console.

This problem has been solved

Similar Questions

Single File Programming QuestionProblem StatementGeorge, a secret agent, needs a program to encrypt a character using a shifting method. The program should prompt him to enter an alphabet and a shift amount as register storage class inputs. The encrypted character is obtained by shifting the input alphabet by the specified amount in a circular manner. Uppercase and lowercase letters wrap around, ensuring a seamless shift within the alphabet.Example: If the character 'y' wants to be rotated 6 times, it wraps around the alphabet after reaching 'z'. The shifting process results in the output 'e'.Input format :The input consists of a character c representing the alphabet on which shifting happens and an integer n representing the number of times it has to be shifted, separated by a space.Output format :The output prints the character after shifting the input alphabet (to its right) n times.If c is not an alphabet, the output prints the input character as such without shifting.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:c should be a valid ASCII character.1 ≤ n ≤ 20Sample test cases :Input 1 :A 1Output 1 :BInput 2 :Z 2Output 2 :BInput 3 :c 4Output 3 :gInput 4 :y 6Output 4 :eInput 5 :# 5Output 5 :#Input 6 :b 20Output 6 :vNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

Write a program that takes a string of lowercase characters as input and prints it in uppercase, reversed.

Make a function that encrypts a given input with these steps:Input: "apple"Step 1: Reverse the input: "elppa"Step 2: Replace all vowels using the following chart:a => 0e => 1i => 2o => 2u => 3# "1lpp0"Step 3: Add "vit" to the end of the word: "1lpp0vit"Output: "1lpp0vit"NotesAll inputs are strings, no uppercases and all output must be strings.i/p:bananao/p:0n0n0bvit

Write a program that converts strings of all uppercase characters into strings of all lowercase and viceversa

Write a program to check whether a given character is Alphabet or not using if else statement Note: Check for both upper and lower case characters

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.