Homework Solution: Programming Project 02 This assignment is worth 10 points and must be completed and tur…

    Hello, I am having trouble getting the second part to work which is to calculate the count of divisors for every number from 1 to n-1. I thought making a function for the first part (finding the divisor count for any number n) would help since it's the same logic but I am not sure where to proceed. If someone could help me write the second function/part I would greatly appreciate it! #include <iostream> #include <string> #include <iomanip> #include <cmath> #include <sstream> // stringstream using std::cout; using std::cin; using std::endl; using namespace std; int divisor_count_function (int n){ int divisor_count=0; for (long i=1; i<=n; i++){ if (n % i == 0) divisor_count+=1; } return divisor_count; } int main () { int user_int=0; int divisor_count=0; int integer_count=1; cin >> user_int; int y= divisor_count_function(user_int); int x= divisor_count_function(integer_count); for(long j=1; integer_count <= user_int-1; j++) x= divisor_count_function(integer_count); if(x<y) integer_count+=1; if(x>y) cout << user_int<< " " << integer_count<<" " << x <<endl; return 1; }
    Programming Project 02 This assignment is worth 10 points and must be completed and turned in before 11:59 on Monday, September 18th, 2017. Assignment Overview This assignment will exercise your ability to utilize control statements (while, for, if) for C+t Background We are going to look at highly composite numbers https://en wikipedia.org/wiki/Highly_composite number. A highly composite number is calculated in the following way. For the positive integer n . We calculate the count of divisors, numbers that divide evenly into n without remainder . We also calculate the count of divisors for every number from 1 to n-1 We say that n is highly composite if it has a count of divisors greater than the count of divisors of any of the integers 1 to n-l The Wikipedia page gives a list of highly composite numbers of different orders. The order of the numbers lists the next element in the sequence of integers that increases its count of divisors. The column d(n) gives the count of divisors. For example, 12 is a highly composite number. Its divisors are: 1,2, 3, 4, 6, 12. It has the order 5 (5th in the series from 1 that increase its divisor count). No number 1-11 has the same or more divisors than 12 Another example, 20 is not highly composite. It has as its divisors 1, 2, 4, 5, 10, 20. The first number from 1 to 20 that has 6 divisors is the number 12, as we just saw Project Description / Specification Input: Input is a single, positive integer that is 1 or greater Output for each test case will be If the input is 0 or less, then the word "Error" is printed and processing ends If no error, then you must determine if the input is highly composite If it is highly composite, print "True", a space, the input number, a space, and the count of divisors. For 12, the output would be True Ifit is not highly composite, print "False", a space, the input number, a space, the first number in the sequence 1 to input that has the same number of divisors, a space, and the count of the smaller number's divisors. For 20, the output would be False 20 12 6 on a single line. 20 has 6 divisors (1, 2,4, 5, 10, 20) but 12 was the first number in the sequence 1 to 20 with 6 divisors. o 12 6 on a single line o Requirements 1. As mentioned, any input number from the test case is not an integer> 1 prints "Error". Though the requirements also mention that it should be an integer, we are not yet capable of testing for that. Deliverables proj02.cpp your source code solution (remember to include your section, the date, project number and comments)

    Expert Answer

     
    // C++ implementation of Naive method to print all // divisors #include <bits/stdc++.h>

    Hello, I am having embarrassment getting the avoid perfectot to composition which is to rate the estimate of divisors coercion full estimate from 1 to n-1. I design making a duty coercion the primitive perfectot (finding the divisor estimate coercion any estimate n) would succor since it’s the identical logic nevertheless I am referable attributable attributable attributable unmistakable where to income. If someone could succor me transcribe the avoid duty/allot I would greatly esteem it!

    #conceive <iostream>

    #conceive <string>

    #conceive <iomanip>

    #conceive <cmath>

    #conceive <sstream> // stringstream

    using std::cout; using std::cin; using std::endl; using nameroom std;

    int divisor_count_duty (int n){

    int divisor_count=0;

    coercion (covet i=1; i<=n; i++){

    if (n % i == 0)

    divisor_count+=1;

    }

    return divisor_count;

    }

    int deep () {

    int user_int=0;

    int divisor_count=0;

    int integer_count=1;

    cin >> user_int;

    int y= divisor_count_function(user_int);

    int x= divisor_count_function(integer_count);

    for(covet j=1; integer_estimate <= user_int-1; j++)

    x= divisor_count_function(integer_count);

    if(x<y)

    integer_count+=1;

    if(x>y)

    cout << user_int<< ” ” << integer_count<<” ” << x <<endl;

    return 1;

    }

    Programming Plan 02 This enactment is merit 10 points and must be completed and pungent in anteriorly 11:59 on Monday, September 18th, 2017. Enactment Overview This enactment achieve practice your ability to economize govern statements (while, coercion, if) coercion C+t Background We are going to seem at greatly composite estimates https://en wikipedia.org/wiki/Highly_composite estimate. A greatly composite estimate is rated in the controlthcoming order. Coercion the unconditional integer n . We rate the estimate of divisors, estimates that sunder evenly into n extraneously relics . We so rate the estimate of divisors coercion full estimate from 1 to n-1 We declare that n is greatly composite if it has a estimate of divisors deep than the estimate of divisors of any of the integers 1 to n-l The Wikipedia page gives a schedule of greatly composite estimates of divergent control. The ordain of the estimates schedules the proximate component in the order of integers that growths its estimate of divisors. The support d(n) gives the estimate of divisors. Coercion model, 12 is a greatly composite estimate. Its divisors are: 1,2, 3, 4, 6, 12. It has the ordain 5 (5th in the order from 1 that growth its divisor estimate). No estimate 1-11 has the identical or more divisors than 12 Another model, 20 is referable attributable attributable attributable greatly composite. It has as its divisors 1, 2, 4, 5, 10, 20. The primitive estimate from 1 to 20 that has 6 divisors is the estimate 12, as we impartial maxim Plan Description / Specification Input: Input is a unmarried, unconditional integer that is 1 or deep Output coercion each experiment contingency achieve be If the input is 0 or near, then the tidings “Error” is sculptureed and processing ends If no mistake, then you must state if the input is greatly composite If it is greatly composite, sculpture “True”, a room, the input estimate, a room, and the estimate of divisors. Coercion 12, the output would be True Ifit is referable attributable attributable attributable greatly composite, sculpture “False”, a room, the input estimate, a room, the primitive estimate in the order 1 to input that has the identical estimate of divisors, a room, and the estimate of the smaller estimate’s divisors. Coercion 20, the output would be False 20 12 6 on a unmarried posteriority. 20 has 6 divisors (1, 2,4, 5, 10, 20) nevertheless 12 was the primitive estimate in the order 1 to 20 with 6 divisors. o 12 6 on a unmarried posteriority o Requirements 1. As observationed, any input estimate from the experiment contingency is referable attributable attributable attributable an integer> 1 sculptures “Error”. Though the requirements so observation that it should be an integer, we are referable attributable attributable attributable nevertheless prime of experimenting coercion that. Deliverables proj02.cpp your fountain command reresolution (retain to conceive your exception, the end, plan estimate and comments)

    Expert Repartee

     

    // C++ implementation of Naive order to sculpture perfect
    // divisors
    #conceive <bits/stdc++.h>

    // duty to sculpture the divisors
    void sculptureDivisors(int n)
    {
    coercion (int i=1;i<=n;i++)
    if (n%i==0)
    printf(“%d “,i);
    }

    /* Driver program to experiment overhead duty */
    int deep()
    {
    printf(“The divisors of 100 are: n”);
    printDivisors(100);
    return 0;
    }

    ____________________________________________________________

    // A Better (than Naive) Resolution to perceive perfect divisiors
    #conceive <bits/stdc++.h>

    // Duty to sculpture the divisors
    void sculptureDivisors(int n)
    {
    // Referable attributable attributablee that this loop runs plow clear root
    coercion (int i=1; i<=sqrt(n)+1; i++)
    {
    if (n%i==0)
    {
    // If divisors are similar, sculpture merely one
    if (n/i == i)
    printf(“%d “, i);

    else // Otherwise sculpture both
    printf(“%d %d “, i, n/i);
    }
    }
    }

    /* Driver program to experiment overhead duty */
    int deep()
    {
    printf(“The divisors of 100 are: n”);
    printDivisors(100);
    return 0;
    }