program options: 10 minutes online write a program that will display your home address as it would...
Post on 18-Jan-2018
218 Views
Preview:
DESCRIPTION
TRANSCRIPT
Program Options: 10 Minutes online• Write a program that will display your home address as it would on
an envelope.– First Name Last Name– Address– City, State Zip Code– Push: Let the user enter some or all of the information, and have your program format
it.• Write a mad-lib program
– Have the user enter at least 4 pieces of information. • Noun, Adverb (honestly), Adjective (messy), Verb, Geographical location, …
– The computer will generate the mad-lib– Here is a sample website
• http://us.penguingroup.com/static/packages/us/yreaders/madlibs/fun.html
• Write a program that shows a poem or song. Can be an original work. Include space as appropriate.– Push: Look up for..do, or repeat..until to have your program repeat the song several
times.– Push: Use the Pascal tutorial to add color etc.
Computer Science 19/15/2015
ReviewDry Run
Math in PascalHow do you start, when you don’t know
where to start?
Goals
• Improve in your ability to execute a dry run.
• See how to let Pascal do the math.• Go through pseudo code for the second
programming assignment• Give second programming assignment
Review: What do you recall about…?• Program review;• Var
– X:real;– Y:integer;
• begin– Writeln(‘Hello world.’);– x:= 5.4321;– Y:= 10;– Writeln(y);– Writeln(‘Hello’, y);– Writeln(‘World’, x:10:2);– readln;
• End.
Dry run 1 (What do you think the
following program does?)
{Mr. Smith's Sample Program}{Dry Run #1}{9/15/2015}program DryRunTest;uses crt;var a,b,c:integer;
begin clrscr; a:= 8; b:= 6; c:= a+b; writeln(a, b, c); b:= b + 2*a; a:= a + 7; writeln(a, b, c);end.
a b c
Screen
Math Math Pascal Code Example+ + Ans:= first+second;- - Ans:= second – first;x * Ans := first * second;÷ / Ans := first / second() () Ans := (first + 2)/second;π PI Ans := PI;
52 sqr Ans := sqr(first);√ Sqrt() Ans:= sqrt(first);
You turn: What is the result of the following?
Expression Answer Type2+ 125*(8-15)5 + 6*36 + 4/2 – 8(6+4)/2 – 8(6+4)/(2-8)Sqrt(9)Sqrt(4*4 + 9)Sqrt(sqr(3) + sqr(4))
Summary
• Write a one to three sentence summary of using Math in Pascal.
Review: What do you recall about…?• Program review;• Var
– X:real;– Y:integer;
• begin– Writeln(‘Hello world.’);– x:= 5.4321;– Y:= 10;– Writeln(y);– Writeln(‘Hello’, y);– Writeln(‘World’, x:10:2);– readln;
• End.
Evaluate the following• 2*5-6• Sqr(8-2*2)• Sqrt(8-2*2)Translate to PascalX-2y(1/2)(bh)
Steps to code
• Hands on– Doing samples by hand.
• Pseudo code– Write out instructions in English
• Dry Run– Testing your instructions
• Code– Translate the Pseudo-Code to Pascal.
Sample program
• Input: The radius and height of a cylinder.• Process:
– Surface area = πr2 + πr2 +2 πrh– Volume = πr2h
• Output: The Volume and surface area of the cylinder.
Hands on
– Surface area = πr2 + πr2 +2 πrh– Volume = πr2h
• Test: • Radius of 1 inch and height of 1 inch• Radius of 2 inches and height of 10 inches
Pseudo Code
• Describe what we did to solve this.
Dry Run
• Test the pseudo code
Code
• Translate the Pseudo code to code, Pascal in the case of this class.
Program optionso Write a program for one of the followingo Volume and surface area of cylinder
o Input: The radius and height of a cylinder.o Process:
o Surface area = πr2 + πr2 +2 πrho Volume = πr2h
o Output: The Volume and surface area of the cylinder.o Write a program to calculate the volume of a spherical
cap. Include the needed inputs.o a = radius of the capo r = radius of the sphereo h = height of the cap
Write a second program for one of the following
aacbbroot
241
2
top related