Question

C++ program

Write a program that does the following: n main0 1. Prompts the user to enter the height, length, and depth of a cube 2. Calls a function that will reduce the size of the height, length, and depth by half (ie. divide them each by 2 arguments must be passed using references handle possible resulting decimal values (ie. 3/2-1.5) 3. Calls another function that will calculate and return the volume of the reduced cube -arguments must be passed by value 4. Display the new height, length and volume of the cube ie. Height: 2.5 Length: 9 Depth: 3 Volume: 67.5 The volume should be a float displaying 1 digit of precision

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<iomanip>

using namespace std;

//Function to reduce dimensions by half
void reduceHalf(float &height, float &length, float &depth)
{
   height /= 2;
   length /= 2;
   depth /= 2;
}

//Function to calculate and return volume of cube
float volumeOfCube(float height, float length, float depth)
{
   return (height * length * depth);
}

int main(void)
{
   float height, length, depth, volume;
  
   //Prompt user to enter dimensions of cube
   cout<<"Enter height: ";
   cin>>height;
   cout<<"Enter lenght: ";
   cin>>length;
   cout<<"Enter depth: ";
   cin>>depth;
  
   reduceHalf(height, length, depth);//Reduce dimensions by half
  
   volume = volumeOfCube(height, length, depth);
  
   cout<<"Height: "<<height;
   cout<<" Lenght: "<<length;
   cout<<" Depth: "<<depth;
   cout<<" Volume: "<<setprecision(1)<<fixed<<volume;//Print volume with precision of 1 digit
  
   return 0;
}

OUTPUT:
CAUsers Shubham Desktop Untitled1.exe Enter height: !5 Enter lenght: 18 Enter depth: 6 Height: 2.5 Lenght: 9 Depth: 3 Volume: 67.5 Process exited after 5.442 seconds with return value e Press any key to continue

Add a comment
Know the answer?
Add Answer to:
C++ program Write a program that does the following: n main0 1. Prompts the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a c++ program that does the following: in main() 1. prompts for a student's name...

    Write a c++ program that does the following: in main() 1. prompts for a student's name (with spaces_ 2. prompts for 3 grades 3. Calls a function to calculate the average of the 3 grades - arguments must be passed by value 3. displays the student's name and average grade - example: Fred Smith : 85.5 - the average should be a float displaying 1 digit of precision

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • C++ please Problem 3: Write a C++ program that prompts the user to enter an integer...

    C++ please Problem 3: Write a C++ program that prompts the user to enter an integer of any length (but not more than 8- digits), the program then extracts and prints each digit in its respective column. For example, in the integer 436, 4 should be printed in the 4th column, 3 in the 3rd and 6 in the 6th column. Hint: you can use setw to solve this problem. Sample Input/Output Enter an integer of any length. 9836472 ...Printing...

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • USING PYTHON - Write a program that calls a function that prompts the user to enter...

    USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

  • On Dev C++, write a C++ program that prompts the user with the following option: 1)...

    On Dev C++, write a C++ program that prompts the user with the following option: 1) to enter a student information such as First Name, Last Name, SS# formatted as ###-##-####, userID and Password and store them into a struct data type. 2) to display the student information as shown in the example below: Name: Mary Last Name: Parker SS#: 000-00-1398 userID: mParker Password: ******** 3) Exit the program.

  • c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user...

    c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user to input a positive integer n, then calls the function generate() which generates n random numbers in the range [11, 217] inclusive. The function main() also calls the function indexMin() which finds the smallest random number and its index. The function main() prints the random numbers and the two values produced by the function indexMin(). Sample input/output: How many integers: 9 The 9 random...

  • use C++ to write the following program. needs to ask the user for n The user...

    use C++ to write the following program. needs to ask the user for n The user must put in those 5 values, probably using a for loop. NOTE: You can assume the number of values to be entered is 5. My attempted program below: (not correct, but just a basis) 4. Larger Than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume that the array contains...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT