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

Write JavaScript statements to accomplish each of the following tasks: a) Display the value of the...
Write JavaScript statements to accomplish each of the following tasks: a) Display the value of the seventh element of array f. b) Initialize each of the five elements of one-dimensional array g to 8. c) Total the elements of array c, which contains 100 numeric elements. d) Copy 11-element array a into the first portion of array b, which contains 34 elements. e) Determine and print the smallest and largest values contained in 99-element floating- point array w. PLEASE WRITE...
Consider the following income statement                                    &nbs
Consider the following income statement                                              Net Sales                        2,600.00 Cost of Goods Sold        -1,400.00 SG&A Expenses               -400.00 Depreciation                 -150.00 Other Operating Expenses -100.00 Operating income               550.00 Interest Expenses          -200.00 Income Before Tax             350.00 Income Tax (25%)          -140.00 Net Profit After Taxes      210.00 Reformat it as a common size income statement Calculate the net profit margin and gross profit margin The company has a $15 Capex and $10 change in net working capital. Calculate the FCF. Calculate the value of the...
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.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT