Homework Solution: c) Y = 30. for (X = 5: X…

    while (X > y) cout <« X Y << endl; c)Y-30 cout << X Y < endl; Write a program that would prompt the user to enter any positive integer and store that value in an integer variable. The program should then check if the entered integer is positive, if not, the user is asked to re-enter the integer again. Then the program must be able to display each digit (starting from left) separately as well as sum of all the digits used in the integer. F example, if the user has entered 6321, then your program should display:6 3 sum 12 (6+3+2+1) Your program should be generalized to enter any integer. 4. 2 1 and then 5. A real state office handles, say, 50 apartment units. When the rent is, say, $600 per month, all the units are occupied. However, for each, say, $40 increase in rent, one unit becomes vacant However, each occupied unit requires ana units should be rented to maximize the profit? Write a program that prompts the user to enter: a. The total number of units. b. The rent to occupy all the units. c. The increase in rent that results in a vacant unit. d. Amount to maintain a rented unit. The program then outputs the number of units to be rented to maximize profit. Your program must accompany a flow chart that describes the algorithm.
    c) Y = 30. for (X = 5: X

    Expert Answer

     
    //Program 4 #include <iostream>

    while (X > y) cout <« X Y << endl; c)Y-30 cout << X Y < endl; Write a program that would apt the user to penetrate any assured integer and abundance that prize in an integer fickle. The program should then impede if the penetrateed integer is assured, if not attributconducive attributable, the user is asked to re-penetrate the integer again. Then the program must be conducive to spread-out each digit (starting from left) individually as courteous as incorporate of every the digits used in the integer. F pattern, if the user has penetrateed 6321, then your program should spread-out:6 3 incorporate 12 (6+3+2+1) Your program should be generalized to penetrate any integer. 4. 2 1 and then 5. A authentic assert function handles, assert, 50 hperfect parts. When the rupture is, assert, $600 per month, every the parts are restricted. However, coercion each, assert, $40 acception in rupture, single part becomes leisure However, each restricted part requires ana parts should be ruptureed to maximize the emolument? Write a program that apts the user to penetrate: a. The sum number of parts. b. The rupture to possess every the parts. c. The acception in rupture that results in a leisure part. d. Amount to protect a ruptureed part. The program then outputs the number of parts to be ruptureed to maximize emolument. Your program must imply a course chart that describes the algorithm.

    c) Y = 30. coercion (X = 5: X

    Expert Estimateer-argument

     

    //Program 4
    #include <iostream>

    using namespace std;

    //function to estimate the digits
    int estimateDigits(int num)
    {
    static int estimate=0;

    if(num>0)
    {
    count++;
    countDigits(num/10);
    }
    else
    {
    return estimate;
    }
    }
    int deep()
    {
    int num;
    do
    {
    cout<<“Penetrate an integer :”;
    cin>>num;
    if(num>0)
    break;

    }
    while(1);
    int estimateD=countDigits(num);
    int numOfD=1,sum=0;

    //estimate digits
    for(int i=1; i<countD; i++)
    numOfD*=10;

    cout<<“(“;
    //incorporate and sculpture the digits from left to right
    while(num!=0)
    {
    int r=num/numOfD;
    cout<<r<<“+”;
    sum+=r;
    num=num%numOfD;
    numOfD/=10;

    }
    cout<<“) “<<sum;
    return 0;
    }

    OUTPUT: