1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pogonyaev
3 years ago
10

A method countDigits(int num) of class Digits returns the remainder when the input argument num(num > 0) is divided by the nu

mber of digits in num. The function compiles successfully but fails to return the desired result due to logical errors. Your task is to debug the program to pass all the test cases.
Computers and Technology
1 answer:
sertanlavr [38]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

class Digits

{

   public:

   int num;

   int read()       //method to read num from user

   {

       cout<<"Enter number(>0)\n";

       cin>>num;

       return num;

   }

   int digit_count(int num)  //method to count number of digits of num

   {

       int count=0;

       while(num>0)    //loop till num>0

       {

           num/=10;

           count++;   //counter which counts number of digits

       }

       return count;

   }

   int countDigits(int num)   //method to return remainder

   {

       int c=digit_count(num); //calls method inside method

       return num%c;  

   }

};

int main()

{

   Digits d;    //object of class Digits is created

   int number=d.read();   //num is read from user

   cout<<"\nRemainder is : "<<d.countDigits(number);  //used to find remainder

   return 0;

}

Output :

Enter number(>0)

343

Remainder is : 1

Explanation:

As program is missing to find errors , a logically write program is written to find the remainder when a number is divided by its number of digits. A class  Digits is constructed which has public variable num and methods read(), digit_count(), countDigits().

  • read() - This method reads value of num from the user and return num.
  • digit_count() - This method takes a integer as parameter and counts the number of digits of a number passed as argument. while loop is used to increement the counter until num<0. This returns the value of count.
  • countDigits() - This method takes a integer as a parameter and returns remainder when the argument is divided by number of  digits of argument. Number of digits is calculated by using method digit_count().

At last in main method , object of Digits class is created and its methods are used to find the output.

You might be interested in
Giving 5 stars, a Thanks, 80 points, and Branliest to whoever answers them correctly.
Mrac [35]

Answer:

Explanation:

The answer is ludonarrative.

Please mark me brainliest.

4 0
2 years ago
Who is affected by electronuc theft of a song ?
Sonbull [250]
I would have to say the artist.
simply because the artist or publisher does not receive any income on their product. 
7 0
3 years ago
Read 2 more answers
Why is it important for people to express resentments in the workplace?
svp [43]

C. Unexpressed resentments can build and hamper work

5 0
3 years ago
What is company NDR?​
lina2011 [118]

Answer:

Explanation:

NDR is a multinational American based company with international branches in Thailand, Cambodia, and Myanmar in the telecom industry and media with sales of over US$100 Million. The company develops application store (APP Store) and application (APP) for mobile devices with 700,000+ apps in the app store.

7 0
3 years ago
Which of these might be an example of an advertisers target group
Eduardwww [97]
Where are the examples?

3 0
3 years ago
Other questions:
  • A technician is troubleshooting a computer that will not communicate with any hosts on the local network. While performing a vis
    9·1 answer
  • 3. You are a network administrator responsible for all network platforms and services. The Teta Company currently has only one b
    13·2 answers
  • Why did artists use pinhole cameras during the renaissance?
    8·1 answer
  • Write a Program in C language using arrays:
    14·1 answer
  • In your opinion is it more beneficial to have many folders or is it better to nest subfolders
    12·1 answer
  • A bluetooth network consists of _____ primary device(s) and up to ____ secondary devices.
    8·1 answer
  • Where does change management play a major role in transforming a client
    11·1 answer
  • What accesses organizational databases that track similar issues or questions and automatically generate the details to the repr
    14·1 answer
  • Why did Elena Gilbert Turn her humanity off when she was sired to Damon? (In The Vampire Diaries)
    14·1 answer
  • You are a developer for a news, entertainment, lifestyle, and fashion website. User traffic has steadily increased month-over-mo
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!