Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Water is a SOLID below 0C, a LIQUID above that until it changes to a VAPOR above 100C. Add an if else {} block to

Water is a SOLID below 0C, a LIQUID above that until it changes to a VAPOR above 100C. Add an if else {} block to handle the case of a GAS, that is the case when T > boiling_point Notice the code uses the standard C++ string class, which you will find much easier to use than character arrays, given your Python background.

In the future, humans have colonized Titan, the largest moon of Saturn. The colony is located at Ligeia Mare, a sea near the moon's northern pole, made of almost pure methane. Ask the user to input if they are on Earth or Titan. If Earth - output the above results. If Titan, inform the user that their ocean is mostly made of methane and output the results for its state. Use these melting and boiling points to determine if the methane is solid, liquid or gas. Methane melting: -182.5 C Surface temperature on Titan is -179.2C. Methane boiling point: -155.15 C

a. Show your completed if/else if/else blocks to determine if the substance is a solid, liquid or gas.

b. Show your complete console session for a colonist on Titan if the temperature is 200 Celsius

Starting CODE:

#include

using namespace std;

// Determine the state of water or methane given its temperature in Celsius.

int main() { cout << " This program determines the state of water/methane given its temperature." << endl;

// by default, these settings are for Earth string location = "Earth"; // default location, but there are also humans at the colony on Titan float boiling_point = 100.0; // in Celsius for water float melting_point = 0.0; // in Celsius for water string substance = "water";

// add code to we ask if the user is on Earth or Titan. // reset the value of location

// Complete the if block to handle the case of Titan // reset the values for substance (to methane) and the melting and boiling points. if (location == "Titan") { printf("Greetings Titan colonist!");

// add code to reset the substance to "methane", we're on Titan! // reset the melting point to -182.5 // reset the boiling point to -155.15

printf(" The lake at Ligeia Mare is almost pure methane."); printf(" The average surface temperature on Titan is %.2f in Celsius.", -179.2);

} else { printf("Greetings visitor on Earth!"); printf(" The dominant substance in Earth's lakes and seas is water.");

}

printf(" Let's determine the state of %s at your location.", substance.data());

double temperature; // in Celsius cout << " Please enter the temperature in Celsius: "; cin >> temperature;

printf("The %s has a temperature in Celsius of: %f", substance.data(), temperature);

string state; // State of water/methane at given temperature: SOLID, LIQUID or VAPOR.

// check the boolean condition if (temperature < melting_point) { state = "SOLID"; } // Ack! We forgot the case for GAS!!!! // add an else if block to handle the case of "GAS"

else { state = "LIQUID"; }

cout << " At this temperature " << substance << " is a: " << state << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Determine the amplitude and period of each function.

Answered: 1 week ago

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago