Explanation of Solution
The program execution is explained in the in-lined comments:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//declare pointer variables and allocate memory
int *myPtr = new int;
int *yourPtr = new int;
//assign value to the memory location pointed to by myPtr
*myPtr = 10;
//assign value to memory location pointed to by myPtr
//using an arithmetic expression
//RHS expression = 2 &*#x00A0;10 + 3 = 23
*yourPtr = 2 &*#x00A0;*myPtr + 3;
//print statement using arithmetic expression
//value held in memory location myPtr is 10
//the second expression = (23 - 10 + 5) = 18
cout << *myPtr << " " << (*yourPtr - *myPtr + 5) << endl;
//pointer myPtr assigned the pointer yourPtr so
//now myPtr refers to the memory location holding
//the value 23
myPtr = yourPtr;
;&#...
Trending nowThis is a popular solution!
Chapter 12 Solutions
C++ Programming: From Problem Analysis to Program Design
- CODE USING C++ 1. Please Fix Me by CodeChum Admin Hi dear Programmer, I am broken. Can you please help me fix me? ?? Instructions: In the code editor, you are provided with a main() function that declares an array, sets its values, and then prints the sum of all of its values. However, there is a problem with how the array is declared. The array should be able to store 5 values. Your task is to fix the me array's declaration. Output 25arrow_forwardConsider the following C++ code: static long z = 5 ; int d = 10 ; int *ptr1 = new int[2] ; void myfun ( int param1 ){ static int x = 100 ; float y = 50; int *ptr2 = new int ; // . . .; delete ptr2 ; delete ptr1 ; } void fun2() { static int num =5; int var = 10; } Identify the storage bindings types, storage locations and lifetime of each variable. Select one for storage binding types: static, stack dynamic, explicit heap dynamic, implicit dynamic Select one for storage locations: static segment, stack, heap. Select one for lifetimes: Entire program, Execution of funct1, From Line ... to Line ...arrow_forwardExplain this c++ statement void bar(int* panam) {*panam +=1;}arrow_forward
- Please help me in c++ languagearrow_forwardTrying to write a gravity function in C languagearrow_forwardAssume the Product structure is declared in c++ as follows:struct Product{string description; // Product descriptionint partNum; // Part numberdouble cost; // Product cost}; Now write a loop that will step through the entire array array of 100 Product structures (do not initialize the array), setting all the product descriptions to an empty string, all part numbers to zero, and all costs to zero. ( Drop the screenshot of output as well )arrow_forward
- #include using namespace std; void myfunction(int num2, int num1); lint main() { my function (5,2); return 0; } void myfunction(int num1, int num2) {if (num1>3) cout << "A1"; else if (num1<3) cout<<"A2"; else cout<<"A3";} O A2 O A1 O A3 A1 A2 A3arrow_forwardLAB: Expression for calories burned during workout Instructor note: Important Coding Guidelines: Please do in C++ Use comments, and whitespaces around operators and assignments. Use line breaks and indent your code. Use naming conventions for variables, functions, methods, and more. This makes it easier to understand the code. Write simple code and do not over complicate the logic. Code exhibits simplicity when it’s well organized, logically minimal, and easily readable. The following equations estimate the calories burned when exercising (source): Women: Calories = ( (Age x 0.074) — (Weight x 0.05741) + (Heart Rate x 0.4472) — 20.4022 ) x Time / 4.184 Men: Calories = ( (Age x 0.2017) + (Weight x 0.09036) + (Heart Rate x 0.6309) — 55.0969 ) x Time / 4.184 Write a program with inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output calories burned for women and men. Output each floating-point value with two digits…arrow_forwardPROGRAMMING LANGUAGE: C++ You need to store hiring date and date of birth for teachers, and for students store their admission date and date of birth. You need to create a Date class for this purpose. Create objects of Date class in Teacher and Student class to store respective dates. You need to write print function in Teacher and Student classes as well to print all information of Teachers and Students. You need to perform composition to implement this task. Create objects of Teacher and Student classes in main function and call print function for both objects. Print Date class here. Print updated Teacher class here. Print updated Student class here. Print main function here. Print Outputshere.arrow_forward
- 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."…arrow_forwardDeal or No Deal? Code in C languagearrow_forwardin C++ Language can you answer that questionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education