| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C++ for beginners? |
From: Gregg N
I cut and pasted from the actual file I compiled, but for some reason it
ended up missing the first line. I will try again:
#include
template
class Operands
{
public:
Operands(T a, T b) : a_(a), b_(b) { }
Operands(T a) : a_(a), b_(T()) { }
~Operands() { /* Nothing to do */}
T Add() { return a_ + b_; }
T Subtract() { return a_ - b_; }
T Divide() { return a_ / b_; }
T Multiply() { return a_ * b_; }
void ShowOps()
{
std::cout << "a=" << a_ << ",
b=" << b_ << std::endl;
}
void Display()
{
ShowOps();
std::cout << " Sum: " << Add() << '\n'
<< " Difference: " << Subtract()
<< '\n'
<< " Product: " << Multiply()
<< '\n';
if (b_ != 0)
std::cout << " Quotient: " << Divide()
<< '\n';
}
private:
T a_;
T b_;
};
int main() {
Operands op1(1);
op1.Display();
Operands op2(5, 6);
op2.Display();
Operands op3(3.14, 2.718);
op3.Display();
}
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.