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 of the following best describes the protocols used on the Internet?
max2010maxim [7]

Answer:

D: The protocols of the Internet are open and used by all devices connected to the network

Explanation:

There are billions of devices connected to the Internet, and hundreds of different kinds of devices: laptops, tablets, phones, refrigerators, handheld credit card readers, and so on. Protocols (standards) ensure that the variety of devices interact with each other smoothly.  There are a lot of protocols! The Internet was designed with several layers of abstraction that sort the protocols according to what part of the process they support.

5 0
2 years ago
Narrate an incident from the experience of a 14 year old girl which brings out the message: " Never leave till tomorrow what you
pogonyaev
Smth called google turbo record United in
7 0
2 years ago
Programmers can use sql on systems ranging from pcs to mid-size servers.
zaharov [31]

It is false that Programmers can use SQL on systems ranging from PCs to mid-size servers.

Applications for structured query language can be found in a wide range of sectors, mostly in those that deal with database-related tasks. It might be used, for example, by a data analyst to query data sets and produce precise insights. On the other hand, a data scientist might use this programming language to add data to their models.

Businesses and other organizations use SQL tools to create and modify new tables as well as access and edit information and data in their databases.

A database is a tool for gathering and organizing data. Databases can store data about people, things, orders, and other things. Many databases begin in a spreadsheet or word processor. Many firms find it beneficial to move them to a database made by a database management system as they grow larger.

SQL helps manage the data kept in databases, enabling users to get the precise data they require when they need it.

To learn more about SQL click here:

brainly.com/question/13154090

#SPJ4

4 0
10 months ago
This is a device that enables computers to be connected to a network.
zhuklara [117]

The answer to your question is,

NIC - Network Interface Card

-Mabel <3

8 0
3 years ago
WILL GIVE BRAINIEST! Your users are young children learning their arithmetic facts. The program will give them a choice of pract
Ierofanga [76]

In python:

numA = [4, 1, 6, 10, 2, 3, 7, 9, 11, 12, 5, 8]

numB = [2, 12, 10, 11, 1, 3, 7, 9, 4, 8, 5, 6]

while True:

   i = 0

   userChoice = input("Adding or Multiplying? (a/m) ")

   if userChoice == "a":

       while i < len(numA):

           answer = int(input("What is {} + {} ".format(numA[i],numB[i])))

           if answer == numA[i] + numB[i]:

               print("Correct!")

           else:

               print("That's incorrect. The right answer is {}".format(numA[i] + numB[i]))

           i += 1

   elif userChoice == "m":

       while i < len(numA):

           answer = int(input("What is {} * {} ".format(numA[i], numB[i])))

           if answer == numA[i] * numB[i]:

               print("Correct!")

           else:

               print("that's incorrect. The right answer is {}".format(numA[i] * numB[i]))

           i += 1

4 0
3 years ago
Other questions:
  • It takes an older computer twice as long to send out a company's email as it does a newer computer. Working together, it takes t
    15·1 answer
  • How can you best protect yourself when using social media
    5·2 answers
  • Select the focus questions that emphasizes what is more important: (Select all that apply) a.What needs to be relegated to the b
    8·1 answer
  • When you make a cell phone call, which type of electromagnetic wave is most likely transmitting the signal?
    12·1 answer
  • The function below takes one parameter: a string (date_string) containing a date in the mm/dd/year format. Complete the function
    11·1 answer
  • How can an administrator make only the files and folders to which a user has at least Read permissions visible?
    13·1 answer
  • Which feature is used to change how a presentation moves from slide to slide?
    14·1 answer
  • Which lighting technique can often heighten a dramatic story?
    14·1 answer
  • How to make a project using PID and thermacouple
    11·1 answer
  • _____ is rampant with bugs and shortcomings because most programmers do not know how or do not take the time to incorporate secu
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!