Answer to Question #326314 in C++ for vinni

Question #326314

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


1
Expert's answer
2022-04-09T17:52:51-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS