2.7 Floating-point numbers (double)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given sphereRadius and piVal, compute the volume of a sphere and assign sphereVolume with the result. Use (4.0 / 3.0) to perform floating-point division, instead of (4/3) which performs integer division. Write whole code. Make output: sphereVolume output Volume of sphere = (4.0/3.0)pi r^3 (r^3 can be computed using *)

#include <iostream> using namespace std; int main() { double piVal = 3.14; double sphereVolume; double sphereRadius; cin >> sphereRadius; sphereVolume = (4.0 / 3.0) * piVal * (sphereRadius * sphereRadius * sphereRadius); cout << sphereVolume << "\n"; return 0; }

Determine the result. 0.0 / 5.0

0.0

Determine the result. 13.0 / 3.0

4.333333

Determine the result. 0.0 / 0.0

Not a number

Choose the best type for a variable to represent each item. Double or Int? A person's height in centimeters.

double

Choose the best type for a variable to represent each item. Double or Int? The average number of kids per household.

double

Which statement best assigns the variable? Both variables are of type double. a. cityRainfall = measuredRain - 5; b. cityRainfall = measuredRain - 5.0;

b

Which statement best assigns the variable? cityRainfall is of type double. a. cityRainfall = .97; b. cityRainfall = 0.97;

b

Which statement best declares and initializes the double variable? a. double currHumidity = 99%; b. double currHumidity = 99.0; c. double currHumidity = 99;

b

All variables are of type double and already-declared unless otherwise noted. Assign ballRadius with ballHeight divided by 2.0. Do not use the fraction 1.0/2.0; instead divide ballHeight directly by 2.0.

ballRadius = ballHeight / 2.0;

All variables are of type double and already-declared unless otherwise noted. Assign ballRadius with ballHeight multiplied by one half, namely (1.0 / 2.0). Use the parentheses around the fraction.

ballRadius = ballheight * (1.0/2.0);

Choose the best type for a variable to represent each item. Double or Int? The current temperature in Celsius.

double

All variables are of type double and already-declared unless otherwise noted. Declare a double variable named packageWeight and initialize the variable to 7.1.

double packageWeight = 7.1;

All variables are of type double and already-declared unless otherwise noted. Declare a double variable named personHeight.

double personHeight;

Choose the best type for a variable to represent each item. Double or Int? The number of cars in a parking lot.

int

Choose the best type for a variable to represent each item. Double or Int? The number of hairs on a person's head.

int

Determine the result. 12.0 / 0.0

positive infinity


Set pelajaran terkait

Ch 8: Project Quality Management

View Set

NUR 110 Taylor Chapter 7 - Legal Dimensions of Nursing Practice

View Set

Elite Grammar Week 6 (Misused modifier)

View Set

Cell compounds and biological molecules ch. 2 & 3

View Set

Quiz #1 -Radiation Protection (Chapters 1 & 2)

View Set