Page 1 of 1

I'm having a lot of trouble understanding pointers and their uses. Here is a question I am stuck on. volumeValue and tem

Posted: Sun Jul 03, 2022 9:57 am
by answerhappygod
I'm having a lot of trouble understanding pointers and theiruses. Here is a question I am stuck on.
volumeValue and temperatureValue are read from input. Declareand assign pointer myGas with a new Gas object. Then, set myGas'svolume and temperature to volumeValue and temperatureValue,respectively.
Ex: if the input is 12 33, then the output is:
Gas's volume: 12 Gas's temperature: 33
CODE INCLUDED:
#include <iostream>using namespace std;
class Gas { public: Gas(); void Print();
int volume; int temperature;};Gas::Gas() { volume = 0; temperature = 0;}void Gas::Print() { cout << "Gas's volume: " << volume<< endl; cout << "Gas's temperature: " <<temperature << endl;}
int main() { int volumeValue; int temperatureValue; /* Additional variable declarations go here */ cin >> volumeValue; cin >> temperatureValue; /* Your code goes here */ myGas->Print(); return 0;}