Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gotten how to do this, review last week’s lab.) You should now have a folder named lab3 inside a folder named Lab 3 (check this). 3. Download file main.c from cuLearn. Move this file into your lab3 folder. You must also add main.c to your project: from the menu bar, select Project > Add files to project... In the dialogue box, select main.c, then click Open. An icon labelled main.c will appear in the Pelles C project window. 4. Open main.c. Sample Exercise A function named s e p i has two parameters: le_n _olsepi(Bo wedy _olvcto) Bo le_n_ol eka, Bo aain; Parameter w e d y s t u if today is a weekday, and parameter v c t o is t u if we are on e k a i r e aain re vacation. We sleep in if it is not a weekday or we're on vacation. The function should return t u if we re sleep in today; otherwise it should return f l e as. Solution: the condition, "we sleep in if is not a weekday" can be coded as: i ( w e d y . . f !eka). The condition, "we sleep in if we are on vacation"can be coded as: i ( a a i n . . ince we f v c t o ) . S sleep in if either condition is true, we use the | operator to combine the conditions: | i (wedy| vcto){ f !eka | aain rtr tu; eun re }es { le rtr fle eun as; } Because the "true" clause in the i statement has a return statement, we don't need the e s clause. f le Our solution becomes: _olsepi(Bo wedy _olvcto){ Bo le_n_ol eka, Bo aain i (wedy| vcto){ f !eka | aain rtr tu; eun re } rtr fle eun as; } 2 It is better programming style to write v c t o than v c t o = t u . These expressions aain aain = re mean exactly the same thing, so testing a boolean variable for equality with t u is superfluous. re Likewise, writing ! e k a is better style than writing w e d y = f l e wedy eka = as. Function s e p i has already been...
View Full Document

This lab report was uploaded on 03/28/2014 for the course SYSC 2006 taught by Professor Schram during the Spring '12 term at Carleton CA.

Ask a homework question - tutors are online