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
The web lab consists of which elements. Select all that apply. Group of answer choices Files Inspector Tool Preview Hints Work S
djverab [1.8K]

Answer:

Inspector Tool

Preview

Work Space

Instructions

Explanation:

Web Lab is a function that incorporates HTML in web development. It has functions such as Workspace where the developer writes the body of the website. Preview helps the developer take a look at the final product of what he is creating. Instructions panel provides a list of the different types of html packages that the developer can chose from.

All of these options help the developer produce a website that is up to standard.

8 0
2 years ago
Shannon has been a member of her schools newpaper club for 2 years and attends writing workshops in her free time. Which career
kkurt [141]

D) Web content developer

Explanation:

A content developer writes a well-researched content for websites, publications, and television. They also write sales copy and other marketing material for online and offline marketing. They develop text, graphics, audios, and videos.  

Skills that help web content developer:

  1. Reading news every day  
  2. Write regularly
  3. Study end audience
  4. Develop original and unique content
  5. Research; reading other people's content as well
  6. Provide solutions through your content

Besides these, a web content writer must possess technical skills like front-end web development. They must know basic HTML formatting and search engine optimization.  

7 0
3 years ago
To rearrange the data on your hard disk so your computer can run more efficiently, you use ____.
Ratling [72]
A disk optimization program, but they're probably looking for defragmenting program.
5 0
3 years ago
What career opportunities are available within the floral industry?
Vsevolod [243]

Answer: The floral industry has quite an array of possible occupation pathways. You can do flower production, design, publishing, marketing, home design, engineering, retailing, commercial, research, and lots more.

6 0
2 years ago
Question # 5
Mazyrski [523]

for num in range(4):

   print(num)

The output will be:

0

1

2

3

The for loop iterates through the numbers in the range function and prints those same numbers to the console.

6 0
2 years ago
Read 2 more answers
Other questions:
  • Marisol manages the online advertising campaigns for a chain of toy stores with both a physical and an online presence. Which Go
    7·1 answer
  • Write a function getPigLatin(pigStr) that accepts pigStr as a parameter (a sentence as input) and converts each word to "Pig Lat
    8·1 answer
  • Maia notices that her paragraphs are too close to one another. She wants to increase the space. Which arrangement of steps does
    6·2 answers
  • 7. Which innovation in video games do you think has been most significant? Include at least one way that innovation affects the
    6·1 answer
  • Dwight <br> d. eisenhower was impressed with germany's network of highways and how it __________.
    15·1 answer
  • If you decide to get married, a trade-off would be that you have to give up being single.
    12·2 answers
  • Taking away iPad privileges when a student hits another child would be considered a(an) ________ principle for decreasing or ext
    10·1 answer
  • Where is the thesis statement usually located in research paper?
    6·1 answer
  • Which type of financial institution typically has membership requirements?
    14·1 answer
  • When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustm
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!