7 like 0 dislike

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.

[Exercise] Coding (C) - asked in Final Exam Preparation
Available when: Unlimited - Due to: Unlimited

reshown by | 81 views
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help

20 Answers

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

using namespace std;



class Adder{

public:
** *** * *** * * * * ** * sum;
** * * * * **
* ** **** * ** * * *
** *** * * *** * * * *** ****** * *** ** * = 0;
* * ** ** * * *
*** *** * * ** * * *
*** **** ** * * * *
** **** ** * * **** x){
** * * ** **** * ** * ** * ** **** * = x;
*** **** * * ** * * *
*** ** *** *** *
** * **** ******** * * * * * *
* * * * * *** ** ** ** *** );
* * **** ***** * ** *
* * **** * ** * ** * *
* * ** ***** *** *

};



int Adder:: ** ** * x){
* * * ** * ** ** * * * x;
*** *** * *** * ** ** sum;

}



bool ** ** * * * a){
** ***** * * * * ** ****** x;
* * * ** ** * * ****** * == a.sum)
** * * * * ***** * * * ** *
**** * * * ** ** * *
* ** ** ** ** * ***** *** *** *** **
* ** *** ** * * *** * x;

}



int main()

{
* ** * * ***** ** ** * * * x,y;
** *** * ** * *** * ***** * * ** x *** ** y;
* ** * * ** ** * * *** * ** sum1; // sum1 is *** **** to 0
**** * *** *** ** ** *** * sum2(x); // sum2 is * ** **** to x
* * ***** *** * * * * *** sum3(y); // sum1 is ** **** to y
** ***** * ** * * ** * * * * ** * *** * is " * ** * sum1.sum * ** ** '\n'; // prints * * is **
** **** ** *** * ** ** * * * is " ****** sum2.sum * *** *** '\n'; // prints ** * * is **
* * * *** * * ** ** **** ***** * *** is ** * *** * * sum3.sum * * ** ** * '\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 (1.4k points)
0 like 0 dislike
Hidden content!
** ** ** ** * ** * * *
**** * ***
*** * ***** * *
* ** ** std;


* Adder

{
*****
* *** ** ** * * ***** * * sum;
*** * ** **** * ** ()
** * * * * ** *
* *** *** * ** *** *** ****** ** ** **
* * **** * *
* * ** ** * ** * (int *** *


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


* ** * * * ** * ** ** * *** * * int *** * *


* * * * ** * * * **** **** ** ***** ** ** * * * * const * ** *
**** ** *** * ** **
* * *** * *** * * * * * * ** * * *** * *** * * *
**** ** *** ** * * * * ** * * * * * **** * *
* * ** * * * *** * *


*** * * ** *** ** ** ** ** **** *** * * * **
* **** * * * * * *
*** * * * * **** ***** * * * ** **** *
**** * * * * **** ****** * * *** * * ** * * * ** * * ** * 1;
* * ** * * ** *** ******* **** * **** ** ** ** *** *
** * * * * ** *** ** * * * **** *** ** ***** * * **** ** ** * * *** *** 0;
*** ** *** ** ** ** * *

};


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

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

}





void * * int * ***

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

}



int * *

{

int x,y;

cin * * * * * x * * y;
** sum1; // sum1 is * ** * to 0
* * * * // sum2 is * ** to x
* *** ** // sum1 is *** *** to y

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

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

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

sum1 += x; ** x to sum1; now sum1 is x
** += -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 == *
** **** * and sum3 are the * *

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

}
answered by (10.8k points)
0 like 0 dislike
Hidden content!
**** * ** *
* * * ** * *** * ***
* * **** ** *
** * ** * std;


* Adder

{
****
*** * *** * ** * ** * * ** * sum;
* *** *** ** ** *** ** ()
** * ** * **** * ** * **
** * ** * * * **** * * ** ****
*** ** ** ****
** ****** ** * *** ** (int * ** *


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


* * ** ** ** ** *** * * int *****


* * * * ** ** ******** ** * ** * **** ****** **** * *** * * const * * **
***** * ** ** * ** *
*** * * * * ** * * * *** * * * **** * *** * * * * ** *
** ******** * ** * * ****** *** * ** * ** * **
*** *** ** * * ****


* ** *** * **** * * ** * ** ******
* * **** * ** ** * *
** * ***** ***** * * * ** * **** *** * * *********
** * * * * ** ******** * * ** *** * ** * ** * * ** ** * 1;
* * * * ** * ** * * ** * ** *** **** ***
* * ** * * *** *** ** *** * * * ** ** * * ** ** * ** * * ** 0;
* **** **** * ** * **

};


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

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

}





void *** * int *** **

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

}



int ** *

{

int x,y;

cin *** ** x ** * **** y;
***** sum1; // sum1 is * * to 0
** * ** // sum2 is * * to x
** ** *** // sum1 is * *** * to y

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

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

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

sum1 += x; * * x to sum1; now sum1 is x
* += -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 == *
** * **** * * and sum3 are the ***** **

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

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


* * Adder

{
* **
**** ** ******** ** * * sum;
**** ** * * * * ** ** ()
** ******* * * ******
** ** *** *** **** * * ******** * ** ** ****
*** *** ** ** ** **
*** * ** ** *** *** (int *****


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


* ** ** *** * ** * **** * ** * int ****


* ** **** * ** * ** * ** ** * * ** ** ****** ***** *** * *** ***** const Adder *** ** *
* * * * * * * **
******* *** *** * * *** ** ** ****** **** ** * *
* * **** ** ** ** * ** * ***** *** * ***** * * * * **
* ** * * * * * * **


********** * ** ***** * ** ***** **
* ** *** ******* *
* ** * ******* * ** ** *** ** ** ** *
******* **** ** * * * * * * *** *** * * * ** **** * ** * ** 1;
*** ** * ** * * * * * ** * ** **
****** * *** * ** * * ** * *** *** * ** * * * ** ** *** *** 0;
****** *** ** * * *

};



void ** ** * ** ** * * *

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

}





void * * * ** * * int * ****

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

}



int **

{

int x,y;

cin * * ** ** x ** *** y;
** sum1; // sum1 is ** to 0
* // sum2 is * **** * to x
**** // sum1 is * * to y

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

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

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

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

if (sum1 == sum2)

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

if ***** == sum3)

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

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

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


** *

{
* * *
* * * ** * * * * * **
* * * * * * ****** * *
* * ** ** * ** ****** ***** * * ** * * **
** ** ****** * **
** ** ***** ***** ***** ** * ** a)
* *** * * **** * * *
** *** * *** * * ** * * * * *** * ***
*** **** ** * *** * * ** *
**** ** * * **** *** * *
* * ******** * **
** *** * * ** ** ** * **** * * *** * num;
** ** * ** * ** *
*** * ***** * * * * ** * ** a)
** ** * * * * * ** * ***
* ** * ** * ** * * * ** * ** **** *** * *** ** * **
* * * * *** * *
* *
** * **** * ** num;

};

int ***

{

int x,y;

cin *** * x ****** * y;
** * // sum1 is * * * to 0
* *** // sum2 is ** ** * to x
* * ** // sum1 is ** *** to y

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

cout ****** ***** * * is ** * *** * ** * ** * * * *** // * * ** ***** is ***** *
* ** ** ** ** * * * is * * * * * * ** ** * ** * // * *** is ****
* ** * ** ** x) ; * * * x to sum1; now sum1 is x
*** * ** * * * -3) ; // adds -3 to sum2; now sum2 is x-3
* ** * 2) ; ***** 2 to sum3; now sum3 is y+2

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

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

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

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

{
*
* * * ******* ** * var;

* ** *** * ** **** ** * *** n=0)
* * ** * ** ** * ** ** *
** * ** * ***** * * * *** * * * * ** ** *
** ******* ** *** * * *
* * * *** * * ** **** * ** * * * * * ****
* * **** *** * * ** if ** * ***** **
***** * *** *
* *** * * * * * * *** **** * ** * * * * 1;
*** * * * ** * * *
** * * ********** * ****
*** ******** * * **
**** ** ******** *** *** * *** ** **** * ** * 0;
****** ** * ** *******
*** ****** * * * ** ** *


* * * * * * * * ******** *** *** int * **
*** ** ** **** * * **
* * * *** ** * *** ** * * ** *** ** * *** * *
** ** * * * *
**** * * *** ********** *** * * *
****** ** ** * * *
*** * * *** * *** *** *** **** * *** * var;
** ****** * ********* ***

};
** * * *** ** * *** * *** *** ** me, ******* *** win)

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

}



int * *

{

int x,y;

cin * **** x * * * ** y;
sum1; // sum1 is **** to 0
** * // sum2 is ** * to x
** **** // sum1 is *** * * to y

cout * * ** *** * * * * is * ** * * *** sum1 ** * * * '\n'; // **** ** * *** is **
* * * * * *** ** is * ** **** * sum2 * * ** * * * ** // ***** is **** *
* * * * * * is ** * * *** sum3 * ***** * // * * * * * ** is *
* += x; * x to sum1; now sum1 is x
* += -3; // adds -3 to ***** now sum2 is x-3

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

if (sum1 == sum2)

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

if (sum1 == sum3)

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

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

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


* *** {
** * **
** * * ** int
** *
* * * * * ** n = 0) : * ***


* ** ** * ********** *** int * {
** * * * ** ** *** * ** * += a;
* ***** ** * }
* *** * * * int ** * ***** * ** {
***** ** ** * * ** * *** if * *** == *** * {
** ** * *** * ** * * * * *** * * 1;
*** ** *** * * * **** * }
** * ** ** * *** * ** * * {
** * * *** * * *** * *** ** ** * 0;
* *** ** * * * * }
* * **** }
**** ** **** int ** {
**** * ** * * ** **** ** ** ****
** * * * * * }
* * *** ** *

};
*** ** ** ** * ** * * ******* * * * * *** ** * * {
* **** * * * out ******* * *****

}




*

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

*** * * ** ** // *** is * * ** * to x
** * ** *** * * * // is **** to y



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

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

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

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

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

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

using * * * std;



class Adder

{
*****
* **** * * ** *** *** sum;
* * * * * * * * ** * * * s)
***** *** * * * *
** *** * ******* * * *** * ****** ** * * = s;
* ** * ** * *** * * *
* * * *** * *** ***
* * ** ** * * ** **
* *** * *** ** ** * ** ** *** ** **** = 0;
** *** * ***** ** * ** *
* ** * * * ***** *** * * operator += (const int n)
* * **** ** *** * * * * * *
**** * * * * * ** * * * * * ** * ** ** += n;
**** * * ** * **
** * **** * ** ***** * * == (const Adder ** ptr)
** * *** * * ** ****
* * ** * **** * *** * ** * * *** *** * ** *** ** * **** == * ** 1;
* * ** **** ** * **** * ** ** * *** ** * *** * return 0;
* * *** * ** * * **** *
* * *** * ** * * ostream ** * * ** * * (ostream * * * sen, const Adder * * ptr)
*** * * * ** *** ** * **
* ** ** ******* * * * * * ** ** * **** * ***** * ** ** * *
* ** * **** * **



};



int main()

{
* ** *** *** * * *** * x, y;
* * ** * ** ** ***** * * ** * x ** ***** * y;
* ** ** ** ** * ** *** sum1; // sum1 is * * to 0
*** ** * *** *** sum2(x); // sum2 is * *** to x
* * * * * * ** * * sum3(y); // 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 == ** ** ** * ** * and sum2 are the * ***
** * * ***** *** * * * * cout ** * * * ** * *** and sum2 are not the ***** * *
* *** * * ****** * * (sum1 == * * * * * * ** * and sum3 are the * *** **
* *** *** * *** **** ** * cout * * **** * * * and sum3 are not the * *


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

}
answered by (157 points)
reshown by
0 like 0 dislike
Hidden content!
***** ****** ** ***
* * ** ** std;


Adder

{
**
* **** * ***** *** * ** * ** *** *
* * ** * * ** ** ***
* **** ** * ** * * * * * ** *** ****** *
*** **** **** * * *** ** *
** * * * * ** ** *** * * *** i)
* ** ** *** ** *** ** ** *
* * * * * ***** ** * * * * * * *** * *
*** * * * * * *
** * ** * * ** * ***** * *** *
*** **** ******* * ** *** *
* ** *** *** * ***** * *** * * ** * * * ** ** * a;
** **** ** * * ** * ** *
** * ** * * * * * * * * i)
*** * * * ** *** *** *
*** ** * * * *** **** * *********** * ***** *
** ** *** ** * * *** *
** *
** * *** * * *** * * * a;

};

int * *

{

int x,y;

cin ** * * x * ** y;
** sum1; // sum1 is * to 0
*** * * *** // sum2 is ***** to x
*** * ** * // sum1 is **** ** * to y

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

cout ** * **** ** ** is ** *** ** * ** * * **** * '\n'; // * * ** * 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 * *** == * ****** *

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

if * * **** == ***** *

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

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

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

using ** std;



class Adder

{
** * * *** * ** * * *
**** *
* ** **** * ***** ** * total;
** **** * * ** * ** *** * ostream ** * ** ** * * ** * * *** *** *** ** * *** ****
** *** * ** **
* * ** ***** * *

public:
* * ******* * **** ** * * ** x)
* ** * * ** ** *
*** * ** * * * * *** *** ** ** * * ** * ** *** = x;
** ** ** ** * * ***
** ** *** * ** *****
* *** * **** ** **** **
* * *** **** **** * * ** *** ***** ** ** * ** = 0;
*** * * ******* ** *
** ** * ** * * ***
* * * * *** *** **** * operator +=(const int);
****** * * * ***** ** * operator ==(const **** * **



};



void * * *** * +=(const int y)

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

}



bool ** *** * ==(const * ** object)

{
*** * ** ** ***** ** *** *** * **
** * ** * ** * *** * * * true;
* * *** *** ** * ** * ** false;

}


*** * * ** *** * * ** * * **** ***** **** * object)

{
* * **** **** * **** * **** * ******* **** * * *
* ***** **** * * output;

}





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 *** ***
*** * *** * * * * ****
* ** * ** ** * * *** 0;

}
answered by (-359 points)
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:162.158.78.202
©2016-2018

Related questions

6 like 0 dislike
20 answers
[Exercise] Essay (Open question) - asked Jun 16, 2016 in Final Exam Preparation
Available when: Unlimited - Due to: Unlimited
| 53 views
7 like 0 dislike
22 answers
asked Jun 16, 2016 in Final Exam Preparation by thopd (11.8k points) | 87 views
7 like 0 dislike
25 answers
[Exercise] Coding (C) - asked Jun 22, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 33 views
5 like 1 dislike
24 answers
[Exercise] Coding (C) - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 34 views
8 like 1 dislike
43 answers
2,974 questions
57,433 answers
29,089 comments
938 users