0 like 0 dislike
1.7k views

Write a class called Adder that stores the sum of all the ints given to it. Your Adder class should allow you to write the following main function (and code like it):

int main()
{
int x,y;
cin >> x >> y;
Adder sum1; // sum1 is initialized to 0 
Adder sum2(x); // sum2 is initialized to x
Adder sum3(y); // sum1 is initialized to y 
cout << "sum1 is " << sum1 << '\n'; // prints "sum1 is 0" 
cout << "sum2 is " << sum2 << '\n'; // prints "sum2 is x"
cout << "sum3 is " << sum3 << '\n'; // prints "sum3 is y" 
sum1 += x; //adds x to sum1; now sum1 is x 
sum2 += -3; // adds -3 to sum2; now sum2 is x-3
sum3 += 2; //adds 2 to sum3; now sum3 is y+2 
if (sum1 == sum2)
cout << "sum1 and sum2 are the same\n";
else cout << "sum1 and sum2 are not the same\n";
if (sum1 == sum3)
cout << "sum1 and sum3 are the same\n";
else cout << "sum1 and sum3 are not the same\n";
}

You should write the functions that are necessary for Adder to be used as in the above program. Combine them all together in your answer to make a perfect program. Use const wherever appropriate, and do not write or use a cast operator. Make sure to include any necessary header files.

Example input:

3 5

Example output:

sum1 is 0
sum2 is 3
sum3 is 5
sum1 and sum2 are not the same
sum1 and sum3 are not the same

 

[Exercise] Coding (C) - asked in C++
ID: 24588 - Available when: Unlimited - Due to: Unlimited

edited by | 1.7k views
0 0
Called for Help
0 0
Called for Help

31 Answers

0 like 0 dislike
Hidden content!
** * * * * ** * *

using namespace std;



class Adder{
* * ** *** * * ** *** *
** * ** ** ******* **** * *** * ** * * ** num)
** ** * ** ** * ** * * * *** ***** * * ** *
* * ** * ** *** * * * * ****** * * **** ** * ****** ** * ** **
* * *** **** ** ** * *** *** *
*** * ** ** *** ** * ** * *** * ** * * **
** *** * * ** *** * * * *** ***** * * **
*** ***** * * ** * ** * *** * **** ** *** * ** ** * ** ** * * ***
* * ** * ** ** * * *** ** * * * ********
** ** * *** *** *** ** ** * ** * ****** ** ** * *
* * * ** ** * * ** *** * ** * *** * ** *
** ***** ** ** *** **** ** * * * * ***** ** *** * * ***** x;
* ** *** **** ** **** * * * * ** **** ** * *
*** * * ** * * *** ** * **** ** * * * ** int b)
******* *** * *** * ** * ** *** * ** ** * **
*** **** *** *** *** ** **** * * * * * ******* ** * ** *** ** **
* * * *** * ** * ** * * *** ** ** *


* ***** ** * * ** ** * **** * * ** * *** ** operator == (const ** *** b)
* ** ******** **** ** *** ** **** * *** * *
**** ** * ****** * * ** * * * * * * * * ** * ** **** ***** * * * ** ****
* ** * ** ** ***** ** * ******* * ** * *** * ** ** ** * true;
** ** ** * ** * * * * **** * * ****** * * ** ** ** ** false;
* * ** * * * ** * * ** * ** ** **** ** * **** * * * * ** ***
* ** ** ***** * * *** * * **** ***** * ** ****
* ********** * * * * * * ****** *
** * ** * * * * *** * ** * ** ** * * * x;

};



int main()

{

int x,y;

cin * * * x * y;

Adder sum1; // sum1 is ** * ** to 0

Adder sum2(x); // sum2 is initialized to x

Adder sum3(y); // sum1 is initialized to y

cout * * * ** * ***** is " * ** * * * * * * ** '\n'; // prints *** ** is 0"

cout *** ** ** **** is " * * * ** * ** * * **** **** '\n'; // prints *** ** ** is * *

cout * * ** * * * * is " ** * *** * * *** '\n'; // prints * ** * * is y"

sum1 += x; //adds x to sum1; now sum1 is x

sum2 += -3; // adds -3 to sum2; now sum2 is x-3

sum3 += 2; //adds 2 to sum3; now sum3 is y+2

 

if (sum1 == sum2)

cout * * * ** *** * and sum2 are the * * ** ****

else cout * ** * ** **** and sum2 are not the ******

if (sum1 == sum3)

cout *** **** * **** and sum3 are the ** ** *

else cout * * *** * * and sum3 are not the *** ** **

}
answered by (-298 points)
0 like 0 dislike
Hidden content!
#include<iostream>

using namespace std;

class Complex

{
* * *** * * * **
* * ** * * ** * **** ***** *** n1, double n2){
* * * ** *** * **** ** * * * * * ** * * * **
* * ** * ** *** * * *** * ** * ** ** **

    } **** * ** * **** * *** * * ** *
* * * * * * **** * n3){
* *** ** * ****** * ** * ** ** ** *** ** ***
* ** * * * **** * * ** ** * ****** * *

    } *** *** ** * * ******* * * ** * ** * * ******* * ***** * **** *** * * * * *
* ** * * ** **** *** * *
* *** *** ** * *** **** ** * ** * ** ***
* * ** **** ** * ** ** * **
*** * ** ** ****** * **** * * * * * ***** ** ** * * ** ****** * * ** ** *** * *** ** ** ** *** ** * ** ** *** * ** * *** * * * * * * * *
* *** * * *** *** ** ** operator+ (Complex& b){
*** * * *** ** * ** ** ** ** ** * c;
** * * *** * * ** ** * ** ********* ** * **
** * ******* ***** * *** *** *** **** ** *** * * * ***
* * ***** ** ** * ** * ******* * ** *** * * *** c;

    }
** ** * * ** * ** ** operator- (Complex& b){
** **** ** ** * * ** **** ** * ** * * ** ** * c;
** * * *** * * * *** ** * *** *** * * ** * * *** ** *
** * *** ** ** * * *** *** * *** * * ** * *
*** * *** * *** **** * * ** ** * *** c;

    }
** * * * **** *** * *** *** geti();
****** * * ***** * * ***** getr();
*** ** * * * * * * print(); ** * *** * **** *** ** *
* ** * ****** *** * * *
**** * ****** * * * * * *** ** * * ** * ** r;
* ** * **** ** **** * ** * *** **** * i; * ***** ** * *** * * * * * *** * ** * ***** prints the complex number

};

void Complex::print(){
* * * *** * * ***** * * *
* * * * ** *** ** *** * * * * * ** ** * * * **** **** ** * + * * ** *** * ** * **** *** *****
* * * * * ***** **
* ** ** * ** * ** *** * ***** ** *** * ** * * * * *** ** * - *** * *** ** ** ** * ** * * *** * *** ****

}

Complex::geti(){
* * ** * *** * * * * *** * i;

}

Complex::getr(){
* * **** * ** * * ** ** ** * r;

}

int main()

{
******* * ** * * * * ar,ai,br,bi,cr;
** ** * *** ** ** ** *** * ** *** * ** * ***** ** * ** * * * *** * * * ** *
*** ** ** ** * ** * **** a(ar,ai);
** *** * * * *** ** * * << "Constructor with two values: a = ";
****** **** ** ** * ** *


*** ** ** ** * * * * ** b(br,bi);
* * * **** ** * * ** * ** *** << "b = ";
* ** ** * * * * *** ** *


* *** * ** ** ** * ******* c(cr);
* ** * *** *** **** ** **** * * << "Constructor with one value: c = ";
*** *** * * **** * *****



    c = a + b;
** *** ** * ** **** * << "a + b = ";
******** ** * ** * ** * ** ** *


* * *** * ***** * * *** * d;
* * * * **** * << "Default constructor: d = ";
* *** * * *** * *


* * * ** * ** * = a - b;
* * *** ********* * ** * *** ** << "a - b = ";
**** ** ** ** ** * ***


* *** ** * * *** * ****** 0;

}
answered by (-298 points)
0 like 0 dislike
Hidden content!
#include<iostream>

using namespace std;

class Complex

{
* * * * * ** ***** ** * **
** *** *** * * * *** **** ** n1, double n2){
* * * ** *** * ******* * *** * ** * ** * ** *
** *** * * * * * * **** ** ** * *

    } * ******* ** ** * * * *** * *
** * * * * * ** * * **** n3){
* ** * * **** * * * * ** ** * * **** *
**** *** ** ****** *** ** *** * ** * **** **** *** **

    } *** ** * **** ** * *** ** * * ****** * * * * * * ** ** ** *
* * * * * * * ** * **** * **
*** * ** * * **** ** ** ** ** * * * ** * * ** *** *
* **** ****** * * * * **** ******** ** ** **
* * ** ** *** ***** *** * *** * *** * ****** * * * ** *** * * *** *** ******** * * * *** * ** * ** ** * * *** ***
** * * * * * * ******* * *** operator+ (Complex& b){
** *** ** * *** *** ***** * ** ** ***** ** c;
* * **** ** * * ** * * ** * * ** * * *** *** **** *** ** * *
** * *** * * ** ** * ** * * ** ** * *** ***** * *
* * * * * * * * ** ** * * ** **** ******* * c;

    }
** * * * ** * ** ** **** * operator- (Complex& b){
* * * *** ** * **** ** * ** * ** * * ** c;
* * * * ** * ** ******** * ** ** * * ** *** * ** * ** ** **
* * ** * * * * ** * *** ** ** * ** ***** *****
* ** ** * * * * ** ***** *** * ********* * * * * * *** c;

    }
* * ** * * * ** ******** geti();
* *** * * * * ** * * *** getr();
* * * ** * ******* * print(); **** * ** ** * ******* * * *** **
* **** * **** ** ** ** * * **
*** * * * ** * * * *** **** * ***** * r;
* *** ** * ** *** ***** *** * * * * *** * * * i; * ** ** **** * * ** *** ***** **** ** * ***** * prints the complex number

};

void Complex::print(){
* *** ** **** * ** ** * * **
* * ** *** *** *** * **** **** ** * *** * * ** *** * *** * ** ** **** + *** * * ** ** *** **** ** * * ** **** *
** ** ** * ** * *
*** * ** ** * * * * * * ***** * * * ****** ** * * * * * * ** ** **** - * *** **** * ** ** * *** *** ****** *

}

Complex::geti(){
** * * ******* * * ** i;

}

Complex::getr(){
* ** ****** ** *** * ** * ** r;

}

int main()

{
** ** ** * * * **** * * * ar,ai,br,bi,cr;
* ** *** * * * ****** * * * * ** **** ** * * ** *
* ***** * * ** * ** a(ar,ai);
* ** ** ** * ** * << "Constructor with two values: a = ";
** * *** ** * *** * *


* ** * * * * ** * b(br,bi);
** * ** ****** * ** * **** << "b = ";
***** ** * * * *** * * ************


* * ** *** * * ** * ** c(cr);
* **** * * ** * ** * * ** << "Constructor with one value: c = ";
** * ** ******** ***** ***



    c = a + b;
* ** ** * ** ** << "a + b = ";
* * ** ** * ** ** **


** ** * * ** ** * * d;
* ** **** ** **** ** ** << "Default constructor: d = ";
***** * * *** **** *** ** * *


**** * **** ** * * ** = a - b;
* ** * * ** **** * << "a - b = ";
* *** *** ** * * * *


**** ** ** ** **** ** ** * * 0;

}
answered by (-249 points)
0 like 0 dislike
Hidden content!
** ** *** ***
* * * ** * *



* {

** **** * * ** *
* * ** ** ******** **

* * * * * * ** * ** **** * ***
* ** ** * * **
* * ****** ** * * * ***** * ** * * ** * = 0;
**** * * * *** * *
* ** *** ** * * * ** ** n){
* **** ** * * * ** ** ***** *** * ** ** = n;
* *** * * **** ** * **
* * * * **** ** * ** * ** *** n) ** += n;}
* * * ** * * * **** **** * **** * ** * ** x, * * ** * y); * *
** * * *** ** * **** ** ** * * * ****** ** * ** *** ***** x);

};


* * ** *** * x, ** * * * y){ ** **
* *** * * * * * * * * * * * * *** == ****

}
** ** ** ** ** ***** **** * ** * **** ** ** * x){

**** * ** **** * * * ** ostr ***** * *

}



int

{

int x,y;
** ** * * * *** x * * * * y;
* * * // ** is *** * to 0

* * ** // sum2 is * to x
* * * *** // sum1 is * * to y

cout * ** * *** ** * is * * * **** * ** ** ** * ** * // ** * ** * is *** ****

* *** *** * * is **** * ******* ** ** ***** ** // * ** *** ** is ***
* * * * * ** * *** * * * is *** **** * **** * * * * ** ** // * * ** * **** is * * *

* += x; ** x to now * is x

*** += -3; // ** -3 to * now is x-3
* += 2; * ** 2 to * now * is y+2

if ** == ***
* ** *** ****** * ** and * are the * * ** *** *
* ** * * * and sum2 are not the **** **

if *** == ** *
* * * * * * * * * and sum3 are the * * ** ***
* *** ** ** * and sum3 are not the ** * ***

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
**** ** **** * ***

using namespace std;



class Adder{
**** * *** * ** * ******** *** * *
* * ** ** ** * ** * * * * **** * * * *** *** ** num)
* * * ***** * * ** * ** * ** *** * ** *** *
* * * ***** ***** * * * * *** * * ** * * *** ** *** ** * * ** * ** * *
*** ** ** *** ** * *** * ** * * *****
* * ***** * ** ** * **** * *** ** ** * ** **
* * * ** * ** * * ** * * *** * *** *
* * * ** * * *** ** *** * ** * ** *** ** * * * * * * ** * *
* * * *** ** * ****** * * **** *** **** * *
* * * *** * **** * ***** * *** * ** * * ** ** * * * **
** * **** * ** *** * ** * ***** * * ***** ** * * *
*** ** * * * ** *** ** * * ** ** * * * * * *** *** ** ** *** * * x;
* * * * **** * *** * ** *** * * * * ** * *
* * * *** * * **** *** * ** * ** * * * * * * * int b)
* ** * * **** * **** **** * * * * * ****** *
*** ** * * * ** * * * *** **** *** * * * * * * * * * * * * ** *
* * **** *** ** * * ** * * * * * **


* ** * * **** * ***** * *** ***** ** operator == (const * ***** * b)
**** * * ** ** * ******* * * **** * * * * ** * * *
** ** **** * * * *** * * ** * * * * ** ** * ** * ** *** *** * * * * *
* ** ** ** ****** ** *** ** **** **** *** *** * ** ** ** * ** ***** true;
*** * *** ** * ** ** * ** * * * *** ** **** ** ** * * **** **** false;
*** **** ** *** * * *** * * * * * * ** ** **** * ******* * * **
** * ***** * ** * * * * ***** * ** **
* * * * * * **
**** * * *** * * ***** *** ** * ** * * * * x;

};



int main()

{

int x,y;

cin *** ** ** x * * ** y;

Adder sum1; // sum1 is * * * to 0

Adder sum2(x); // sum2 is initialized to x

Adder sum3(y); // sum1 is initialized to y

cout **** ** * * * is " * * * * * * ** * ** * '\n'; // prints *** ** is 0"

cout * ** ** * * ** ** * is " *** * ***** * * * ** ** ** ** '\n'; // prints ** is ** *

cout * *** ** ** * * is " ** *** * *** ** * * * '\n'; // prints **** is y"

sum1 += x; //adds x to sum1; now sum1 is x

sum2 += -3; // adds -3 to sum2; now sum2 is x-3

sum3 += 2; //adds 2 to sum3; now sum3 is y+2

 

if (sum1 == sum2)

cout * * * * * * * and sum2 are the ** ****

else cout **** * ** ** and sum2 are not the *** *

if (sum1 == sum3)

cout ** * * * ** * and sum3 are the ***

else cout *** * * and sum3 are not the * ** * **

}
answered by (-412 points)
0 like 0 dislike
Hidden content!
#include * *** **** * *
* * ** ** * *** *

using * * * std;



class Adder{
* * *
* ***** * * * sum;
****
* * *** * *** ** * * (int x){
* ** *** * * ** * *** * *** * ** ** * * = x;
** ** * * * * * * ** *
******* ** ** ** ** ** ***
* *** * * * * ** **** *** * * * * * = 0;
* *** * * * * * **
** * * * * *** *** * ** ** * *** * * * *** *** * ** * *** *** * * *
* * **** ***** * * ** * *** * bool operator * ** * * * b, const ** c);
* * * ** *** ** ** *** * * * *** int x) {
* * *** **** * *** * ** *** * * += x;
* *** *** ** *** * ** ** ** * * *** ** * *this;
* * * * **


* * * * * * *
* * ** * * * *****
* * * *** * * *

};

bool operator ==(const * **** b, const ** ** * c){
* * * ** * ** * *** * (b.sum == c.sum);

}


********** ** ** **** ** * ** *** *** ***
*** ** * * * *** ******* * * ** * ***
* *** *** * * * ** *** * out;
** * * * **** **

}







int main()

{
**** * ** ** ******* * *** ** x,y;
**** *** * * *** ***** ** ** ** **** x * *** * * y;
*** **** * **** * **** sum1; // sum1 is * ** * to 0
* ** * ** *** ** ** sum2(x); // sum2 is * * ** to x
**** * * **** * * ** ** ** * * // sum1 is * to y
** * * ** *** ** * **** * ** * * * is *** * *** * sum1 * ** * ****** '\n'; // prints * is * ***
** * ** * ** * ** * * * *** * * * * * **** ** is *** * ***** * **** sum2 ** *** '\n'; // prints *** * * is * ****
**** ** * ** *** * * * * * ***** ** * ** is ** ****** sum3 ** ** '\n'; // prints * is ** * *
* * **** * ** ** * * += x; //adds x to sum1; now sum1 is x
* **** ** **** *** += -3; // adds -3 to sum2; now sum2 is x-3
* * * ** ** * += 2; //adds 2 to sum3; now sum3 is y+2
** ******** * * * * *** (sum1 == sum2)
**** * **** * * ** * * ** ***** *** ****** * * * * ** * * ** and sum2 are the ** * * ** *
** ** ** * * ** cout * * ** ** * ** * and sum2 are not the ** ****
* * ** **** ** * * (sum1 == sum3)
**** ** *** ** *** * ***** ** * * * ** * * * ** **** and sum3 are the *** * *
** ** * ***** ** * * cout ** * * ** * * ** and sum3 are not the *** ****
* ****** * * ** * ** ** * // prints * ***** * is * *

}
answered by (-368 points)
0 like 0 dislike
Hidden content!
#include ** * * * *
** *** ** *****

using * * * std;



class Adder{
*****
** * * ** * * **** sum;

public:
** * *** *** ** * * ** (int x){
* * * **** * ****** **** *** * ** * * * = x;
* * *** ** ** * * *
* ** * ** * **** *** **
* * * **** * * * * * * ** * * *** * * * *** = 0;
** ** * * **
*** **** * ** *** * ** ** * ** * * * ** **** * **** * *** * * ** *** **
* * ** ** * * ** * * * * bool operator ==(const * b, const ** c);
** * ******** ****
* * ** * * *** * *** * ** * * * * *** * b) {
* * ** *** * * ** * ***** * * ****** * *** * * adder;
* **** * *** * * * * *** *** ** **** ***** ** ** = ** * * + b.sum;
* ******* * **** ***** ** ** ** * * * * * adder;
** * * * * * ******
** ** * ** * ***** **** *

};

bool operator ==(const * **** * * b, const * c){
* *** * * ** ***** * * *** (b.sum == c.sum);

}




**** ****** ** ** *** ** ** * * * * * * ***
* **** ******* * ** * * ** ** * *
** *** ***** ** * ** ** out;
* ** ** ** ** * * * *

}







int main()

{
* * * * * * ** * ** ** x,y;
** ** ****** ** * * ** * * ***** * * x * *** * y;
**** * ** * * *** * * **** ** sum1; // sum1 is ** * to 0
*** * * ** * * ** * * * *** * // sum2 is * to x
* ******* * ** * * ** *** ** // sum1 is ** * * to y
**** ****** *** * ***** **** *** * * is * ** ** *** ** sum1 * ****** '\n'; // prints ** * *** is ** * **
*** * ***** ******* * ** * ** * *** is * ** ** * *** **** sum2 **** ** * '\n'; // prints * * * is ** * *
* ** * * * ** * * * * ** *** *** * * * is ** * * * * sum3 * ** **** '\n'; // prints **** ** is ** * *
** * *** * * * ** * ** ** += x; //adds x to sum1; now sum1 is x
* ** * ** * * * += -3; // adds -3 to sum2; now sum2 is x-3
****** ** ** ** * * ** ** += 2; //adds 2 to sum3; now sum3 is y+2
* * ** * * (sum1 == sum2)
** * ** ***** * * * * * * * * *** * *** ** * ** * ** ** ** and sum2 are the * ** **
** * * ** ** * **** * cout **** * * * * * ** and sum2 are not the *** *
**** * ** ********* * *** (sum1 == sum3)
*** *** * * * * ** ** *** *** * * ** *** * * * * *** and sum3 are the ** * * **
***** ** * ** * * cout ***** * * ** ** and sum3 are not the * *****

}
answered by (-368 points)
0 like 0 dislike
Hidden content!
* * * ** *
* ** * ** std;


* * **

{
***
**** **** **** *** * ** * * * *
* * * * * **** * ** *
* ** * * **** * * * *
** * * * * * ** * * * ****** * ** ** ** * *
* * **** **** * * * * * ** *** ** *


**
** * * **** * *** * * * **

};


** **** * *** * * *** ano)

{
**** *** *** * *** * *** * value * ** * * endl *** * * ** * *** * **
** * * * * ** ** * * ** *** *
** * * *** **** ** * ** **** * ** * * ** * ****** ** *
* *** ** ** *** *
** ** *** * * * * **
* * ** ** ** * *** * * *** ** *** ** * * **

}


** ** * * * * *** ** * ano)

{
** *** * * * ****** ** * * *
*** ***** ** ** ** * = this ** * ** **
* **** * * * *** ** * = * * *

}


* ****

{
** * * * ******* ***** *

}


******** * * *

{
**** ****** ***** ** ****** ** ***

}



int ** * **

{
** * **** * ** ** ** * **

}



int **

{

int x,y;

cin * * * **** x *** ** * y;
* * // sum1 is ** ** to 0
** * * // sum2 is ** **** to x
* ** * // sum1 is * * to y
* *** * *** ** * ** is *** * *** *** * * *** * *** // ** * * * * *** is * * *
* * * *** * **** ** is *** * * * * *** *** * * ** ** // * * ** * * is ***
* * * * ******* * is *** * * * * *** * ** * * ** // ** ** ** **** is ** ***
*** += x; ** x to now sum1 is x
** += -3; // adds -3 to * now sum2 is x-3
* += 2; * * 2 to ** now sum3 is y+2

if * * == *
** *** *** ** * * and sum2 are the * *** *
** cout * * * ** and sum2 are not the *** * *

if ** ==
*** * ** * * * *** and sum3 are the * *

else cout ** * *** * ** ** and sum3 are not the ** ****

}
answered by (-581 points)
0 like 0 dislike
Hidden content!
** * * * * * **



using ** std;



class Adder

{
* **
* ** ** * * **** x;
* * * *** * ** ****** num;



public:
** * ** **** * * * * * *
* * *** ** * * * a);


*** ** * ********** * * * ** * ** (int z)
* * **** * ** ** * *


* ** * * ** * * ** **** * * ******* * = x + z;
**** ***** **** * * *** * * *** * * ****** ** * num;
****** * * ***** * * * *


** ** * * ***** get();


** *** * * ** ** * * x;};



};


* * ***

{
* * * **** *** = 0;





}


* * *** * a)

{
* * ** * ** * **** = a;



}



int **** **

{
*** * * ** * * * * *** * num;

}





int main()

{
* * * ** * * * * x,y;
* * *** * * * *** ********* * * ***** x * * y;
* *** * *** ** ** sum1; // sum1 is * *** * to 0
** *** *** ** *** * sum2(x); // sum2 is ** to x
** * ** *** ** * *** * sum3(y); // sum1 is * * *** to y
* **** * **** **** ** *** * *** ** * is ** * * *** ** ** * ***** * * * ** ** * '\n'; // prints * * is * * ** **
* * * ** **** ** ** * ** ** * ***** *** is * ** * * * * ** ** * * * * '\n'; // prints ** * * is * *
** ***** * * * * * * * * ** ** * * is ** * * ** ** ** ****** * **** ** '\n'; // prints ** * is ** **
**** * * * * * *** * * += x; //adds x to sum1; now sum1 is x
* * ** *** ** * *** *** += -3; // adds -3 to sum2; now sum2 is x-3
* ** *** ** * ** * * * += 2; //adds 2 to sum3; now sum3 is y+2
* * * * *** ** * ** * *** *** == * * * *
*** ******* *** ****** *** * * * * ****** ***** * ***** * ** *** and sum2 are the ** * * *
* ** * *** * ** **
* * ** * *** ** * ***** ***** * ******* * ** * ****** **** ** and sum2 are not the ** * * *
* *** ** *** ** * ** * == *** * **
* ** * ***** * * * * ** * **** * ** * *** ** * *** ** *** * * * * and sum3 are the * ** ** **
* * ** * * *** * * * *****
** ** *** * ** * * * *** ** * **** *** *** * * ** *** * and sum3 are not the ** * **
* * * * * * ** ** * * ****** 0;

}
answered by (-189 points)
0 like 0 dislike
Hidden content!
***** * * * *
* * ** * ** ******



using ** ** std;



class Adder

{
** * ** *** * * * * **
****** ** ** * * ** * *** **** ** ** *** * ** * a;
* *** *** *** * ** * * ** **


* * * ** ** * ***** x)
* *** ** ** * **
** ** ** * *** * *** * * ***** * * **** ** = x;
***** * ** * ** ***
** * ** ** ** * **** **
**** ** * * *** ** *** *
* * * * * * * **** * *** * * ** * * * = 0;
* * ** * ** * *


* * ** ** * * ** **** ***** * * (const Adder * **
* ** *** ** * *


***** *** * ** ** * * * **** **** *** * * ** ** **
* **** *** * * ** * * * * * * ***** * * * * *this;
** * * **** * * *
** ** * ** * **** *** * ** *** * (const * * * * x)
* * * ** **** * * **
**** ** ****** ** ** ** * ** ** temp;
* * * * **** *** * ** ** * * * *** **** *** * * = * * * **** a-x.a;
** ** ** ** **** ** ** * * ** **** ****** * *
* * **** * *** * ** **** *** * *** * ** ** *** *** *** ** ** * 1;
* **** * * ** * * * *** **** *** ** *****
**** ** *** * * * *** ** * * * * ** ** ** ***** ****** ** * 0;
** ** ** ** **
* ** * * * **** ** g()
* *** * *** *** * **
** *** ** * ** * * ** *** * *** * * * a;
* * ****** *** ** **** *****



};



int main()

{

int x,y;

cin *** * **** x * * ** y;

Adder sum1; // sum1 is *** to 0

Adder * * * // sum2 is ** * * to x

Adder * * // sum1 is ** * to y

cout ******* * * is * **** ** * * * * * *** * '\n'; // prints *** * is ** *

cout * ** ** * * is *** ** ** **** * * * ** '\n'; // * ** * ** is * ** * *

cout * ** * ** ** * is ** * * ** ** ** * '\n'; // * ** ** ** * is * *

sum1 += x; * * x to sum1; now sum1 is x

sum2 += -3; // adds -3 to sum2; now sum2 is x-3

sum3 += 2; ** * 2 to sum3; now sum3 is y+2



if (sum1 == sum2)

cout ** * * * * and sum2 are the * ******* *

else cout **** * *** *** and sum2 are not the * * * *** ** *

if (sum1 == sum3)

cout * ** * * ******** and sum3 are the * * * * *

else cout * ** ** * * * and sum3 are not the ********


* * * ** * * * ** * * * 0;

}
answered by (-364 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.146
©2016-2024

Related questions

0 like 0 dislike
30 answers
[Exercise] Coding (C) - asked May 18, 2017 in C++
ID: 24769 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
15 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24854 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
12,783 questions
183,443 answers
172,219 comments
4,824 users