Matlab Tutorials | Examples
Practice 2:
A cell phone company offers three different price packages to its clients. In all of the
packages there is a fixed monthly fee; in addition, telephone calls are priced
according to per minute calling rate of that package. Package prices are as follows:
order of Package A, Package B, Package C
Monthly fixed rate 1.50 TL, 5.00 TL, 10.00 TL
Same operator calls 0.35 TL/min, 0.35 TL/min, 0.10 TL/min
Land line calls 0.40 TL/min, 0.35 TL/min, 0.20 TL/min
Other operator calls 0.60 TL/min, 0.35 TL/min, 0.30 TL/min
Write a MATLAB program that will do the following:
- Get the package type (“A”, “a”, “B”, “b”, “C”, or “c”).
- Readthenumberofminutestheclienthascalledsameoperatornumbers,land line numbers, and other operator numbers.
- If any of the durations is negative, display a warning and stop.
- Calculate and display the client’s bills
Solution:
Bellow code shows the how to pick best phone sector with given using inputs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
%% Start to giving inputs from user package = input('Select package ','s'); %% String input same = input('Calls towards same operator numbers (minutes): '); %Integer inputs land = input('Calls towards land line numbers (minutes): '); other = input('Calls towards other operator numbers (minutes): '); if same>=0 && land>=0 && other>=0 %% Checking the given inputs are positive or negative if it positive go to inside switch package(1) % switch expression case {'A','a'} %Case expressions two type bill = 1.50 + same*0.35 + land * 0.40 + other * 0.60; % Calculate the bills in expression fprintf('Your bill is %f TL.\n',bill) % print the bills using &g with fprintf case {'B','b'} bill = 5 + same*0.35 + land * 0.35 + other * 0.35; fprintf('Your bill is %f TL.\n',bill) case {'C','c'} bill = 10 + same*0.10 + land * 0.20 + other * 0.30; fprintf('Your bill is %f TL.\n',bill) otherwise disp ('Invalid package. It must be one of A,B,C'); %If package is not A B C a b c end else % Else statement for the negative numbers disp ('All durations must be zero or positive!'); %Display error message end |