0 thích 0 k thích
1.8k đã xem

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) - đã hỏi trong C++
ID: 24588 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

đã sửa bởi | 1.8k đã xem
0 0
Called for Help
0 0
Called for Help

31 Trả lời

0 thích 0 k thích
Hidden content!
*** ** ** ***

using namespace std;



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


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

};



int main()

{

int x,y;

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

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

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

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

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

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

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

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

}
trả lời bởi (-412 điểm)
0 thích 0 k thích
Hidden content!
* * ****** ***

using namespace std;



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


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

};



int main()

{

int x,y;

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

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

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

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

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

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

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

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

}
trả lời bởi (-412 điểm)
0 thích 0 k thích
Hidden content!
#include * * * **



using namespace std;



class Adder{
** ** * * ****** * ***
* *** ** ** * * * * **
* * ***** *** * * * *
* * * * **** * ******* * **** * * * **** a)
* ** * ** * *
** ***** * * *** * *** * * ** * * *** * * * *** = ** ** ** ** + a.sum);
* *** * *** * * * *** * * * * * *this;
** * *** *** ** *** *
* * *** *** ****** * * Adder &a)
*** ** * * * * * * **
****** * *** ** *** *** ** ** *** * * * * ***** * == a.sum)
**** ** *** **** ** * * * * *** *** **** * * * * * ** ** * * 1;
* *** ** **** * ** * *** * *** * * * **** * *
* * *** * * *** ***** * ** * ** **** **** * * * * ***** * * ** 0;
* ** * *** ** ****** ** * *
** ****** * * * **** * * * * ** * **** ** * ***** * os, const Adder &a)
****** ** * ***
* * ** ***** **** * *** * * * * ** **** * ***** * **** ** ** a.sum;
***** * * ** * * * ** * ***** * **** * * * * os;
** * * **** ** **
* ** * * *
* * ** * * * * * ** sum;

};


* * *

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

}


* * * **** * a)

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

}



int main()

{
**** * ** * * * ** * * x,y;
** * * ** * ** ** * * * * x *** ** y;
** * *** * * ** * sum1; // sum1 is initialized to 0
***** *** * * * * ** *** sum2(x); // sum2 is initialized to x
* * ** * * * * * * sum3(y); // sum1 is initialized to y
* * *** ***** * * *** * ** * ** ** * is " **** **** * sum1 * * '\n'; // prints * * * **** is 0"
*** * *** * ***** * * ** * ** **** ** is " * ** * sum2 * * '\n'; // prints * * * * is x"
** *** **** * * ** * * ** ** ** is " * * sum3 ** **** * '\n'; // prints * * * * is y"
* *** * *** ** ** ****** ** * += 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 *** * **
** ** ** *** ** ** **** *
* * * ** **** * ** * ** * ** * * *** * ** ** * *** ** and sum2 are not the * * *
* *** * * ** ******** (sum1 == sum3)
* * * ** * ** * * ******* * * * * * * ** *** * * * and sum3 are the ** * ** * *
* * **** * * ** ** * ** *****
* * ***** ****** *** * ***** * **** * *** ** *** * **** ** * ** * and sum3 are not the ** ***
* * * *** *** *** * * ** 0;

}
trả lời bởi (237 điểm)
0 thích 0 k thích
Hidden content!
#include *** * **



using namespace std;



class Adder{
** * * ** **
* * ******* * ** * ** ****
* ** * *** ** ** ** ****** * *
**** ***** ** **** ** * * *** * * ****** a)
*** ****** *** * * *
* * ******** *** ** ** ** ** * **** * = * ** * ** + a.sum);
** *** ** *** * ** * * * * *** *** * ** **** * *this;
* * ** * * * ** * ****
*** * *********** *** * Adder &a)
* **** * **** * * ****
** * * * **** ** * * **** * * * * ** * * ***** == a.sum)
**** * * * *** *** * ** * * *** ** * * * **** * * ** ***** * * * * * ** * 1;
* *** * * * ** **** ***** * **** **** * * * *
*** * *** * ***** **** * * ** * * * * * ************* * * * ** *** ** * * 0;
* * * ** * * *** * * ****
**** ** ** * ** ** ** * * * * * ** ** ** *** ** * **** os, const Adder &a)
* * ** * ** * ** * *****
** * *** * * ** * *** * * ** ******* * * * a.sum;
* * * * * ***** * ********* * * ****** ** os;
* ** * *
*** * * **** **
*** * * ***** ********* sum;

};


* ******

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

}


******* a)

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

}



int main()

{
*** ***** ** * ***** * x,y;
* * ** ***** * * * ** * ** x ** ** * y;
* ** ** * ** * **** * * sum1; // sum1 is initialized to 0
* ** *** * * * ** * * *** * sum2(x); // sum2 is initialized to x
* * *** * * * * * **** sum3(y); // sum1 is initialized to y
* * * * * ** *** *** * * ** *** * ** is " *** sum1 * * *** '\n'; // prints ** ** is 0"
* * ** *** * ** *** * ** **** ** is " ** ** sum2 ** ** ** '\n'; // prints *** **** is x"
* * **** * * * * ** * ** *** * **** ** **** * is " ** sum3 * *** * *** '\n'; // prints * *** is y"
** **** * * *** ** * * += 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 ** ***
** * *** *** * *** * * *
***** *** * **** ** ******* * * ** ** * * ** *** ****** * *** and sum2 are not the * * * *
*** ** **** * * *** ** * * (sum1 == sum3)
* ** * ** * * **** ********** * ** ** * ** *** * *** and sum3 are the ** ** * *
***** * * ** * **** **** * *
* * ***** **** * ** **** ** *** * * ** * * ** * * * ** **** and sum3 are not the *** * ***
** * ** * * ** * * 0;

}
trả lời bởi (126 điểm)
0 thích 0 k thích
Hidden content!
#include * * * ** ** *



using namespace std;



class Adder{
*** *** *
* ** ** * * **** * ** * ****
* * * * * * ** *** * *** ***
*** *** ** * ******** * ** ** * * * *** * a)
* * ****** * * *
** *** * ** * ** * ** * * ** * * * ** = ****** * * + a.sum);
* ** ** ** ** ** *** * * ** ** ** *** *this;
** **** ** * ***** *
* *** * * **** * ** * * * * Adder &a)
** *** ** *********
* *** * * * ** *** * * * * * ** * *** **** * *** * * * * * * ***** == a.sum)
* ** **** * * * * **** ** * ** *** ** * ** * * **** ****** ** * ** 1;
* * * * * ** * ** * * ** * * ** * * ** * *
******** * * ** * *** * * ** * ****** * *** **** 0;
* * ** ****** * * **
** * *** * * * * * * ** * * * ** *** * ** * ** ** os, const Adder &a)
* ** * ** ******
* * * ** *** ** *** **** * ** *** *** a.sum;
* ** * **** * ** * * * * ** * ** ** *** os;
*** * * ** * ** ***
*** *** * * *
* ******* * ** * ** sum;

};


* * *

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

}


** **** a)

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

}



int main()

{
*** ** ** * *** * * * * * x,y;
* * * ** * * * * ** ** ** *** x * * ** * y;
* * * * *** *** * * ** sum1; // sum1 is initialized to 0
*** **** * **** ****** sum2(x); // sum2 is initialized to x
** *** **** * * ** ********** sum3(y); // sum1 is initialized to y
** ** ** **** * **** * * ******* * * ** * is " **** ** sum1 * * * '\n'; // prints * is 0"
**** ** * **** * * * * *** ** ** ** ** is " ** * ** sum2 ****** * '\n'; // prints * * * is x"
******* ** *** * *** ** *** * **** * * * * is " ** ** * sum3 * * * * * '\n'; // prints ** is y"
**** **** ** **** *** += 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 * * * ***
** ***** *** * * *** *
* **** **** ** * *** *** * **** ** * * * ** * * * * and sum2 are not the * * *** **
** * * ******** *** *** (sum1 == sum3)
* * * * * * ********** **** ***** * * * **** *** * ** and sum3 are the ** * * **
** **** * ** **** * **
** * * * ** * ** ** **** * * * * *** ** * * ** ** ****** * * and sum3 are not the *** * *
* ** * * * * * * * ** *** 0;

}
trả lời bởi (-298 điểm)
0 thích 0 k thích
Hidden content!
#include ** *** *********



using namespace std;



class Adder{
***** ****** ** **
** * * *** * * * ****
** * * ***** ** * *** * * ***** **
* *** ****** ** * ** ** *** * *** * * ** a)
* ** * * * ** * **
* ***** * ** * *** ** *** * * **** ** *** * ** *** = **** * + a.sum);
****** * *** ********** *** **** ** *** ** ** * * *this;
* **** ****** * * ** * * **
* ** ** ** ** * * * * *** * * Adder &a)
* * *** ** * ****** * *
** * * * ** * ******** * * * * *** * ** *** ** * * == a.sum)
** * ** ** ** ** * ** ** *** * * *** *** **** ** * ** ** **** * ** 1;
* **** ******* * *** * * ** ** * * *
* ** **** ** * * *** ** * ******** ** * ** * ** * * ** * * * * ** *** 0;
** ****** * * * ** *** ** * *
**** * **** ** * ** * * * * * ** * *** os, const Adder &a)
* * * * * * **
*** * * *** * * * ** * * ** * ** * * ** * * * * *** ** a.sum;
* * **** ** ***** ** * * * * ** ** *** ** * * os;
* * * ** * * ** * ** *
*** * ** ** ***
* * * * * * * ** * * sum;

};


***

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

}


* * *** * a)

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

}



int main()

{
**** *** * * * ** * * x,y;
* **** * ** * ** ** * *** * *** **** * x * *** * y;
* * ***** * * * *** * * sum1; // sum1 is initialized to 0
******* * ** ** **** * * ** sum2(x); // sum2 is initialized to x
* ** ** ***** * * * * sum3(y); // sum1 is initialized to y
* * * ***** ***** ** * * **** * * ** *** is " *** * * sum1 ** ** * '\n'; // prints * * * is 0"
** * * **** *** * * * * * *** is " ** * ** sum2 * ** ** ** '\n'; // prints ** * * is x"
* * * * ** **** *** ** * ** * ** *** * is " * **** *** sum3 * ** * '\n'; // prints ** ** * is y"
**** ** *** * ** ** * * += 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 *** ***** **
* * * * * ***** **
*** ** ***** ** * * *** ** * * * ** * * * ** *** ** and sum2 are not the *** *** *
*** ** ** * *** ** * (sum1 == sum3)
***** * * * * * ** * *** * * ****** * * * * ** * * * * * ** *** and sum3 are the * ** *
** * *** * *
* * * * * * * **** * ** * ** * * *** ** * ** and sum3 are not the * *** *
* * * ** * ** *** * * **** 0;

}
trả lời bởi (-215 điểm)
0 thích 0 k thích
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 initialized to 0

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

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

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

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

}
trả lời bởi (126 điểm)
0 thích 0 k thích
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 initialized to 0

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

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

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

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

}
trả lời bởi (237 điểm)
0 thích 0 k thích
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 initialized to 0

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

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

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

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

}
trả lời bởi (-215 điểm)
0 thích 0 k thích
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 *

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

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

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


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

}
trả lời bởi (-298 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.100.103
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
30 trả lời
[Exercise] Coding (C) - đã hỏi ngày 18 tháng 5 năm 2017 trong C++
ID: 24769 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.8k đã xem
0 thích 0 k thích
17 trả lời
[Exercise] Coding (C) - đã hỏi ngày 1 tháng 6 năm 2017 trong C++
ID: 24855 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.2k đã xem
0 thích 0 k thích
15 trả lời
[Exercise] Coding (C) - đã hỏi ngày 1 tháng 6 năm 2017 trong C++
ID: 24854 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.2k đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên