C++ Coding Help (Operators: new delete) Assign pointer myGas with a new Gas object. Call myGas's Read() to read the object's fields. Then, call myGas's Print() to output the values of the fields. Finally, delete myGas. Ex: If the input is 14 45, then the output is: Gas's volume: 14 Gas's temperature: 45 Gas with volume 14 and temperature 45 is deallocated.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter11: Introduction To Classes
Section11.3: Adding Class Functions
Problem 8E
icon
Related questions
Question
100%

C++ Coding Help (Operators: new delete)

Assign pointer myGas with a new Gas object. Call myGas's Read() to read the object's fields. Then, call myGas's Print() to output the values of the fields. Finally, delete myGas.

Ex: If the input is 14 45, then the output is:

Gas's volume: 14 Gas's temperature: 45 Gas with volume 14 and temperature 45 is deallocated.

 

#include <iostream>
using namespace std;

class Gas {
   public:
      Gas();
      void Read();
      void Print();
      ~Gas();
   private:
      int volume;
      int temperature;
};
Gas::Gas() {
   volume = 0;
   temperature = 0;
}
void Gas::Read() {
   cin >> volume;
   cin >> temperature;
}  
void Gas::Print() {
   cout << "Gas's volume: " << volume << endl;
   cout << "Gas's temperature: " << temperature << endl;
}  
Gas::~Gas() { // Covered in section on Destructors.
   cout << "Gas with volume " << volume << " and temperature " << temperature << " is deallocated." <<  endl;
}

int main() {
   Gas* myGas = nullptr;
   
   /* CODE HELP SOLUTION GOES HERE */

   return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage