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

Explanation of Solution

The corrected program is given below with errors and corrections explained in the in-lined comments:

#include <iostream> 

#include <iomanip>

using namespace std; 

int main()  

{  

    //declare double pointer variables

    double *baseRadius;

    double *height;

    //set the print output format

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

    //allocate memory of type double and store the 

    //address of the allocated memory in baseRadius

    baseRadius = new double;

    //store 1.5 in the allocated memory

    *baseRadius = 1.5;

    //allocate memory of type double and store the 

    //address of the allocated memory in height

    height = new double;

    //store the value of the RHS expression in the allocated memory

    //RHS = 2 &*#x00A0;(1.5) = 3.0

    *height = 2 &*#x00A0;(*baseRadius);

    //allocate fresh memory of type double and store the 

    //address of the allocated memory in baseRadius

    //the earlier address referred to by baseRadius now

    //becomes a case of leaked memory

    //so it is essential to first deallocate the memory

    //using delete operator

    delete baseRadius;

    baseRadius = new double;

    //store 4.0 in the allocated memory

    *baseRadius = 4.0;

    //the code prints the address stored in baseRadius

    //instead of the actual radius of the base

    ///cout << "Radius of the base: " << baseRadius << endl;

    //so the correct code is

    cout << "Radius of the base: " << *baseRadius << endl;

  �...

Blurred answer
Students have asked these similar questions
What is the output of the code below:
(Python matplotlib or seaborn) CPU Usage We have the hourly average CPU usage for a worker's computer over the course of a week. Each row of data represents a day of the week starting with Monday. Each column of data is an hour in the day starting with 0 being midnight. Create a chart that shows the CPU usage over the week. You should be able to answer the following questions using the chart: When does the worker typically take lunch? Did the worker do work on the weekend? On which weekday did the worker start working on their computer at the latest hour?   cpu_usage = [ [2, 2, 4, 2, 4, 1, 1, 4, 4, 12, 22, 23, 45, 9, 33, 56, 23, 40, 21, 6, 6, 2, 2, 3], # Monday [1, 2, 3, 2, 3, 2, 3, 2, 7, 22, 45, 44, 33, 9, 23, 19, 33, 56, 12, 2, 3, 1, 2, 2], # Tuesday [2, 3, 1, 2, 4, 4, 2, 2, 1, 2, 5, 31, 54, 7, 6, 34, 68, 34, 49, 6, 6, 2, 2, 3], # Wednesday [1, 2, 3, 2, 4, 1, 2, 4, 1, 17, 24, 18, 41, 3, 44, 42, 12, 36, 41, 2, 2, 4, 2, 4], # Thursday [4, 1, 2, 2, 3, 2, 5, 1, 2, 12, 33, 27, 43, 8,…
This Code print the first occurrences of x, Please Modify the code to print the last occurrences of x  and print how many times it exists? ( with explanation for each line if possible) many thanks.
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,