Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

New Skills Practiced (Learning Goals) Problem solving and debugging. Use of coun

ID: 3818629 • Letter: N

Question

New Skills Practiced (Learning Goals)

Problem solving and debugging.

Use of count-controlled loop.

Nested loop.

An abundant number is an integer greater than 0 such that the sum of its proper divisors is greater than the integer. For example, 12 is abundant because 1+2+3+4+6 = 16 which is greater than 12.

A deficient number is an integer greater than 0 such that the sum of its proper divisors is less than the integer. For example, 8 is deficient because 1+2+4 = 7 which is less than 8.

A perfect number is an integer greater than 0 such that the sum of its proper divisors is equal to the integer. For example, 6 is perfect because 1+2+3 = 6.

for each of the data values, determines if the integer is abundant, deficient, perfect or neither and

displays a message that includes the integer and which of the 4 categories it falls into

if the integer is abundant, counts how many factors it has and displays a message that includes its factor count



NOTES:

Make sure you choose enough test data to ensure that your program meets all the requirements.

Sample terminal session:
[keys]$ more data4seven

17   -5    246
[keys]$ g++ ex07.cpp
[keys]$ ./a.out
Enter the number.
17

17 is deficient

[keys]$ ./a.out
Enter the number.
-15
-15 is not abundant, deficient or perfect.

[keys]$ ./a.out
Enter the number.
246

246 is abundant and has 8 factors

*USE A FOR LOOP. THIS DOES NOT USE FSTREAM OR FUNCTIONS.

Explanation / Answer

#include <iostream>
using namespace std;

int main() {
  
   int number,i,count,factorSum=0;
   count =0;
  
   cout<<" Enter the number.";
   cin>>number;
  
   //find factors and the sum of factors of number
  
   for(i=1;i<=number;i++)
   {
   if (number%i == 0 )
   {
        factorSum += i;
        count++;
   }
   }
  
   cout<<" Factors sum = "<<factorSum;
   cout<<" Number has "<<count<<" factors";
  
    // compare factorSum and number to decide whether the number is abundant,deficient or perfect
    if (number > 0 && factorSum > number)
    cout<<" "<<number<<" is abundant ";
    else
    cout<<" "<<number<<" is not abundant ";
  
    if (factorSum < number)
    cout<<"deficient ";
    else
    cout<<"not deficient ";
  
    if(factorSum == number)
    cout<<" perfect";
    else
    cout<<"not perfect";
  
  
  
   return 0;
}


Output:

Enter the number. 246

Factors sum = 504

Number has 8 factors

246 is abundant not deficient not perfect

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote