Write in Matlab A restaurant sells five different desserts w

Write in Matlab

A restaurant sells five different desserts whose prices are shown in the following table:

Write a Matlab program to display the above menu to the user. The program then prompts the customer for a key board entry of a series of pairs of numbers as follows.

Dessert Number:

Quantity sold:

The program should then use the switch statement to obtain the total price for the selected product. The program should also display the results after the computation using appropiate format statements.

Dessert Number Unit Price($)
1 2.98
2 4.5
3 9.8
4 4.5
5 3.85

Solution

MATLAB CODE

clc;clear all;
Price = [2.98 4.5 9.8 4.5 3.85];
fprintf(\'MENU\ \');
fprintf(\' _______________________________________________\ \');
fprintf(\'|\\tDeseart Number\\t|\\tUnit Price($)\\t|\ \');
fprintf(\' _______________________________________________\ \');
for i =1:length(Price);
    fprintf(\'|\\t%d\\t\\t|\\t%2.2f\\t\\t|\ \',i,Price(i));
    fprintf(\' _______________________________________________\ \');
end
ext = 1;
fprintf(\'Please enter your order. Press 0 to stop ordering! Thank you :)\ \');
while ext
    Number(ext) = input(\'Dessert Number:\');
    if(Number(ext) ==0)
        ext =0;
    else
        Quantity(ext) = input(\'Quantity sold:\');
        ext = ext+1;
    end
end
clc;
SubTotal =0;
fprintf(\'Bill\ \');
fprintf(\' ________________________________________________________\ \');
fprintf(\'| Deseart Number | Unit Price($) | Quantity sold | Total |\ \');
fprintf(\' ________________________________________________________\ \');
for i =1:length(Quantity);
    switch(Number(i))
        case 1
            p = Price(1);
            total = p*Quantity(i);
        case 2
            p = Price(2);
            total = p*Quantity(i);
        case 3
            p = Price(3);
            total = p*Quantity(i);
        case 4
            p = Price(4);
            total = p*Quantity(i);
        case 5
            p = Price(5);
            total = p*Quantity(i);
    end
    SubTotal = SubTotal+total;
    fprintf(\'|\\t%d\\t |\\t%2.2f\\t |\\t%d\\t | %3.2f |\ \',Number(i),p,Quantity(i),total);
   fprintf(\' ________________________________________________________\ \');
end
fprintf(\'| Sub Total: %5.2f\\t\\t\\t\\t\\t |\ \',SubTotal);
fprintf(\' ________________________________________________________\ \');

SAMPLE OUTPUT

MENU
_______________________________________________
|   Deseart Number   |   Unit Price($)   |
_______________________________________________
|   1       |   2.98       |
_______________________________________________
|   2       |   4.50       |
_______________________________________________
|   3       |   9.80       |
_______________________________________________
|   4       |   4.50       |
_______________________________________________
|   5       |   3.85       |
_______________________________________________
Please enter your order. Press 0 to stop ordering! Thank you :)
Dessert Number:3
Quantity sold:1
Dessert Number:2
Quantity sold:6
Dessert Number:4
Quantity sold:6
Dessert Number:5
Quantity sold:1
Dessert Number:1
Quantity sold:1
Dessert Number:0
Bill
________________________________________________________
| Deseart Number | Unit Price($) | Quantity sold | Total |
________________________________________________________
|   3   |   9.80   |   1   | 9.80 |
________________________________________________________
|   2   |   4.50   |   6   | 27.00 |
________________________________________________________
|   4   |   4.50   |   6   | 27.00 |
________________________________________________________
|   5   |   3.85   |   1   | 3.85 |
________________________________________________________
|   1   |   2.98   |   1   | 2.98 |
________________________________________________________
| Sub Total: 70.63                   |
________________________________________________________
  

Write in Matlab A restaurant sells five different desserts whose prices are shown in the following table: Write a Matlab program to display the above menu to th
Write in Matlab A restaurant sells five different desserts whose prices are shown in the following table: Write a Matlab program to display the above menu to th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site