the default constructor sets both feet and inches to zero, and the argument constructor sets feet and inches to argument values. Function setDist() asks user input for feet and inches, and printDist() displays feet and inches.
The add function adds the parameter distance to the current object and returns the total. The add function is const so it does not modify the current object. To perform addition, add feet to feet and inches to inches. The inches value of the total distance should be less than 12.
Exercise your class in main. Provide a menu to let user choose addition, subtraction, or exit. Loop until exit is chosen. If addition is picked, ask input for two distances, add them, and display the total. If subtraction is picked, ask for two distances, subtract one from the other and display the difference.
So if im understanding it, is it saying you'll pick add or subtract. Then you'll put in 2 numbers and it will add or subtract(which ever you chose). Then it will ask add or subtract again and repeat this process?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <conio.h>
using namespace std;
class CDistance
{
private:
int feet, inches;
public:
CDistance();
CDistance(int, int);
~CDistance();
void setDist();
void printDist() const;
int add(const CDistance&) const;
int subtract(const CDistance&) const;
};
CDistance::CDistance(int f, int i)
{
feet = f;
inches = i;
}
void CDistance::setDist()
{
cout << "Enter the distance. Feet then inches: ";
cin >> feet >> inches;
}
void CDistance::printDist() const
{
cout << "Feet: " << feet
<< "Inches: " << inches << endl;
}
int CDistance::add(const CDistance& total) const
{
}
|