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;
�...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
C++ Programming: From Problem Analysis to Program Design
- dont use chatgbt to solve this question please and thank you.arrow_forwardQ2. Write a program that creates a class named BankAccount and contains: • Private attributes: • • ° ° id int), balance double and annual InterestRate (double). These attributes must never take a negative value. beneficiaries String [] ) to store the names of people who may receive the balance of funds when the account owner passes away. count static int ) to keep a record of the number of created objects. Constructors: 。 A 3-argument constructor that creates an account with given annual InterestRate), balance, and list of beneficiaries passed to the constructor as a series of names, e.g. BankAccount(3300, 6.7, "John", "Lili"). The constructor must increment count by 1, and then stores the new count into id. 。 A no-argument constructor that invokes the above 3-arg constructor and sets both balance and annual Interest Rate to 0, and beneficiaries to a new empty (String array of the size 3. Methods: ° Getter methods for all attributes. ° Setter methods for balance, annual Interest Rate °…arrow_forwardQ1. Create a class named Cuboid to represent cuboid objects and contains: • Three double attributes ①, W, and ʼn specifying the length, width and height of the cuboid. • A String attribute colour that specifies the colour of the cuboid. • A constructor (with 4 arguments) that creates a cuboid with specified values. • A constructor (with no arguments) that sets 1, w, and h to 1 and color to "white". This constructor should invoke the 4-argument constructor using the this keyword. • Your program must have these methods: 。 Getter methods for all fields (e.g. getColour () which returns the colour) о о getVolume: returns the cuboid volume which is 1*w*h getSurfaceArea(): returns the surface area of the cuboid: (2*(1*w + 1*h + w*h) displayInfo(): displays on the screen the colour, dimensions, surface area, and volume of this cuboid. Write a test program that creates two objects of the Cuboid class ⚫ the first object will have default values ⚫ the second object must be green of length = 8,…arrow_forward
- solve for thesearrow_forwardEach catalog costs $2 to mail (including printing, postage, and mailing costs). Based on this cost, the response rate from the test, and the average spend you can determine based on the purchasers in the dataset, using r studio estimate the gross profit that the firm could expect from the remaining 180,000 names if it selected them randomly from the pool.arrow_forwardConsider the following time series data: Month 1 2 3 4 5 6 7 Value 23 13 21 13 19 21 17arrow_forward
- help with this cmputer architecture program pleasearrow_forwardControl Theory I Mid-Examina on (2024-2025) Answer all questions Time: 1.0 hr. Q.1/ Find the overall transfer function, T(s) = C(s)/R(s), for the following block diagram system shown in Figure 1. G₁ H₁ Figure 1 H₂ C S G₂ G3arrow_forwardhelp with this computer architecture question pleasearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr