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
JUST NEED TO KNOW WHO ALL DOSE EDGINUITY
grandymaker [24]

Answer:

I don't use it but my little brother does and I help him with it.

3 0
3 years ago
Read 2 more answers
Objects both in the real world and in object-oriented programming contain ____ and methods.
larisa86 [58]

Objects both in the real world and in object-oriented programming contain <u>attributes</u> and methods.

<h3>What is an attribute?</h3>

In Computer technology, an attribute can be defined as a unique characteristic or quality which primarily describes an entity in a software program.

<h3>What is a method?</h3>

In Computer programming, a method can be defined as a block of executable code (sets of instruction) that are written and used by programmers to break down a given problem into small but manageable fragments (pieces).

This ultimately implies that, methods are typically written and used by programmers to break down any complex problem into simple and manageable fragments (pieces). Also, all modern programming languages comprises several methods that are predefined.

In this context, we can infer and logically deduce that all objects both in the real world and in object-oriented programming generally contain <u>attributes</u> and methods.

Read more on methods here: brainly.com/question/25619349

#SPJ4

6 0
2 years ago
Ben has to write a note on color concepts. Help him complete the following sentences.
k0ka [10]
<span>Ben has to write a note on color concepts. Help him complete the following sentences.
When light hits a surface, the surface absorbs some of the light and reflects the rest. The color that you see depends on which light waves the surface reflects
( reflects, absorbs, emits) the most. You perceive objects as having a specific color because of these constituent ______( rays, colors, intensities) of light.

I wasn't sure on the last one.</span>
5 0
4 years ago
Read 2 more answers
Assignment 2: Room area
Y_Kistochka [10]

Answer:

a = float(input("Enter Side A: "))

b = float(input("Enter Side B: "))

c = float(input("Enter Side C: "))

d = float(input("Enter Side D: "))

e = float(input("Enter Side E: "))

area1 = 1.0* a * b

area2 = (a - c) * (d - e -b)

area3 = 0.5 * (a - c) * e

print ("Room Area: " + str(area1 + area2 + area3))

Explanation:

happy to help ^3^

5 0
3 years ago
Free Brainliest Here. i Also Have A Quiz for Brainliest So Check That Out To
AysviL [449]

Answer:nice

veru cool

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Database management systems _____. a. include transaction-processing reports for database analysis b. are used to create, organi
    6·1 answer
  • In animation what is exaggerated to make the characters more intensely what they are​
    9·1 answer
  • A customer reports that recently several files cannot be accessed. The service technician decides to check the hard disk status
    11·1 answer
  • Which strategy would most likely improve a student's reading comprehension?
    8·2 answers
  • Which is an internet service? <br> A.) antivirus <br> B.) chat <br> C.) firewall<br> D.) router
    6·2 answers
  • 14. The term used to describe an attribute that can function like a primary key is a?​
    14·1 answer
  • What is the use of an NDP?
    13·1 answer
  • Which are the two places where auto sum button is available?​
    6·1 answer
  • Consider an online shopping portal that allows a customer to browse and purchase different products. The products are arranged u
    9·2 answers
  • A combined counting and logical looping statement may be needed in the following situations: (a). The values stored in a linked
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!