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
BitTorrent, a P2P protocol for file distribution, depends on a centralized resource allocation mechanism through which peers are
ch4aika [34]

Answer:

yes. it is true. mark as brainlest

8 0
2 years ago
A school principal trying to find out if parents will help buy new playground equipment shows digital leadership by.
ELEN [110]

Answer:

D. is the correct answer!

8 0
3 years ago
Read 2 more answers
A network administrator is reviewing a network design that uses a fixed configuration enterprise router that supports both LAN a
tester [92]

Answer:

a modular router

Explanation:

A modular router is a type of router that will provide multiple slots, this will enable the network engineer to either change or increase the number of space the router has.

A layer 3 switch cannot provide a WAN connectivity even though it can increase the number of ports on a router. The concept of PoE capability of any device have nothing to do with the number of ports it has. If the Engineer decides to use another fixed configuration router it will still lead to the same problem in the future because it cannot guarantee or provide the flexibility of future growth adaptation which can be given by a modular router if put in use.

8 0
3 years ago
Anyone have Minecraft dungeons I need help with it
steposvetlana [31]

Answer:

for sure add me upppp its mypplong

5 0
3 years ago
Read 2 more answers
True and false 1. Trace topology is also referred to as tree bus topology. ​
algol13

Answer:

Trace topology is also referred to as tree bus topology.

Explanation:

6 0
2 years ago
Other questions:
  • What must be done if the intended destination hardware is not supported by the chosen OS?
    6·1 answer
  • In your own words, describe what Internet Protocols are. Why is it important to have agreed upon protocols?
    6·1 answer
  • What to do when the tool bar for paint tool sai dissapears?
    12·1 answer
  • WILL DO A BRIANLY! Use an algorithm to help the Python Turtle get to the finish line in 10 steps by using only the 3 commands be
    12·1 answer
  • Greg is the network administrator for a large stadium that hosts many events throughout the course of the year. They equip usher
    7·1 answer
  • How do computer users benefit from the increased speed?
    9·1 answer
  • Question 8 (True/False Worth 3 points)
    15·1 answer
  • Describe the uses of computer in different fileds? please help me ​
    14·1 answer
  • In the following nested loop structure, which loop does the program EXIT first?
    6·1 answer
  • Group of programs are software <br>​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!