Over 10 Million Study Resources Now at Your Fingertips


Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Language:EN
Pages: 7
Words: 1227

Complete "Box" Class Code Homework Answers Needed

Your Question:

/* * CECS 2223, Computer Programming II Laboratory * Fall 2023, Sec. 09 * Date: August 23, 2023 * Topic: Parameterized Constructors and Class Variables * File name: Box.h * This file declares a class named Box * This file requires no changes *1 \#pragma once \#include using namespace std; class Box \{ private: static int boxcount; int height; int width; int length; public: Box () ; Box(int); Box(int, int); Box(int, int, int); Box (const Box\&); -Box (); void setHeight(int); void, setwidth (int); void setLength(int); int getHeight() const; int getwidth() const; int getLength () const; int getVolume() const; int getBoxCount () const; \}; void printBox() const; * CECS 2223, Computer Programming II Laboratory * Fal1 2023, Sec. 09 * Date: August 23, 2023 * Topic: Parameterized Constructors and class Variables - File name: Box.cpp * Name: [YOUR NAME HERE], ID\#[YOUR ID NUMBER HERE] * This file defines the Box class ⋆1 // do we need any preprocessor directives? // initialize the class variable to 0 // Define the default constructor; assign -1 to all fields // and increments the value of the class variable // The parameterized constructors assign the parameter's value // to the fields only if the value is valid. Use the ternary, or // conditional, operator for the assignment operation, using 0 // as the value to be assigned when the condition is false. The // parameters represent the values for the fields in the height, // width, and length order. For example, the constructor with one // parameter receives the value for height, and the one with two // parameters receives the values for height and width. // Recall that all constructors must invrement the class variable // The copy constructor assigns the attribute values of the parameter // to the new object and increments the value of the class variable. // The destructor does not include any code, it is defined Box: :-Box() \{ \} 1/ The set methods DO NOT prompt the user for values or include // any cout or printf statements. Make sure that the values // received as parameters are valid. Use the ternary, or // conditional, operator for the assignment operation, using the // current value of the field as the option when the condition 1/ is false. The setter methods have no return value. I/ define the get methods, they should all be constant // The printBox method uses printf to output values formatted // to be displayed in a table at 8 spaces per column aligned to // the left of the column. The values to be displayed are: height, // width, length, and volume. All values must be printed in the // same line. pic: Parameterized Constructors and class Variables le name: 1 ab02.cpp ne: [YOUR NAME HERE], IDF[YOUR ID NUMBER HBRE] mplete the Ct+ code as required we need any preprocessor directives? he main function returns an integer value, should be 0 main()< // declare a Box object, named box1, using the default constructor // assign a height of 1, width of 10 and a length of -20 to box 1 // declare a Box object, named box2, using the 1-parameter constructor // with a value of 2 for the height. // assign a width of -5 and length of 10 to box 2 1/ declare a Box object, named box3, using the 2-parameter constructor // with a value of 3 for the height and 4 for the width // assign a length of 12 to box 3 // declare a Box object, named box4, using the 3-parameter constructor // with values of -4 for height, 4 for width, and 4 for length // get the value of boxcount to complete the printf statement printf("The 8i boxes created have the following dimensions: in"); // table headers // using printBox method, print the dimensions for each Box object. cout ≪ endl; // assign a length of 20 to boxl // assign a width of 5 to box 2 // assign a length of -8 to box 3 1/ assign a height of 4 to box 4 1/ get the value of boxcount to complete the printf statement printf("The 81 boxes created have the following dimensions: (n"); // table headers printf (" -.-what to write here?---In", "HEIGHT", "WIDTH", "LENGTH", "VOLUME") ; // using printBox method, print the dimensions for each Box object // Write a statement which prints the phrase 1/ "Program developed by [YOUR NAME], IDE [YOUR ID NUMBRR]" f/ where the square brackets and the text within is substitued with 1/ your personal information. Make sure to include a blank line 1/ before and after the phrase. system("pause"); // for Visual studio use only return 0;// this statement MUST be included at the end of main

student submitted image, transcription available below

Step By Step Answers with Explanation

#pragma once

#include <iostream>

    int height;

    int width;

    Box(int, int); // 2-parameter constructor

    Box(int, int, int); // 3-parameter constructor

    void setLength(int);

    int getHeight() const;

    void printBox() const;

};

    boxcount++;

}

    boxcount++;

}

    if (width < 0) {

        width = 0;

    if (height < 0) {

        height = -1;

    if (length < 0) {

        length = 0;

    boxcount++;

}

    height = (h >= 0) ? h : height;

}

    length = (l >= 0) ? l : length;

}

    return width;

}

    return height * width * length;

}

    cout << "Height: " << height << "\tWidth: " << width << "\tLength: " << length << "\tVolume: " << getVolume() << endl;

}

    box1.setHeight(1);

    box1.setWidth(10);

    Box box3(3, 4); // 2-parameter constructor

    box3.setLength(12);

    cout << "HEIGHT\tWIDTH\tLENGTH\tVOLUME" << endl;

    box1.printBox();

    cout << "Program developed by [YOUR NAME], ID: [YOUR ID NUMBER]" << endl;

    return 0;

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Payment
Make payment
Document download
Download File
PageId: ELIC97FEF7
img
Uploaded by :
Ywx7A0EB
Page 1 Preview
parameter constructor box setlength box box
Sell Your Old Documents & Earn Wallet Balance