Question

In: Computer Science

Write a program that accepts as input the mass, in grams, and density, in grams per...

Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density.

Format your output to two decimal places.

** Add Comments

Solutions

Expert Solution

  1. #include <iostream>

  2. #include <iomanip>

  3. using namespace std;

  4. int main()

  5. {

  6. //variable declarations and initializations

  7. double mass, density, volume;

  8. mass = 0, density = 0, volume = 0;

  9. //setting the output to have only two decimal places, even if the answer is an integer (10 would output as 10.00)

  10. cout << fixed << showpoint;

  11. cout << setprecision(2);

  12. //user prompts and user inputs

  13. cout << "Please enter the mass of an object in grams: ";

  14. cin >> mass;

  15. cout << "Please enter the density of an object in cubic centimeters: ";

  16. cin >> density;

  17. volume = mass / density;

  18. cout << '\n';

  19. cout << "The volume of the object is: " << volume << " cubic centimeters. \n";

  20. cout << '\n';

  21. //system("pause");

  22. return 0;

  23. }

  24. //end Main()

stdin

10 20

stdout

Please enter the mass of an object in grams: 
Please enter the density of an object in cubic centimeters: 
The volume of the object is: ----- cubic centimeters.

Related Solutions

Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
PYTHON Write a program that accepts a range of input from the user and checks whether...
PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
C++ language Write a program that accepts as input the base price and the finished area...
C++ language Write a program that accepts as input the base price and the finished area in square feet of the three models. The program outputs the model(s) with the least price per square foot in the following format: If the colonial model is the least price, output: The price per square foot of the colonial model is the least. If the split-entry model is the least price, output: The price per square foot of the split-entry model is the...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Write a progrm that accepts two strings as input, then indicates if the two strings are...
Write a progrm that accepts two strings as input, then indicates if the two strings are equal when the case of individual letters is ignored. Sample runs are shown below. Use C++ Enter two strings. String 1: PROgraM String 2: proGram PROgraM and proGram are equal. Enter two strings. String 1: litter String 2: LittLe litter and LittLe are not equal.
Write in C++ Write a program that accepts the names of three political parties and the...
Write in C++ Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received.   Be sure to provide labels (party name) and number-align your output values.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT