Homework Solution: What will the program display when the ID is the number 11?…

    What will the program display when the ID is the number 11? 2. How can you write the multiple-alternative selection structure using the longer form of the if statement? 3. How can you write the multiple-alternative selection structure using the shorter form of the if statement? 4. How can you write the multiple-alternative selection structure using the switch statement? 5. What changes would you need to make to the code from Question 4 so that each case clause displays the appropriate price and the default clause displays the invalid id “Invalid ID” messagstart enter ID ID 2,9 5, 7, 11 Other price = 50.55 | | price = 12.35 | | price = 11.46 | | price- l ! =-1 price isT display price display Invalid stop
    start enter ID ID 2,9 5, 7, 11 Other price = 50.55 | | price = 12.35 | | price = 11.46 | | price- l ! =-1 price isT display price display Invalid stop

    Expert Answer

     
    Dear Student, here i have written the C program to demonstrate you the if structure in long form, short.And using switch keyword. Note: Please note that the below program has been tested on ubuntu 16.04 system and compiled

    What procure the program ostentation when the ID is the number 11?

    2. How can you transcribe the multiple-alternative excerption edifice using the hankerer conceive of the if proposition?

    3. How can you transcribe the multiple-alternative excerption edifice using the lackinger conceive of the if proposition?

    4. How can you transcribe the multiple-alternative excerption edifice using the switch proposition?

    5. What changes would you demand to establish to the jurisprudence from Question 4 so that each condition chapter ostentations the embezzle cost and the lapse chapter ostentations the feeble id “Feeble ID” messagstart invade ID ID 2,9 5, 7, 11 Other cost = 50.55 | | cost = 12.35 | | cost = 11.46 | | cost- l ! =-1 cost isT ostentation cost ostentation Feeble stop

    start invade ID ID 2,9 5, 7, 11 Other cost = 50.55 | | cost = 12.35 | | cost = 11.46 | | cost- l ! =-1 cost isT ostentation cost ostentation Feeble stop

    Expert Counter-argument

     

    Dear Student,

    here i feel written the C program to prove you the if edifice in hanker conceive, lacking.And using switch keyword.

    Note: Please music that the inferior program has been tested on ubuntu 16.04 order and compiled inferior gcc compiler. This jurisprudence procure to-boot employment on other IDE’s and C++ microsoft visual studio specific.

    ——————————————————————————————————————————————

    Program: 2: How can you transcribe the multiple-alternative excerption edifice using the hankerer conceive of the if proposition?

    ——————————————————————————————————————————————

    //Hedaer finish declration

    #include<stdio.h>

    //start of deep function

    int deep()

    {

    float cost;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    cost = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 )

    {

    cost = 12.35;

    }

    if(ID == 9)

    {

    cost = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 )

    {

    cost = 11.46;

    }

    if(ID == 7 )

    {

    cost = 11.46;

    }

    if(ID == 11 )

    {

    cost = 11.46;

    }

    //else

    else

    {

    cost = -1;

    }

    //if cost == -1

    if(price)

    {

    printf(“Cost is %lfn”, cost);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    ——————————————————————————————————————————————-

    Output:

    //Hedaer finish declration

    #include<stdio.h>

    //start of deep function

    int deep()

    {

    float cost;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    cost = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 )

    {

    cost = 12.35;

    }

    if(ID == 9)

    {

    cost = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 )

    {

    cost = 11.46;

    }

    if(ID == 7 )

    {

    cost = 11.46;

    }

    if(ID == 11 )

    {

    cost = 11.46;

    }

    //if cost == -1

    if(price)

    {

    printf(“Cost is %lfn”, cost);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    ——————————————————————————————————————————————

    ——————————————————————————————————————————————

    Program: 3: How can you transcribe the multiple-alternative excerption edifice using the lackinger conceive of the if proposition?

    ————————————————————————————————————————————-

    //Hedaer finish declration

    #include<stdio.h>

    //start of deep function

    int deep()

    {

    float cost;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //if ID is 1

    if(ID == 1)

    {

    cost = 50.55;

    }

    //if ID is either 2 or 9

    if(ID == 2 | ID == 9)

    {

    cost = 12.35;

    }

    //if ID is either 5, 7 or 11

    if(ID == 5 | ID == 7 | ID == 11)

    {

    cost = 11.46;

    }

    //else

    else

    {

    cost = -1;

    }

    //if cost == -1

    if(price)

    {

    printf(“Cost is %lfn”, cost);

    }

    else

    {

    printf(“Feeble IDn”);

    }

    return 0;

    }

    —————————————————————————————————————————————–

    here is the pattern speed of the program:

    Output: 2

    ——————————————————————————————————————————————-

    Program: 3: How can you transcribe the multiple-alternative excerption edifice using the switch proposition?

    ——————————————————————————————————————————————

    //Hedaer finish declration

    #include<stdio.h>

    //start of deep function

    int deep()

    {

    float cost;

    int ID;

    printf(“Invade Id: “);

    scanf(“%d”, &ID);

    //switch to condition as per the input

    switch(ID)

    {

    condition 1:

    cost = 50.55;

    printf(“Cost is: %lfn”, cost);

    break;

    //if ID is either 2 or 9

    condition 2:
    condition 9:

    cost = 12.35;

    printf(“Cost is: %lfn”, cost);

    break;

    //if ID is either 5, 7 or 11

    condition 5:
    condition 7:
    condition 11:

    cost = 11.46;

    printf(“Cost is: %lfn”, cost);

    break;

    condition -1:

    printf(“Feeble ID.n”);

    break;

    }

    return 0;

    }

    ——————————————————————————————————————————————

    here is the pattern speed of the program:

    Output: 3

    ——————————————————————————————————————————————–

    Counter-argument : 5

    What changes would you demand to establish to the jurisprudence from Question 4 so that each condition chapter ostentations the embezzle cost and the lapse chapter ostentations the feeble id “Feeble ID” message

    Just infer this proposition in the ultimate lapse condition:

    change these lines

    condition -1:

    printf(“Feeble ID.n”);

    break;

    to

    default:

    printf(“Feeble ID.n”);

    break;

    —————————————————————————————-