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...
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 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’
Write a C++ class that implement two stacks using a single C++ array. That is, it...
Write a C++ class that implement two stacks using a single C++ array. That is, it should have functions pop_first(), pop_second(), push_first(…), push_second(…), size_first(), size_second(), …. When out of space, double the size of the array (similarly to what vector is doing). Notes: Complete all the functions in exercise_2.cpp, then submit this cpp file. pop_first() and pop_second() should throw std::out_of_range exception when stack is empty. CODE: #include <cstdio> #include <stdexcept> template <class T> class TwoStacks { public:   // Constructor, initialize...
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...
1. Write the negation of each statement:
  1. Write the negation of each statement: (a) ∀? ∈ ℝ, ∃? ∈ ℝ such that ? < ? 2. (b) ∀? ∈ ℚ, ∃?, ? ∈ ℕ such that ? = ??. (c) ∀ even integers ?, ∃ an integer ? such that ? = 2?. (d) ∃? ∈ ℝ such that for all real numbers ?, ? + ? = 0. (e) ∃?, ? ∈ ℝ such that if ? < ? then ? 2 < ?...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based on a problem in the C++ text by Friedman & Koffman: The results of a survey of the households in your township are available for public scrutiny. Each record (struct-type entity) contains input data for one household, including a four-digit integer identification number the annual income for the household the number of household members. Assuming that no more than 25 households were surveyed, write...
Using C++ Write One one single program with two or more functioncallsWrite a C++...
Using C++ Write One one single program with two or more function callsWrite a C++ function, smallest Index, that takes as parameters an int array and its size and returns the index of the smallest element in the array. Also the program should test the function.Write another function that prompts the user to input a string and outputs the string in uppercase letters. You must use a character array to store the string.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT