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 13SA

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

    double *trip1Cost = new double;

    double *trip2Cost = new double;

    double *trip3Cost = new double;

    double *max;

    //store values in the allocated memory 

    *trip1Cost = 100.00;

    *trip2Cost = 350.00;

    //assign pointer variables to each other

    //trip3Cost now points to location having 

    //stored 350.00 later trip2Cost points

    //to location having a stored value 100.00

    trip3Cost = trip2Cost;

    trip2Cost = trip1Cost;

    //trip1Cost is now pointed to freshly allocated

    //memory location and assigned value

    trip1Cost = new double;

    //trip1Cost points to a location having

    //stored value of 175 and trip3Cost now

    //points to a location having a stored value 275

    *trip1Cost = 175;

    *trip3Cost = 275;

    //sets the output format

    cout << fixed << showpoint << setprecision(2);

    //prints the arithmetic expression

    //(*trip1Cost + *trip2Cost + *trip3Cost) which

    //evaluates to (175 + 100...

Blurred answer
Students have asked these similar questions
C++ only. Do not copy. Correct code will upvoted else downvote.   Monocarp is playing a PC game. Presently he needs to finish the principal level of this game.    A level is a rectangular framework of 2 lines and n sections. Monocarp controls a character, what begins in cell (1,1) — at the convergence of the 1-st line and the 1-st segment.    Monocarp's character can move starting with one cell then onto the next in one stage if the cells are nearby by side or potentially corner. Officially, it is feasible to move from cell (x1,y1) to cell (x2,y2) in one stage if |x1−x2|≤1 and |y1−y2|≤1. Clearly, it is denied to go external the matrix.    There are traps in certain cells. In case Monocarp's character winds up in such a cell, he bites the dust, and the game closures.    To finish a level, Monocarp's character should arrive at cell (2,n) — at the crossing point of line 2 and section n.    Assist Monocarp with deciding whether it is feasible to finish the level.    Input    The principal…
c++    Write a program to use enumeration type to represent the seven colors of the rainbow, i.e. red, orange, yellow, green, blue, indigo and violet, as the enumerators in sequence, and red starts from 1. Then, ask the user to choose a value between the range of 1 – 7. If the user enters 3, the output will tell the user yellow has been chosen, and also display the previous and next colors of the chosen colors. If the user enters 1 or 7, display the chosen color and only next/previous color is displayed accordingly. Write the program in an infinite while loop, until a number which is beyond the range of 1 – 7 is entered. The sample output is as follows, Enter a number in the sequence of the rainbow color (1-7): 7 Violet is chosen. The previous color is indigo. Enter a number in the sequence of the rainbow color (1-7): 1 Red color is chosen. The next color is orange. Enter a number in the sequence of the rainbow color (1-7): 3Yellow is chosen. The previous color is orange and next…
Code using c++ 2. Solving a Person's Loneliness by CodeChum Admin It's been 1,245 years and our sole Person is getting lonelier each day. This Person definitely needs a partner!   Thus, we need to update our Person's design to have a gender as well and there shall be male and female!     Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. Your task is to first update the struct Person so that it can have a gender as well. For this program, we shall represent a gender with a single character: 'M' for male and 'F' for female. Then, create a Person, take in an integer user input and a character user input, and then set them as the Person's age and gender respectively. Finally, call the displayPerson() function and pass that Person you created. Input 1. The age of the Person 2.…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education