Num Description 1 measurement.cpp -Write all of the member functions for the cla
ID: 3589750 • Letter: N
Question
Num Description
1 measurement.cpp -Write all of the member functions for
the class measurement.
- Use the starter file measurement.cpp
- The driver is already written.
- Execute the program and check that
your answers are correct.
Explanation / Answer
//measurement.h
#include <iostream>
using namespace::std;
class measurement
{
public:
// Constructors
measurement(void);
measurement(int y, int f, int i);
// Mutator Functions
void setYards(int);
void setFeet(int);
void setInches(int);
// Accessor Functions
int getYards(void);
int getFeet(void);
int getInches(void);
// Other Functions
void advanceOneInch();
// increase the inches amount by 1
// NOTE: you may have to advance the feet
// you may have to advance the yards
void output(ostream &);
void zeroOut(void); // set yards, feet and inches to 0
private:
int yards;
int feet;
int inches;
};
------------------------------------------------------------------------------------------
//measurement.cpp
#include"measurement.h"
measurement::measurement()
{
yards = 0;
feet = 0;
inches = 0;
}
measurement::measurement(int y, int f, int i)
{
yards = y;
feet = f;
inches = i;
}
// Mutator Functions
void measurement::setYards(int y)
{
yards = y;
}
void measurement::setFeet(int f)
{
feet = f;
}
void measurement::setInches(int i)
{
inches = i;
}
// Accessor Functions
int measurement::getYards(void)
{
return yards;
}
int measurement::getFeet(void)
{
return feet;
}
int measurement::getInches(void)
{
return inches;
}
void measurement::advanceOneInch()
{
int rem;
// increase the inches amount by 1
// NOTE: you may have to advance the feet
// you may have to advance the yards
//12inches is 1 foor,3 foot is one yards
inches++;
if (inches > 12)
{
rem = inches % 12;
feet += inches / 12;
inches = rem;
if (feet > 3)
{
rem = feet % 3;
yards += feet / 3;
feet = rem;
}
}
}
void measurement::output(ostream &out)
{
out << "yards = " << yards << " feet = " << feet << " inches = " << inches << endl;
}
void measurement::zeroOut(void) // set yards, feet and inches to 0
{
yards = 0;
feet = 0;
inches = 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
//main driver remains same as given in problem statement
#include"measurement.h"
void main()
{
measurement stackOfLumber(3, 2, 5);
for (int i = 1; i <= 200; i++)
{
stackOfLumber.advanceOneInch();
stackOfLumber.output(cout);
}
stackOfLumber.zeroOut();
stackOfLumber.output(cout);
stackOfLumber.setYards(6);
stackOfLumber.setFeet(2);
stackOfLumber.setInches(3);
cout << stackOfLumber.getYards() << ' '
<< stackOfLumber.getFeet() << ' '
<< stackOfLumber.getInches() << endl;
return;
}
----------------------------------------------------------------------------------------------------------------------------------
//output
yards = 6 feet = 2 inches = 11
yards = 6 feet = 2 inches = 12
yards = 6 feet = 3 inches = 1
yards = 6 feet = 3 inches = 2
yards = 6 feet = 3 inches = 3
yards = 6 feet = 3 inches = 4
yards = 6 feet = 3 inches = 5
yards = 6 feet = 3 inches = 6
yards = 6 feet = 3 inches = 7
yards = 6 feet = 3 inches = 8
yards = 6 feet = 3 inches = 9
yards = 6 feet = 3 inches = 10
yards = 6 feet = 3 inches = 11
yards = 6 feet = 3 inches = 12
yards = 7 feet = 1 inches = 1
yards = 7 feet = 1 inches = 2
yards = 7 feet = 1 inches = 3
yards = 7 feet = 1 inches = 4
yards = 7 feet = 1 inches = 5
yards = 7 feet = 1 inches = 6
yards = 7 feet = 1 inches = 7
yards = 7 feet = 1 inches = 8
yards = 7 feet = 1 inches = 9
yards = 7 feet = 1 inches = 10
yards = 7 feet = 1 inches = 11
yards = 7 feet = 1 inches = 12
yards = 7 feet = 2 inches = 1
yards = 7 feet = 2 inches = 2
yards = 7 feet = 2 inches = 3
yards = 7 feet = 2 inches = 4
yards = 7 feet = 2 inches = 5
yards = 7 feet = 2 inches = 6
yards = 7 feet = 2 inches = 7
yards = 7 feet = 2 inches = 8
yards = 7 feet = 2 inches = 9
yards = 7 feet = 2 inches = 10
yards = 7 feet = 2 inches = 11
yards = 7 feet = 2 inches = 12
yards = 7 feet = 3 inches = 1
yards = 7 feet = 3 inches = 2
yards = 7 feet = 3 inches = 3
yards = 7 feet = 3 inches = 4
yards = 7 feet = 3 inches = 5
yards = 7 feet = 3 inches = 6
yards = 7 feet = 3 inches = 7
yards = 7 feet = 3 inches = 8
yards = 7 feet = 3 inches = 9
yards = 7 feet = 3 inches = 10
yards = 7 feet = 3 inches = 11
yards = 7 feet = 3 inches = 12
yards = 8 feet = 1 inches = 1
yards = 8 feet = 1 inches = 2
yards = 8 feet = 1 inches = 3
yards = 8 feet = 1 inches = 4
yards = 8 feet = 1 inches = 5
yards = 8 feet = 1 inches = 6
yards = 8 feet = 1 inches = 7
yards = 8 feet = 1 inches = 8
yards = 8 feet = 1 inches = 9
yards = 8 feet = 1 inches = 10
yards = 8 feet = 1 inches = 11
yards = 8 feet = 1 inches = 12
yards = 8 feet = 2 inches = 1
yards = 8 feet = 2 inches = 2
yards = 8 feet = 2 inches = 3
yards = 8 feet = 2 inches = 4
yards = 8 feet = 2 inches = 5
yards = 8 feet = 2 inches = 6
yards = 8 feet = 2 inches = 7
yards = 8 feet = 2 inches = 8
yards = 8 feet = 2 inches = 9
yards = 8 feet = 2 inches = 10
yards = 8 feet = 2 inches = 11
yards = 8 feet = 2 inches = 12
yards = 8 feet = 3 inches = 1
yards = 8 feet = 3 inches = 2
yards = 8 feet = 3 inches = 3
yards = 8 feet = 3 inches = 4
yards = 8 feet = 3 inches = 5
yards = 8 feet = 3 inches = 6
yards = 8 feet = 3 inches = 7
yards = 8 feet = 3 inches = 8
yards = 8 feet = 3 inches = 9
yards = 8 feet = 3 inches = 10
yards = 8 feet = 3 inches = 11
yards = 8 feet = 3 inches = 12
yards = 9 feet = 1 inches = 1
yards = 0 feet = 0 inches = 0
6 2 3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.