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
4 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]4 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
What is NOT powered by the PSU of your computer?
Yuliya22 [10]
Peripherals like your monitor or your printer.
3 0
3 years ago
A GPS is an example of a dedicated device true or false
Galina-37 [17]

Answer:

true

Explanation:

4 0
3 years ago
Please Help!
tatyana61 [14]

Answer:

Its B,D,E

Explanation:

Got it right on e2020

5 0
3 years ago
What is a credit limit? athe required payment to your credit card company. bthe amount of interest you are charged each month. c
Gnom [1K]
I believe the correct answer from the choices listed above is option C. A credit limit is the maximum amount you can charge each billing cycle.  <span>The </span>credit limit<span> on your credit card is the maximum balance your credit card issuer allows. Hope this answers the question.</span>
4 0
4 years ago
A software development _____________ provides a framework for designing, writing, and testing software.
Ivenika [448]
I think methodology
4 0
3 years ago
Other questions:
  • Write a C++ program that allows the user to enter double values. Display one of two messages: "The first number you entered is l
    9·1 answer
  • A ________ allows users to add, remove, or edit its content. Select one: A. blog B. podcast C. wiki D. chat
    8·1 answer
  • A(n) ____ instruction might look like a meaningless string of 0s and 1s, but it actually represents specific operations and stor
    9·1 answer
  • In 1-2 sentences, describe some keyboard shortcuts you have used during this lesson to save you time.
    13·2 answers
  • Please help!
    15·1 answer
  • Advantage of realtime processing​
    14·1 answer
  • Which ribbon tab is home to the Function library used to insert functions into worksheets?
    15·2 answers
  • Suppose a package pkg1 contains a class named MyClass and another package pkg2 contains a different class named MyClass. What ha
    13·1 answer
  • Write a recursive method that takes four inputs: a 1-D array of Strings (i.e., exams), the length of this 1-D array (i.e., n), a
    8·1 answer
  • A(n) ______is like an intranet except it shares its resources with users from a distant location. Select your answer, then click
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!