Відповідь:
C++ code:
#include <iostream>
class Number{
private:
int number;
public:
Number();
Number(int);
Number(const Number&);
~Number() = default;
void set_number(int number){this->number = number;}
int get_number(){return this->number;}
int c_digit();
int sum_digit();
};
Number::Number(){
number = 0;
}
Number::Number(int number){
this->number = number;
Number::Number(const Number& object){
this->number = object.number;
int Number::c_digit(){
int counter = 0;
int num = this->number;
while(num){
counter++;
num /= 10;
return counter;
int Number::sum_digit(){
int sum = 0;
sum += num % 10;
return sum;
int main(){
Number obj(2578);
std::cout << "Digit: " << obj.c_digit() << std::endl;
std::cout << "Sum digit = " << obj.sum_digit() << std::endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Відповідь:
C++ code:
#include <iostream>
class Number{
private:
int number;
public:
Number();
Number(int);
Number(const Number&);
~Number() = default;
void set_number(int number){this->number = number;}
int get_number(){return this->number;}
int c_digit();
int sum_digit();
};
Number::Number(){
number = 0;
}
Number::Number(int number){
this->number = number;
}
Number::Number(const Number& object){
this->number = object.number;
}
int Number::c_digit(){
int counter = 0;
int num = this->number;
while(num){
counter++;
num /= 10;
}
return counter;
}
int Number::sum_digit(){
int sum = 0;
int num = this->number;
while(num){
sum += num % 10;
num /= 10;
}
return sum;
}
int main(){
Number obj(2578);
std::cout << "Digit: " << obj.c_digit() << std::endl;
std::cout << "Sum digit = " << obj.sum_digit() << std::endl;
return 0;
}