All pastes #609742 Raw Edit

ho to the mo

public cpp v1 · immutable
·published 2007-07-09 01:38 UTC
rendered paste body
//The following partial definition is given for a class Pairs:#include <iostream>#include <string>using namespace std;class Pairs{public:    Pairs( );    Pairs(int first);    Pairs(int first, int second);    //other members and friends    friend istream& operator>> (istream& ins, Pairs& second);    friend ostream& operator<< (ostream& outs, const Pairs& second);    friend Pairs operator+ (const Pairs& first, const Pairs& second);    friend Pairs operator- (const Pairs& first, const Pairs& second);    friend Pairs operator* (const Pairs& first, const Pairs& second);private:    int f;    int s;};Pairs::Pairs ( ){    f = 0;    s = 0;}Pairs::Pairs(int first){    f = first;    s = 0;}Pairs::Pairs(int first, int second){    f = first;    s = second;}ostream& operator<< (ostream& outs, const Pairs& second){    outs << "(" << second.f << "," << second.s << ")";    return outs;}istream& operator>> (istream& ins, Pairs& second){    string inp;    ins >> inp;    sscanf(inp.c_str(), "(%d,%d)", &second.f, &second.s);    return ins;}Pairs operator+ (const Pairs& first, const Pairs& second){    Pairs alie;    int a, b;    a = first.f + second.f;    b = first.s + second.s;    alie = Pairs (a, b);    return alie;}Pairs operator- (const Pairs& first, const Pairs& second){    Pairs nowai;    int a, b;    a = first.f - second.f;    b = first.s - second.s;    nowai = Pairs (a, b);    return nowai;}Pairs operator* (const Pairs& first, const Pairs& second){    Pairs wai;    int a, b;    a = first.f * second.f;    b = first.s * second.s;    wai = Pairs (a, b);    return wai;}int main (){    Pairs hax1 = Pairs (5,6);    Pairs hax2 = Pairs (5,-4);    Pairs hax3 = Pairs (-5,4);    Pairs hax4 = Pairs (-5,-6);    Pairs imba, orly, owl, nou;    orly = hax1 + hax2;    owl = hax1 - hax2;    nou = hax1 * hax2;    cout << hax1 <<  " || " << hax2 << " || " << hax3 << " || " << hax4 << endl;    cout << orly <<  " || " << owl << " || " << nou << endl;    cout << "enter the imba: ";    cin >> imba;    cout << "the imba -> " << imba << endl;    return 0;}/*Question 5Turn the Pairs class from question 3 in this assignment into an ADT, so that separate files are used for theinterface and implementation.  Use separate compilation to compile the implementation separate from theapplication program that tests the ADT.*/