Question

Write a single C++ statements to accomplish each of the following tasks: In one statement, assign...

  1. Write a single C++ statements to accomplish each of the following tasks:

  1. In one statement, assign the sum of the current value of x and y to z and postincrement the value of x.
    1. Determine whether the value of the variable count is greater than 10. If it is, print

“Count is greater than 10.”.

  1. Pre-decrement the variable of x by 1, then subtract it from the variable total.
  2. Multiply variable power by x and assign the result to power.  

(b)  

  1. Given a=3, b=2, and c=5, evaluate the final value of R for the following statements:
    1. R = ++a * c++ % b + (a * b) > 20
    2. R = b * c / a++ + ++a + ++b
    3. R = (a * b * (c + (9 * 3 / 3)))
    4. R = b % b + b * b – b / b
    5. R = c / b * 10 % 3 < 5

SHOW THE STEPS.

(c) Write a program that prompt the user to enter a string. Encrypts a message where each of the character in the string will be replaced by the next 3 letters of the current letter. For example: if the user input a message “Hello”, then the encrypted message is “Khoor”.

Sample Output Run

Enter a String : My Best Friend

Encrypted message is : P|#Ehw#Iuhqg

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

a. In one statement, assign the sum of the current value of x and y to z and post-increment the value of x:

int z = (x++) + y;

i. Determine whether the value of the variable count is greater than 10. If it is, print “Count is greater than 10.”:

int count = 20;

cout << ((count > 10) ? "Count greater than 10" : "Count less than 10");

iii. Pre-decrement the variable of x by 1, then subtract it from the variable total:

(total - --x);

(b)

Given a=3, b=2, and c=5

Pre-increment:

a = a + 1;

(++a) means, cout << a; will give "4".

Post-increment:

a=a;

a = a + 1;

(a++) means, cout << a; will give "3". If again, cout << a; - it will print 4.

i. R = ++a * c++ % b + (a * b) > 20:

= 4 * 5 % 2 + (4 * 2) > 20

= 4 * 5 % 2 + 8 > 20 [Paranthesis comes 1st]

= 20 % 2 + 8 > 20 [Multiplication, Division, Modulus are all of the same priority. So, we will traverse from left to right]

= 0 + 8 > 20

= 8 > 20 = 0 [Yes = 1 and No = 0]

Answer: 0

[After above operation, a = 4, b = 2, c = 6]

ii. R = b * c / a++ + ++a + ++b:

= 2 * 6 / 4 + 6 + 3 ["a" was 4, a++ gave 4 at that instant and changing "a" to 5, ++a gave 6 at that instant]

= 12 / 4 + 6 + 3

= 3 + 6 + 3 = 12

Answer: 12

[After above operation, a = 6, b = 3, c = 6]

iii. R = (a * b * (c + (9 * 3 / 3)))

= (6 * 3 * (6 + (9 * 3 / 3)))

= (6 * 3 * (6 + 9)) [9 * 3 / 3 = 27 / 3 = 9]

= (6 * 3 * 15) = 270

Answer: 270

[After above operation, a = 6, b = 3, c = 6]

iv. R = b % b + b * b – b / b

= 3 % 3 + 3 * 3 - 3 / 3

= 0 + 9 - 1 = 8

Answer: 8

[After above operation, a = 6, b = 3, c = 6]

v. R = c / b * 10 % 3 < 5

= 6 / 3 * 10 % 3 < 5

= 2 * 10 % 3 < 5

= 20 % 3 < 5

= 2 < 5, gives 1 [Yes = 1 and No = 0]

Answer: 1

c.

#include <iostream>
#include <string>
#include <cctype>
#include <stdlib.h>

using namespace std;

int main()
{
string str, resultString = "";
cout << "Enter a string: ";
getline(cin, str);
  
for(int i = 0; i < str.length(); i++)
{
if(str[i] == ' ')
str[i] = '#';
else
str[i] += 3;
}
  
cout << "\nEncrypted message is: " << str << endl;
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a single C++ statements to accomplish each of the following tasks: In one statement, assign...
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
  • Write a single C statement to accomplish each of the following tasks: Assign the sum of...

    Write a single C statement to accomplish each of the following tasks: Assign the sum of x and y to z and decrement the value of y by 1 after the calculation. Multiply num by 3 using the *= operator. Increment variable x by 1, then subtract it from variable value. Add variable x to variable total, then increment x by 1.

  • Write a MATLAB program to accomplish the following: Create a variable x by assigning it the...

    Write a MATLAB program to accomplish the following: Create a variable x by assigning it the value 5. Then, subtract 8 from the square of x and assign the result to a second variable y. Next, create a vector z containing as values all the positive prime integers greater than or equal to 2 and less than 20. Multiply z by two and subtract y, and assign the result to w. ONLY display the value for w in the Command...

  • Write a single command line to accomplish the following tasks in Python 1- Count the number...

    Write a single command line to accomplish the following tasks in Python 1- Count the number of instances of each item in a list and produce another list of lists containing each item and its count. (Use the list count method) 2- Remove all words containing a capital letter at the end in a given string. (Use the join and ends with methods) 3- Remove every other letter from a string

  • Write C++ statements that do the following: Define an enum type, birdType, with the values PEACOCK,...

    Write C++ statements that do the following: Define an enum type, birdType, with the values PEACOCK, SPARROW, CANARY, PARROT, PENGUIN, OSTRICH, EAGLE, CARDINAL, and HUMMINGBIRD. Declare a variable bird of the type birdType. Assign CANARY to the variable bird. Advance bird to the next value in the list. Decrement bird to the previous value in the list. Output the value of the variable bird. Input value in the variable bird. Write C++ statements that do the following: Define an enum...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • EXERCISES: if & if...else STATEMENTS: Name Examples of if and if-else statements: Write an if statement...

    EXERCISES: if & if...else STATEMENTS: Name Examples of if and if-else statements: Write an if statement that multiplies payRate by 1.5 iſ hours is greater than 40. Write variable declarations for the variables payRate and hours first. Hint: Look for keyword if first, your boolean comes after the keyword [. This translates into Java as: double hours, payRate; if (hours > 40) { //{-} are optional here but I recommend that you them payRate = payRate 1.5; pay Rato pay...

  • Problems: 1. Write a program to define the following variables, assign them values, and print their...

    Problems: 1. Write a program to define the following variables, assign them values, and print their values on screen: Integer x = 20, Float y = 40.45 Double z = 91.51e+5 Char w = A • • For the integer variable x, you need to print it in decimal notations, octal notations and hexadecimal notation. For the double variable y, you need to print it in double notations and scientific notation. 2. Write a program with the following three parts:...

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

  • A) write a single c statment the do the following: 1) define two integr variables x...

    A) write a single c statment the do the following: 1) define two integr variables x and y 2) display the message "enter two numbers" 3) obtain values for varibles x and y from the kayboard 4) test if the currnet value of varable y is greater than the current value of variable x B) dfine a function that calculate the lengthe of hypotenuse of a right trinangle when the other two sides are given

  • in C Structures Homework 1. Write code to accomplish each of the following: a) Using t...

    in C Structures Homework 1. Write code to accomplish each of the following: a) Using t ypedef, declare a structure, Automobile, with the following members: mode1 - string of 25 characters maximum year - integer mpg - integer b) Declare variable car to be of type Automobile. c) Assign the information below to the appropriate fields of variable car: 2012 Infiniti gets 25 mpg. d) Declare an array, vehicle, of 500 Automobiles. e) Assign variable car to the 5th element...

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