C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 12, Problem 9SA

Explanation of Solution

The program execution is explained in the in-lined comments:

#include <iostream> 

using namespace std; 

int main()  

{  

    //declare variables dec1, dec2 and initialize

    double dec1 = 2.5;

    double dec2 = 3.8;

    //declare double pointers p and q

    double *p, *q;

    //assign the address of variable dec1 to p

    p = &dec1;

    //assign the value of dec2 - dec1 to the memory

    //location pointed to by p which is dec1

    //so dec1 now holds the value (3.8-2.5 =) 1.3

    *p = dec2 - dec1;

    //q is assigned the value of p so both the pointers

    //now point to variable dec1

    q = p;

    //content of the memory location pointed to by q

    //is assigned 10.00 so dec1 holds the value 10.0

    *q = 10.0;

    //the contents of the memory location pointed to by p

    //i.e dec1 is assigned the value of the RHS expression

    //RHS = 2 &*#x00A0;10 + 10...

Blurred answer
Students have asked these similar questions
Write a C program that reads a double value (x) from the user and then uses it to compute the value of the mathematical constant e to the power of x (ex) and print it in main using the following infinite series: ex =1+x/1!+x2/2!+x3/3!+x4/4!+...       Your program should include the following three functions: 1- function called powerOfNumber which takes two parameters: x (double) and y (integer) and returns the value of xy . Function PowerOfNumber MUST use a while loop. ( Not allowed to use the predefined function pow in math.h). 2- function called factorialOfNumber which takes one parameter x (integer) and returns its factorial. Function factoriaOfNumberl MUST use a for loop. 3- function called computeExpo which receives one parameter x (double) and returns the value of ex for the given x using the series above as well as functions powerOfNumber and factorialOfNumber ( 1 and 2 above) . Function computer_ex MUST use a do/while loop. The loop should stop 1 when the new term…
Write a complete c++ program that does the following: -  Creates a function called 'convertDistance' that takes an integer input representing a value in miles, converts it to its decimal kilometer equivalent, and returns the result. -  Use this function in main to compute and print the kilometer-equivalents of all mile- distances from 10 to 100. -  You may use the following conversion: 1 mile = 1.6 km
The language we are using here is in Racket.  Please enter the following code: (cond ((equal? 16 3) (+ 3 8))       ((equal? 16 8) 12)       (else (* 6 3))) Write the return value for the above code. If replacing all of the 16's in the above code with 8, what is the return value?  What about replacing the 16’s with 3? What does the cond function do?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning