Question

In: Computer Science

Write a single C++ statement to accomplish each of the following.                               &nbs

Write a single C++ statement to accomplish each of the following.                                                  (6 pts)

  1. Read an integer from the user at the keyboard and store the value entered in an integer variable age.
  2. Compute the product of the 3 integers contained in variables x, y and z and assign the result to the variable result

Solutions

Expert Solution

a. To read an integer from the user at the keyboard we use cin object of the iostream class. cin object is used with the >> operator to receive a stream of characters. General Syntax for cin operator is:

cin >> variableName;

For this problem we will first declare an integer variable with name age and then use the cin object to read an integer from the user at keyboard.

int age;
cin >> age;

Above statement will read an integer from the user at the keyboard and store the value entered in an integer variable age.

b. To get the products of integers we use the multiplication operator *. To solve this problem we will declare 3 variables of integer type x, y, z. We will initialize x, y, z with some random value and then we declare an integer variable result whose value will be equal to multiplication of x, y and z.

int x, y, z;
x = 3; y = 4; z = 7;
int result = x*y*z;

Above statement will compute the product of the 3 integers contained in variables x, y and z and assign the result to the variable result.

In above statement I have taken the value of x,y and z as 3,4 and 7 respectively. You can change it to any value you want or can change it to read value from the user at the keyboard by replacing the second line with

cin >> x >> y >> z;

If you're still having any doubt then please feel free to ask in the comment section.


Related Solutions

Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the...
Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the variable:       string s = “Introduction to C++”. 2. Change the letter ‘c’ to ‘C in the following string:    Reprint the string with “C”  given the code and using the string: string greeting = “Introduction to c++” 3. Write the C++ statement or statements that will:    Print the answer for regular division of the real numbers a / b + c and print the answer for integer...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered. b) Use a counter-controlled loop to read seven numbers, some positive and some negative, and compute and display their average. c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many numbers should be processed. For...
Following is the information of Huntington Co. income statement                                &nbs
Following is the information of Huntington Co. income statement                                       2018 2019 Sales                        $15.000 $12.300 COGS                          12.000 7.500 Gross profit                3.000 5.000 Operating expenses 2.000 3.000 Income before taxes 1.000 2.000 Income taxes (30%) 300 700 Net income                 700 1.400 In 2018 Huntington applied FIFO method for its inventory, and starting in 2019 Huntington decised to change the method to the average method. Following is the inventory in 2018 according to FIFO and average:                        31/12/2018                       FIFO Average Inventory...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Write a complete C++ program to implements a Min-heap. Each node will contain a single integer...
Write a complete C++ program to implements a Min-heap. Each node will contain a single integer data element. Initialize the Min-heap to contain 5 nodes, with the values 8, 12, 24, 32, 42. The program should allow for the insertion and deletion of nodes while maintaining a Min-Heap. The program should allow the user to output data in Preorder, Inorder and Postorder. The program should loop with menu items for each of the above objectives and the choice to quit.
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables a, b, and c, have already been placed in registers x10, x11, and x12 respectively. Use a minimal number of RISC-V assembly instructions. a = b + (c − 2); 2. Write a single C statement that corresponds to the two RISC-V assembly instructions below. add e, f, g add e, h, e 3. Assume that registers x5 and x6 hold the values...
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare...
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare the byte stored at the memory location pointed to by register R4 to the upper (higher) byte stored in register R5 b) Branch to instruction at label ‘ZERO’ if the lower byte of register R6 is zero c) Jump to the instruction at label ‘EVEN’ if the value in register R7 is an even number
For each of the following single strands of DNA, write the correct DNA counterstrand using the...
For each of the following single strands of DNA, write the correct DNA counterstrand using the rules of Watson-Crick DNA structure. To get the correct answer, your final structure must have: i) Antiparallel strands ii) Watson-Crick base pairs at each position 1. 5’-GCTGCATCCGTTAA 2. 3’-ATGGCTACTACGTA 3. TCGAATCCAGCTAGGC-5’
1. For each of the following, write a single SELECT query against the TSQLV4 database that...
1. For each of the following, write a single SELECT query against the TSQLV4 database that returns the result set described. Each of these queries involves two tables and can be written using a join operation. a. One row for each order shipped to France or Germany, showing the order ID, the last name of the employee for the order, and the customer ID for the order. b. One row for each employee who handled orders to Belgium, showing the...
For each of the following statements; on the line preceding the statement, write “T” if you...
For each of the following statements; on the line preceding the statement, write “T” if you believe the statement is True and “F” if you believe the statement is false. _____ The calculated value of the test statistic measures how far away the sample statistic is from the hypothesized value of the population parameter. __T__ Sample statistics can be used to estimate the value of a parameter of a population. _____ When evaluating the results of a hypothesis test, if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT