EGR 103/Fall 2017/Lab 4

From PrattWiki
Jump to navigation Jump to search

Errors / Additions

Template Typo

The first version of the template listed Chapra 2.27 as Chapra 2.22. That has been fixed.

Help files missing before 9:30AM Tuesday

During lab 1, I found that the tester files didn't have their help files with them. I sent an e-mail correcting that, but just in case, here are the help files for the three tester files:

function BuildTester(p)
% BuildTester(p)
% If no p or p=0, only print grade
% If p=1, show only incorrect cards
% If p=2, show all cards
%
% Prints card number, what your code thinks it is,
% What it really is, and if you were correct
% Example printouts:
% Card number 42: Yours: 3C True: 3C Correct!
% Card number 43: Yours: 5C True: 4C Incorrect!
% The code correctly made card 42 the three of clubs but
% incorrectly made card 43 the 5 of clubs
%
% Your grade is saved to BTDiary.txt
function InfoTester(p)
% InfoTester(p)
% If no p or p=0, only print grade
% If p=1, show only incorrect entries
% If p=2, show all cards
%
% Prints card string, what your code thinks the value and suit are,
% What they really is, and if you were correct
% Example printouts:
% Card: KS Your Val,Suit: 13,1 True Val,Suit: 13,1 Correct!
% Card: AH Your Val,Suit:  1,3 True Val,Suit:  1,2 Incorrect!
% The code correctly gets the value and suit for the
% king (13) of spades (1) but is not right for the
% ace (1) of hearts (2)
% Your grade is saved to ITDiary.txt
function TOKTester(p)
% TOKTester(p)
% If no p or p=0, only print grade
% If p=1, show only incorrect entries
% If p=2, show only three of a kind
% If p=3, show all hands
%
% Prints hand, what your code thinks about it, and if that is correct
% Example printout:
% Hand: QD QC KC yes: Incorrect!
% If your code thinks QD QC KC is a three of a kind, that is incorrect
%
% Your grade is saved to TTDiary.txt

Additions

4.1 Introduction

The main purpose of this lab is to learn how to write functions and to use selective structures. The following is a companion piece to the lab handout itself. The sections in this guide will match those in the handout.

4.2 Resources

See main EGR 103 page for links to these

4.3 Getting Started

Same as it ever was.

4.4 Ungraded

These problems are good ones to look at and to solve but are not a part of the graded work. Given that, you can absolutely consult with classmates about how to get the answers to these ungraded problems.

4.5 Assignment

4.5.1 Chapra 2.10

See the MATLAB:Plotting page for information about the additional pieces of information you can give the plot command to change sizes and colors.

4.5.2 Chapra 2.27

Pretty straightforward. Note that your function will only have three lines of code - the paradigm (the first line at the top of the function that defines the file as a function and names the outputs and inputs) and the two lines that calculate x and y, respectively. The script should to the rest. Putting too much in the function is grounds for losing points. Precious, precious points.

4.5.3 Palm 3.12

See MATLAB:Selective Structures for a reminder of how to use an if tree. Also, think about the order in which you should check for valid arguments. A good first thing to check is whether the user even gave you two arguments to begin with! Click the word "Diary" to see what the diary should be: Diary

Trial  1: Incorrect entry or entries
Trial  2: Incorrect entry or entries
Trial  3: Length: 7.50e-01
Trial  4: Incorrect entry or entries
Trial  5: Incorrect entry or entries
Trial  6: Incorrect entry or entries
Trial  7: Incorrect entry or entries
Trial  8: Impossible Area
Trial  9: Length: 2.00e+00
Trial 10: Incorrect entry or entries
Trial 11: Incorrect entry or entries
Trial 12: Incorrect entry or entries

4.5.4 Pick a card!

Make sure you understand how mod works and the result it is giving you for mod(CardNum, 13) before attempting to modify it to produce the result you want. Also, see MATLAB:Mod for additional examples. If you want to know more about the for loop, you can look at MATLAB:Iterative Structures. Also, if you want to know more about how BuildTester works, you can type help BuildTester. Note that a .p file is a pre-compiled MATLAB file; it will run but you can't look at the code.

4.5.5 What card is that?

Make sure your function produces two different outputs for this one. If you want to know more about how InfoTester works, you can type help InfoTester.

4.5.6 Is that a three of a kind‽

Before tackling this one, really think about what you the human would do to see if a person has three of a kind -- what information is important and what information is irrelevant. If you want to know more about how TOKTester works, you can type help TOKTester.

General Concepts

This section is not in the lab report but rather has some items in it that span multiple problems in the lab.

Functions

See Chapra 3.1.2 and Palm 3.2 through page 123

Selective Structures

See MATLAB:Selective Structures, and note especially that if trees will only run if all the logical expression it is given is true. If you want to run when any of them is true, put the any() command with it. Also see Chapra 3.3.1 and Palm 4.4


Class Document Protection