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

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 type pointer variables

    double *length;

    double *width;

    //set the output format

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

    //allocate memory to be referred to by length

    length = new double;

    //the statement is incorrect as length is pointer

    //variable and not a double variable

    ///length = 6.5;

    //so the correct code is

    *length = 6.5;

    //statement is incorrect as & is an address of operator

    /// &width = 3.0;

    //so the correct set of statements are shown below

    //where first memory is allocated and then the value

    //is assigned

    width = new double;

    *width = 3...

Blurred answer
Students have asked these similar questions
This Code print the first occurrences of x, 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.
Trace the following code and give the output  int t = 2, r = 3, d; do { d = r * t; cout << d; r *= 2; t--; } while (t >= 0);
Examine the following code segment. What will be printed? If there are any errors indicate the nature of the error. int a[9] = { 1, 12, 3, 14, 25, 16, 7, 8, 9 }; int *ptr ; ptr = & a[ 2 ] ; for( i = 1; i <= 5; i = i + 2) cout << a[i] << *( ptr + i ); cout << ” ” << a[0] << ” ” << *ptr << ” ” << *ptr - 1 << ” ” << *(ptr - 2));
Knowledge Booster
Background pattern image
Similar 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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT