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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply