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
What output is produced by the following code? Integer first = new Integer(7); Integer second = first; if (first == second) Syst
fenix001 [56]

Answer:

The correct output of this question is  "Sneezy Sleepy".

Explanation:

In the given code firstly we create the object of the integer class that is first in this we pass the integer value that is 7. Then we declare another second integer variable is this variable we pass object as a reference. Then we use the two conditional statements. In the first, if block we check that the object of the class is equal to the reference variable. If it is true it prints Sneezy. otherwise, it will print Grumpy. In second if block we check that the object of the class is equal to the reference variable. but in this time we the equals() function it is the same as(==). If the condition is true it prints Sleepy. otherwise, it will print Doc. So the output of the code is Sneezy Sleepy.

6 0
3 years ago
Curtis has been testing a new software package for the past two months. However, he decides not to switch and goes back to using
hodyreva [135]
Retro-active interference
8 0
3 years ago
How can you exaggerate the height of a jump in a photograph
Nataliya [291]

If you take the photo with one person on the ground that way when they take the photo it will look like the person jumping is jumping higher then they really are.


I hope this helps

8 0
3 years ago
g Points The critical section cannot be executed by more than one process at a time. false true Save Answer Q3.28 Points The cod
Ira Lisetskai [31]

Answer: Hello your question lacks some details attached below is the missing detail

answer :

a) True , B) False  C) True  D) True

Explanation:

a) True ; The critical section cannot be executed by more than one process at a time

b) False : The code does not satisfy the progress condition, because while loops are same hence no progress

c ) True :  The code satisfies the bounded waiting condition, because of the waiting condition of the while loop

d) True : No matter how many times this program is run, it will always produce the same output, this is because of the while loop condition

7 0
3 years ago
(true or false) fortnite is the best?
GarryVolchara [31]

Answer:

FALSE ZzZzZzZz

Explanation:

Cus it is PERIOT

7 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following should you avoid when designing your Print resume?
    11·1 answer
  • Match each task with the features necessary to complete the task
    10·1 answer
  • Do you believe that oop should be phased out and we should start working on some alternative?
    13·1 answer
  • Write a pseudocode that will take marks of physics, chemistry and math as input, calculates the average and displays output.
    7·2 answers
  • What activities are the most likely to infect your computer vith a virus? Check all that apply.
    10·1 answer
  • You have to display or connect to network shares on remote computers. Which command-line utility will you use to accomplish the
    10·1 answer
  • Edhisive 3.5 code practice
    9·1 answer
  • When you expect a reader of your message to be uninterested, unwilling, displeased, or hostile, you should Group of answer choic
    15·1 answer
  • What is the best way to use copyrighted material?
    14·2 answers
  • You are creating a query for a website. The query
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!