Question

MATLAB HW 11 problem using Switch Case and Input commands Write a script file that calculates...

MATLAB HW 11 problem using Switch Case and Input commands

Write a script file that calculates the cost of a movie tickets according to the following price schedule:

                                                 Number of Tickets being purchased

Time of Movie

< =5 tickets

6 to 9 tickets

>=10 tickets

Afternoon

$6

$30 + $5 for the number of tickets above 5

$50 + $4 for the number of tickets above 9

Weeknight

$7

$35 + $6 for the number of tickets above 5

$59 + $5 for each ticket above 9

Weekend

$9

$45 + $8 for the number of tickets above 5

$77 + $7 for every ticket above 9

1) The program MUST use Switch Case and Input commands for full credit.

2) The program must ask the user to input if the movie is Afternoon, Weeknight or Weekend. It should contain a safeguard that tells the operator if they have not correctly identified the time of the movie.

3) The program must ask the operator the number of tickets to purchase.

4)   The program must make the operator’s response lower case. For example if Time={‘AFTERNOON’} your program should contain something like

Time2=lower(Time) which converts the ‘AFTERNOON’ string to ‘afternoon’ to use in switch case so that no errors in capital letters vs. lower case letters can be made.

5) Show the cost of the movie tickets, the number purchased and for what time using an fprintf statement.

6) Test your program to see if it runs. Be prepared to demonstrate to the instructor how the program operates if requested by the instructor.

7) Submit a copy of the script file cut and pasted into Microsoft Word. Submit the assignment over Blackboard. (Remember that the Publish option under MATLAB is not compatible with input commands. )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The MATLAB Code is as follows:

clc
clear all

time=input("Enter the time of the movie (Afternoon, Weeknight, Weekend): ",'s'); %Read the time for movie
time2=lower(time); %convert the time to lowercase
while ~(strcmp(time2,'afternoon') || strcmp(time2,'weeknight') || strcmp(time2,'weekend'))
%if the time enetered is neither afternoon, weeknight nor weekend, then
%print error message and read the input again until valid input is entered
    fprintf("Invalid Input\n");
    time=input("Enter the time of the movie (Afternoon, Weeknight, Weekend): ",'s');
    time2=lower(time);
end
tickets=input("Enter the number of tickets to be purchased: "); %read the no.of tickets
switch time2 % use switch case on timeX of the movie
    case 'afternoon' % case afternoon
        if tickets<=5 % if no.of tickets is less than ir equal to 5, then amount is $6
            amount=6;
        elseif tickets>=10 % if no.of tickets is greater than or equal to 10, then amount is $50+$4 for no.of tickets more than 9
            amount=50;%initial amount
            inc=tickets-9; % No.of tickets more than 9
            amount=amount+inc*4; % final amount=main amount + additional amount
        else % if both conditions are not satisfied, then No.of tickets will be in the range of 6-9
            amount=30; %initial amount
            inc=tickets-5; % No.of tickets more than 5
            amount=amount+inc*5; % final amount=main amount + additional amount
        end
    case 'weeknight' % case afternoon
        if tickets<=5 % if no.of tickets is less than ir equal to 5, then amount is $7
            amount=7;
        elseif tickets>=10 % if no.of tickets is greater than or equal to 10, then amount is $59+$5 for no.of tickets more than 9
            amount=59; %initial amount
            inc=tickets-9; % No.of tickets more than 9
            amount=amount+inc*5;% final amount=main amount + additional amount
        else
            amount=35; %initial amount
            inc=tickets-5;% No.of tickets more than 5
            amount=amount+inc*6; % final amount=main amount + additional amount
        end
    case 'weekend' % case afternoon
        if tickets<=5 % if no.of tickets is less than ir equal to 5, then amount is $9
            amount=9;
        elseif tickets>=10 % if no.of tickets is greater than or equal to 10, then amount is $77+$7 for no.of tickets more than 9
            amount=77; %initial amount
            inc=tickets-9; % No.of tickets more than 9
            amount=amount+inc*7; % final amount=main amount + additional amount
        else
            amount=45; %initial amount
            inc=tickets-5; % No.of tickets more than 5
            amount=amount+inc*8; % final amount=main amount + additional amount
        end  
end
fprintf('\n******** BILLING DETAILS ********\n');
fprintf('The time of the show: %s\n', upper(time2));
fprintf('Number of tickets purchased: %d\n', tickets);
fprintf('The total amount of tickets: $%d\n', amount);

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
MATLAB HW 11 problem using Switch Case and Input commands Write a script file that calculates...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please use c++ please write down the input file information please add comments for some codes...

    please use c++ please write down the input file information please add comments for some codes please do not use #include <bits/stdc++.h> we did not learn it yet thank you CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....

  • In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use...

    In Matlab Create a single script (.m file) to solve these problems. Unless directed otherwise, use meaningful variable names for each variable; do not use the default variable ans to store your results. For this project, suppress your output with semi-colons (;). Each problem should be in a separate cell, using the cell mode feature of MATLAB. Problem 4 Video games are rather complicated to program, not least of which because of the graphics work that needs to be completed...

  • All commands must be in the command line. The expense data file is separate. Programming Project...

    All commands must be in the command line. The expense data file is separate. Programming Project #2: Manage Spending Using Commands Objectives: • Understand how to create and manipulate list of objects using array or vector class • Handle input errors and invalid values • Design and create a well-structure program using C++ basic programming constructs and classes. Description: Each “expense” contains 2 values: the spending amount (double) and its description (string) Here is an example of the “expense” data...

  • In MATLAB write a program that given the parameters from problem 13.171 (pg 900) that calculates...

    In MATLAB write a program that given the parameters from problem 13.171 (pg 900) that calculates the horizontal and vertical position of the ball after it strikes point A and until it lands at point B. Use a time increment in seconds that results in a smooth curve. Fully document your script file including a problem description and fully label your graph. from vector mechanics for engineers eleventh edition (Beer, Johnston...) chapter 13 problem number 171 8:24 PM Vector Mechanics...

  • I need help solving these questions,please don’t know how to solve it by using matlab.!

    i need help solving these questions,please don’t know how to solve it by using matlab.! Solve the following questions Ol: You are required to develop a script to calculate the volume of a pyramid, which is 1/3 *base *height, where the base is length *width. Prompt the user to enter values for the length, width, and height, and then calculate the volume of the pyramid. When the user enters each value, he or she will then also be prompted to...

  • Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...

    Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules: All units up to...

  • Using C not C++, Write a program that can be used by a small theater to...

    Using C not C++, Write a program that can be used by a small theater to sell tickets for performances. The theater’s auditorium has 15 rows of seats, with 30 seats in each row. The program should display a screen that shows which seats are available and which are taken. For example, the following screen shows a chart depicting each seat in the theater. Seats that are taken are represented by an * symbol, and seats that are available are...

  • C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file....

    C PROGRAM, A FOPEN FILE NEED TO BE CREATED Objective To review reading from a file. To use records (an instance of a struct) To use Dynamic Memory Allocation To create and use a dynamically allocated array of structs To use enumerated types in a useful manner (more info given on Discussion board!) The Problem Bad economic times has forced the UCF administration to think outside the box for alternative methods of income. Specifically, we now have a UCF lottery,...

  • Please help me correct my MATLAB script code for this problem, thank you!! A projectile PA is launched from point A towards the east with an initial launch velocity voa and an initial...

    Please help me correct my MATLAB script code for this problem, thank you!! A projectile PA is launched from point A towards the east with an initial launch velocity voa and an initial lauw angle of 0x. The impact point of the projectile Pa is a point B in a valley with an ordinate, yon, located below the clevation of point A. The launch from point A is instantaneously detected at point B, and a counter projectile P launched simultaneously...

  • Write in Java Movie Theater Ticket App Write a program that allows a user to purchase...

    Write in Java Movie Theater Ticket App Write a program that allows a user to purchase movie tickets for a showing of one of three movies. Your program will work with two files - a Movie.java and Theater.java file - which will interact with each other. You should begin by creating three Movie objects which will store information about three movies of your choice Once the information has been stored, the program should welcome the user and ask the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT