1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
uysha [10]
3 years ago
5

) Write a complete C++ program in one file which takes a double value from the user, cubes it, and prints the result. Your progr

am must use a function which takes a parameter for the value to be cubed and returns the result by value. The function may not print anything or read anything directly from the user (i.e. no cin/cout in the function). Hint: n cubed is defined as n*n*n. Upload as cubeValue.cpp. (8 pts
Computers and Technology
1 answer:
Jet001 [13]3 years ago
6 0

Answer:

The cpp program is given below.

#include <stdio.h>

#include <iostream>

using namespace std;

//function for cubing declared

double cubeValue(double n);

int main()

{

   //variable to hold user input

   double num;

   std::cout <<"Enter a number to be cubed: ";

   cin>>num;

   //variable to hold cube

   double cube;

   //function returns cube

   cube = cubeValue(num);

   std::cout <<"The cube of " <<num <<" is "<<cube <<std::endl;

   return 0;

}

//function to compute cube of the given parameter

//function definition

double cubeValue(double n)

{

   double d;

   d = n*n*n;

   return d;

}

OUTPUT

Enter a number to be cubed: 3.4

The cube of 3.4 is 39.304

Explanation:

1. The function for cubing is declared in the beginning of the program. The function has double return type as well as takes a double parameter. The function is defined after the main() method. The function only returns the cube of the double parameter passed to it.

double cubeValue(double n);

2. Inside main(), user input is taken for the number whose cube is to be computed.

3. The user input is taken in variable, num.

4. Another double variable, cube, is declared.

5. The method, cubeValue(), is called by passing variable num as parameter.

6. The value returned by the method, cubeValue() is assigned to the variable, cube.

cube = cubeValue(num);

7. The cube is displayed to the user using cout.

8. The program ends with return statement.

return 0;

The return statement assures successful execution of the program.

The program may not contain any syntax errors but contain logic errors which is indicated by the error message. The error message is displayed in red with return value -1.

9. The program is saved as cubeValue.cpp.

10. The method, cubeValue(), does not takes user input and does not prints any message.

11. The code is not written inside the class. The program contains only two methods.

12. The program can be tested for both integer and double values.

13. The program is written in cpp as per the requirements.

You might be interested in
Write the steps for displaying multiple subtotal functions in excel.
Sloan [31]

We can display multiple subtotal functions in excel using the following steps.

<u>Explanation</u>:

Step1: Enter the data you want to add in the excel sheet.

Step2: Select the cell containing the data you want to add.

Step3: Click the Data Tab

Step 4: Now select the SUBTOTAL command in the outline group.

Step 5: An option called ATEACHCHANGEIN will be available.

Step 6: Now select the drop-down menu under that option.

Step 7: After selecting the drop-down menu to select the columns you want to use for the first level subtotals.

By following these steps, we can display multiple subtotal functions in excel.

3 0
3 years ago
Connected contacts require___ to open.
wariber [46]
Manual power





hope it helps you
6 0
3 years ago
You would like to put the data in order by product number. What should you do?
Dafna11 [192]

If someone wants to put data in order (ascending or descending) they should sort the data.

c. Sort

<u>Explanation:</u>

Sorting is the process of arranging the data on the basis of some property or attribute. Using the find command, conducting a query, and mapping the data would not help.

There are various sorting algorithms like the bubble sort, selection sort, insertion sort, quick sort, and merge sort. Out of all the attributes, one or a combination of attributes can be selected to serve as the basis for sorting.

8 0
3 years ago
How do you answer questions
Vera_Pavlovna [14]

Answer:

like this

Explanation:

<h3>you click answer and then<u><em> boom</em></u></h3>
7 0
3 years ago
The code selection above is taken from the Color Sleuth activity you just completed. This selection would count as an abstractio
Vinvika [58]

Answer:

b

Explanation:

4 0
3 years ago
Other questions:
  • The code segmentif (speed &lt;= 40)cout &lt;&lt; "Too slow";if (speed &gt; 40 &amp;&amp; speed &lt;= 55)cout &lt;&lt; "Good spee
    11·1 answer
  • darren wants to substitute every occurence of the word bulky in his spreadsheet with the word strong. which of these options sho
    9·2 answers
  • Multiple arrays. Jump to level 1 For any element in keysList with a value greater than 40, print the corresponding value in item
    7·2 answers
  • Careers in information technology deal with
    12·2 answers
  • What is Java Script?
    13·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an <br> ___?
    14·1 answer
  • A collection of wiress connecting the CPU with main memory that is used to identify particular location is called
    13·1 answer
  • What is keyboard? answer me <br>​
    12·2 answers
  • Describe some things that this person might say that might cause you to NOT hire them. Explain.
    6·1 answer
  • _____ oversee the work of various types of computer professionals and must be able to communicate with people in technical and n
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!