param is a course instructor of c++ programming and currently he is teaching conservations to his students.He started with the basic programs and now he want to introduce some complex problems,he want to start with high difficulty level problem ,such as:counting the digits of a number help Mr .param to write a program which will accept one integer argument and returns count of digits of that argument using class to basic conversion
#include<iostream>
using namespace std;
class Conversion
{
int number;
public:
Conversion(int _number = 0):number(_number){}
void Assign()
{
cout << "Please, enter a number: ";
cin >> number;
}
int CoutDigits()
{
int n = 0;
while (number > 0)
{
number = number / 10;
n++;
}
return n;
}
};
int main()
{
Conversion c;
c.Assign();
cout << "The number of dogits is " << c.CoutDigits();
}
Comments
Leave a comment