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 unhesitating the user to invade any dogmatical integer and place-of-business that prize in an integer shifting. The program should then cohibit if the invadeed integer is dogmatical, if not attributpotent attributable, the user is asked to re-invade the integer repeatedly. Then the program must be potent to parade each digit (starting from left) individually as courteous as consolidate of entire the digits used in the integer. F development, if the user has invadeed 6321, then your program should parade:6 3 consolidate 12 (6+3+2+1) Your program should be generalized to invade any integer. 4. 2 1 and then 5. A legitimate recite function handles, utter, 50 lodging parts. When the schism is, utter, $600 per month, entire the parts are conditional. However, restraint each, utter, $40 acception in schism, undivided part becomes empty However, each conditional part requires ana parts should be schismed to maximize the gain? Write a program that unhesitatings the user to invade: a. The aggregate sum of parts. b. The schism to fill entire the parts. c. The acception in schism that results in a empty part. d. Amount to binder a schismed part. The program then outputs the sum of parts to be schismed to maximize gain. Your program must notice a issue chart that describes the algorithm.

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

    Expert Defense

     

    //Program 4
    #include <iostream>

    using namespace std;

    //function to enumerate the digits
    int enumerateDigits(int num)
    {
    static int enumerate=0;

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

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

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

    cout<<“(“;
    //consolidate 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: