## Description

**Objective**

Students will gain practice using the ‘if-elseif’ and ‘switch’ statements and ‘input’ and ‘output’ functions.

**Assignments**

You have been given the following parameters for the sine wave, square wave and the wedge wave:

Amplitude (A) = 3; Frequency (f) = 20, Time Vector (t) = 0:0.001:1;

The functions to create the waves are given by:

sine_wave = A*sin(2*pi*f*t)

sq_wave = A*square(2*pi*t, 50)

wd_wave = A * sawtooth(2*pi*f*t)

- Write a script using ‘
**if-elseif**’ that will print and prompt the user to select a wave of their choice. This is an example of how it should look like: **SineWave****SquareWave****WedgeWave****Theremin**

**Please select one of the following: **

After the choice has been made, it will print and prompt the user to choose one of the following:

**Enter “a” to change the amplitude:****Enter “b” to change the frequency:****Enter “c” to change both:****Enter “d” to change amplitude of the theremin:**

After the choice has been made, it will ask the user for the value and then plot the wave.

If the user selects one of the sine, square, wedge waves and then selects ‘**d**’, it should display the following message:**Wrong Choice!.**

If the user selects ‘**4**’ and then selects ‘**a**’ or ‘**b**’ or ‘**c**’, it should display “**Wrong Choice!”****.**If the user selects ‘**d**’, it will play the theremin and then plot it.

- Solve 1,2,4,5 from Chapter 3.

**1.**

‘b’ >= ‘c’ -1 will evaluate to 1 b/c ‘b’ is equal to 98 and c-1 = 98

3 == 2+1 evaluates to 1, because it does the addition before the comparison

(3 == 2) + 1 evaluates to 1 because (3 == 2) evals to 0 and then the 1 is added on.

Xor(5<6,8>4) will evaluate to 0 because of the exclusive condition. (if both inputs are 1 the output is 0)

** **

** **

**2.**

user_input = input(‘Enter the character x: ‘,’s’);

if(user_input ~= ‘x’)

disp(‘Wrong!’);

end

function [ next_hour ] = nexthour( hour )

if(hour == 12)

next_hour = 1;

else next_hour = (hour+1);

end

disp(‘Calculate the volume of a pyramid: ‘);

l = input(‘Enter the length of the base: ‘);

lu = input(‘Enter i for inches or c for cm: ‘, ‘s’);

if(lu == ‘c’)

l = (l/2.54);

end

w = input(‘Enter the width of the base: ‘);

wu = input(‘Enter i for inches or c for cm: ‘, ‘s’);

if(wu == ‘c’)

w = (w/2.54);

end

h = input(‘Enter the height: ‘);

hu = input(‘Enter i for inches or c for cm: ‘, ‘s’);

if(hu == ‘c’)

h = (h/2.54);

end

volume = (1/3)*(l*w)*(h);

fprintf(‘\nThe volume of the pyramid is %0.3f cubic inches\n’, volume);

**5.**

letter = input(‘Enter a character: ‘, ‘s’);

if(isletter(letter))

fprintf(‘%s IS a letter of the alphabet\n’, letter);

else

fprintf(‘%s is NOT a letter of the alphabet\n’, letter);

end

** **

**Report**

Copy and paste the commands and the Matlab output (including the plots) into a word document for submitting the final report. Each student should prepare a report and submit it for grading using the blackboard course site. Also, at the end of the report, include an assessment of your contribution to the project and your partner’s contribution (in percentage).**(40 points)**

Each team will also demonstrate your program to the TA. **(10 points)**