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
Which item is essential to know before sketching a navigation menu flowchart?
alisha [4.7K]

Answer:

A, template specifics, such as horizontal or vertical menu layout

Explanation:

4 0
3 years ago
Read 2 more answers
An online game is played with two dice, explain why decomposition will be used in creating the algorithm for the game?
wolverine [178]
Decomposition will be used so you can break down the game into smaller and more manageable parts.
5 0
3 years ago
Read 2 more answers
Can you please look through this code and see wants wrong with it? its in python
Ivanshal [37]
I’m confused what are you trying to ask? What is the python?
3 0
3 years ago
Ill give you brainiest.
quester [9]
Hey there,

I believe that your correct answer would be that "<span> some people will tell you what they think you want to hear </span>". When you ask someone about the perceptions of your person trait, they will most likely <span>tell you what they think you want to hear because its what they want to make you happy. 

For example: Jimmy ask billy "Am I fat Billy"

                      Billy tells Jimmy "No, Your not fat, you look just great".

                         But really, Jimmy is very fat.

The point is that people are going to say things that make you feel happy and something that you want to hear.

~Jurgen</span>
6 0
3 years ago
You are most likely to use<br> images for photos or digital paintings.
Lubov Fominskaja [6]

Answer: Digital Paintings

7 0
3 years ago
Other questions:
  • Automotive engine cylinder heads can be made of what?
    7·1 answer
  • At a local burger chain, a customer became extremely angry. Everyone took notice at the person, who was yelling at anyone he cou
    10·2 answers
  • A computer application such as Microsoft Access that is used to store data and convert it into information is a ________________
    6·1 answer
  • what is the restaurant with the black pom tree and yellow backround three letter name from hi guess the restaurant
    14·2 answers
  • I want pizzzzzzzaaaaaaaaaaa
    9·1 answer
  • All systems have ___________.
    9·2 answers
  • __________ intelligence is an approach to boundary spanning which results from using sophisticated software to search through in
    15·1 answer
  • what you can do to increase your chances of getting employed with changes to your current digital footprint​
    6·1 answer
  • 11:25
    7·1 answer
  • Answer the following 8-mark question in your book.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!