It 218 Week 6 Assignment

Topics: Subroutine, C++, Java Pages: 3 (427 words) Published: April 17, 2011
//Ex7_02.cpp
//Creating and using boxes
#include <iostream>
using std::cout;
using std::endl;

class CBox//Class definition
{
Public:
double m_Length;//Length of box in inches
double m_Width;//Width of box in inches
double m_Height;//Height of box in inches

//Function to calculate volume of boxes
double Volume();
{
Return m_Length*m_Width*m_Height;
}
};

int main()
{
CBox box1;//Declare box 1 of type CBox
CBox box2;//Declare box 2 of type CBox
CBox box3;//Declare box 3 of type CBox

double boxVolume=0.0;//Stores box volume

box1.m_Height=18.0;//Define values
box1.m_Length=78.0;//of of the members of
box1.m_Width=24.0;//the object box1

box2.m_Height= box1.m_Height-10;//Define
box2.m_Length= box1.m_Length/2.0;//members
box2.m_Width= 0.25*box1.m_Length;

box3.m_Height= box1.m_Height-15; //Define
box3.m_Length= box1.m_Length/2.5 //members
box3.m_Width= 0.35*box1.m_Length;

//Calculate volume of box1
boxVolume= box1.Volume();

cout<<endl
<<”Volume of box1 =”<<boxVolume;

//Calculate volume of box2
cout<<endl
<<”Volume of box2=”
<<box2.Volume();

//Calculate volume of box3
cout<<endl
<<”Volume of box3=”
<<box3.Volume();

cout<<endl
<<”box3 has sides which total”
<<box3.m_Height+box3.m_Length+box3.m_Width
<<”inches.”;

cout<< endl
<<”A CBox object occupies”
<<sizeof box1<<”bytes”;

cout <<endl
return 0;
}

.

Under what circumstances must you use classes?

Classes are useful for length programs which require large amounts of similar code. Classes can accelerate program development by reducing redundant code, testing, and debugging. Using classes also makes the code easier to read and follow for other programmers.

Why do you use a class instead of a structure? Are they interchangeable? Explain your answer.

The...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay on Week 6 Assignment It/286
  • Week 6 Assignment Compatible Essay
  • Essay on Week 6 LT Assignment
  • Essay on Week 6 Assignment
  • Week 6 Assignment Essay
  • Week 6 Assignment 1 Essay
  • ECON Week 6 ASSIGNMENT Essay
  • Week 6 Assignment 3 Essay

Become a StudyMode Member

Sign Up - It's Free