Homework 5
This presentation is the property of its rightful owner.
Sponsored Links
1 / 33

Homework 5 PowerPoint PPT Presentation


  • 59 Views
  • Uploaded on
  • Presentation posted in: General

Homework 5. Sun., 10/6. ( MT sections ). Due. at midnight. Mon., 10/7. ( WTh sections ). Problems. http://www.cs.hmc.edu/courses/2002/fall/cs5/week_05/homework.html. CS 5 website. http://www.cs.hmc.edu/courses/2002/fall/cs5/. Submission problems or other concerns?.

Download Presentation

Homework 5

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Homework 5

Homework 5

Sun., 10/6

( MT sections )

  • Due

at midnight

Mon., 10/7

( WTh sections )

  • Problems

http://www.cs.hmc.edu/courses/2002/fall/cs5/week_05/homework.html

  • CS 5 website

http://www.cs.hmc.edu/courses/2002/fall/cs5/

  • Submission problems or other concerns?

email [email protected] or [email protected]


Homework 5

  • Tutors available

Academic Computing labs (Parsons)

Friday Afternoons 1-4 pm

----------------------------------------

Chris Hwang this week (10/4): Parsons

Don Lee this week (10/4): Parsons

Daniel Chan this week (10/4): LAC Lab

Zach Andree this week (10/4): LAC Lab

Annie Chang this week (10/4): LAC Lab

Saturday Afternoons 1-4pm

----------------------------------------

Chris Weisiger this week (10/5): Parsons

Yu-Min Kim this week (10/5): Parsons

Elizabeth Lee-Su this week (10/5): LAC Lab

Aaron Homer this week (10/5): LAC Lab

Sunday Afternoons 1-4pm

----------------------------------------

Gabriel Neer this week (10/6): Parsons

Jeff Brenion this week (10/6): LAC Lab

Rene Logan this week (10/6): LAC Lab

Linde Activities Center lab


Homework 5

  • Tutors available

Sunday evenings 7-12pm

----------------------------------------

Jenny Xu 6-9 this week (10/6): Parsons

Eric Flynn 7-10 this week (10/6): Parsons

Melissa Federowicz 7-10 this week (10/6): LAC Lab

Max Yi 7-10 this week (10/6): LAC Lab

Yu-Min Kim 9-12 this week (10/6): Parsons

A. Klose 9-12 this week (10/6): Parsons

Matt Beaumont-Gay 9-12 this week (10/6): LAC Lab

Chris Hwang 9-12 this week (10/6): LAC Lab

Monday Evenings 7-12pm

----------------------------------------

Adam Kangas 7-10 this week (10/7): Parsons

Ryka Neher 7-10 this week (10/7): Parsons

Max Yi 7-10 this week (10/7): LAC Lab

Annie Chang 9-12 this week (10/7): Parsons

Paul Scott 9-12 this week (10/7): Parsons

John McCollough 9-12 this week (10/7): Parsons

Alex Pipkin 9-12 this week (10/7): LAC Lab

Chris Wottawa 9-12 this week (10/7): LAC Lab

Alex Utter 9-12 this week (10/7): LAC Lab


Homework 5

Problem 2 -- Caesar Cipher

Encryption strategy

Choose an amount to shift your message.

Move each letter that amount.

message:

shift amount:

3

encrypted message:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru


Homework 5

bloody instructions which return to plague their inventor

Macbeth, Act I, Scene 7

???


Homework 5

Problem 2 -- Caesar Cipher

Decryption strategy

Shift the encrypted message by every possible shift amount

Pick out the English text...

encrypted message:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru

all possible shifts:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru

fpsshc mrwxvygxmsrw almgl vixyvr xs tpekyi xlimv mrzirxsv

gqttid nsxywzhyntsx bmnhm wjyzws yt uqflzj ymjnw nsajsytw

hruuje otyzxaizouty cnoin xkzaxt zu vrgmak znkox otbktzux

isvvkf puzaybjapvuz dopjo ylabyu av wshnbl aolpy pucluavy

jtwwlg qvabzckbqwva epqkp zmbczv bw xtiocm bpmqz qvdmvbwz

kuxxmh rwbcadlcrxwb fqrlq ancdaw cx yujpdn cqnra rwenwcxa

lvyyni sxcdbemdsyxc grsmr bodebx dy zvkqeo drosb sxfoxdyb

mwzzoj tydecfnetzyd hstns cpefcy ez awlrfp esptc tygpyezc

nxaapk uzefdgofuaze ituot dqfgdz fa bxmsgq ftqud uzhqzfad

< skipping 9 lines >

xhkkzu ejopnqypekjo sdeyd napqnj pk lhwcqa pdaen ejrajpkn

yillav fkpqorzqflkp tefze obqrok ql mixdrb qebfo fksbkqlo

zjmmbw glqrpsargmlq ufgaf pcrspl rm njyesc rfcgp gltclrmp

aknncx hmrsqtbshnmr vghbg qdstqm sn okzftd sgdhq hmudmsnq

bloody instructions which return to plague their inventor

cmppez jotusvdujpot xijdi sfuvso up qmbhvf uifjs jowfoups

dnqqfa kpuvtwevkqpu yjkej tgvwtp vq rnciwg vjgkt kpxgpvqt


Homework 5

Resources

Suppose we have a method that shifts a character c by n letters.

Assume these work...

char advanceChar(char c, int n)

advanceChar(‘h’, 4) is

advanceChar(‘z’, 2) is

String s = “more java”;

length() (tells the length of a String)

charAt(int n) (returns the nth char of a String)

s.length() is

s.charAt(2) is

s.charAt( ) is ‘v’


Homework 5

High-level plan

char advanceChar(char c, int n)

length() (tells the length of a String)

charAt(int n) (returns the nth char in a String, starting at 0)

We have

What to do ?


Homework 5

advanceChar

Now we need to worry about making this piece work...

public static char advanceChar(char c, int n)


Homework 5

Working with chars

99

122

97

98

123

_ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~

char c = ‘y’;

c = (char)(c - 2);

c += 5;

How do we get back?


Homework 5

Style note

// Name: advanceChar

// Inputs: a char (c) and an int (n)

// Output: the char that is n places

// to the right of c, where the

// alphabet wraps from ‘z’ to ‘a’.

// be sure to comment each method you write!

public staticchar advanceChar(char c, int n)


Homework 5

A message from our sponsor

public static void main(String[] args)

{

int x = H.in.nextInt();

int y = H.in.nextInt();

int z = confusing(x,y);

H.out.println(“z is ” + z);

}

public static int confusing(int y, int x)

{

int a = 0;

a = 10*y + x;

return a;

}


Homework 5

Problem 1 -- finding ex

Please input a power (a double) and I will raise e to that power: 2.5

Enter the number of terms you'd like to use (an int >= 1): 10

The result is 12.179115120485767

Would you like to continue (yes/no)? no

This is e2.5 computed using 10 terms of the series

x0

x1

x2

x3

+

+

+

+…

Inside main :

0!

1!

2!

3!

4 terms


Homework 5

What does exp do?

What are x and numTerms referring to?

exp

public static double exp(double x, int numTerms)


Homework 5

power

What does power do?

What are base and p referring to?

public static double power(double base, int p)


Homework 5

factorial

What does factorial do?

What is n referring to?

public static double factorial(int n)


Homework 5

Problem 1 -- finding ex

Please input a power (a double) and I will raise e to that power: 2.5

Enter the number of terms you'd like to use (an int >= 1): 10

The result is 12.179115120485767

Would you like to continue (yes/no)? no

Inside main :


Homework 5

This is e2.5 computed using 10 terms of the series

x0

x1

x2

x3

+

+

+

+…

0!

1!

2!

3!

4 terms


Homework 5

Homework 5

Sun., 10/6

( MT sections )

  • Due

at midnight

Mon., 10/7

( WTh sections )

  • Problems

http://www.cs.hmc.edu/courses/2002/fall/cs5/week_05/homework.html

  • CS 5 website

http://www.cs.hmc.edu/courses/2002/fall/cs5/

  • Submission problems or other concerns?

email [email protected] or [email protected]


Homework 5

  • Tutors available

Academic Computing labs (Parsons)

Friday Afternoons 1-4 pm

----------------------------------------

Chris Hwang this week (10/4): Parsons

Don Lee this week (10/4): Parsons

Daniel Chan this week (10/4): LAC Lab

Zach Andree this week (10/4): LAC Lab

Annie Chang this week (10/4): LAC Lab

Saturday Afternoons 1-4pm

----------------------------------------

Chris Weisiger this week (10/5): Parsons

Yu-Min Kim this week (10/5): Parsons

Elizabeth Lee-Su this week (10/5): LAC Lab

Aaron Homer this week (10/5): LAC Lab

Sunday Afternoons 1-4pm

----------------------------------------

Gabriel Neer this week (10/6): Parsons

Jeff Brenion this week (10/6): LAC Lab

Rene Logan this week (10/6): LAC Lab

Linde Activities Center lab


Homework 5

  • Tutors available

Sunday evenings 7-12pm

----------------------------------------

Jenny Xu 6-9 this week (10/6): Parsons

Eric Flynn 7-10 this week (10/6): Parsons

Melissa Federowicz 7-10 this week (10/6): LAC Lab

Max Yi 7-10 this week (10/6): LAC Lab

Yu-Min Kim 9-12 this week (10/6): Parsons

A. Klose 9-12 this week (10/6): Parsons

Matt Beaumont-Gay 9-12 this week (10/6): LAC Lab

Chris Hwang 9-12 this week (10/6): LAC Lab

Monday Evenings 7-12pm

----------------------------------------

Adam Kangas 7-10 this week (10/7): Parsons

Ryka Neher 7-10 this week (10/7): Parsons

Max Yi 7-10 this week (10/7): LAC Lab

Annie Chang 9-12 this week (10/7): Parsons

Paul Scott 9-12 this week (10/7): Parsons

John McCollough 9-12 this week (10/7): Parsons

Alex Pipkin 9-12 this week (10/7): LAC Lab

Chris Wottawa 9-12 this week (10/7): LAC Lab

Alex Utter 9-12 this week (10/7): LAC Lab


Homework 5

Problem 2 -- Caesar Cipher

Encryption strategy

Choose an amount to shift your message.

Move each letter that amount.

message:

shift amount:

3

encrypted message:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru


Homework 5

Problem 2 -- Caesar Cipher

Decryption strategy

Shift the encrypted message by every possible shift amount

Pick out the English text...

encrypted message:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru

all possible shifts:

eorrgb lqvwuxfwlrqv zklfk uhwxuq wr sodjxh wkhlu lqyhqwru

fpsshc mrwxvygxmsrw almgl vixyvr xs tpekyi xlimv mrzirxsv

gqttid nsxywzhyntsx bmnhm wjyzws yt uqflzj ymjnw nsajsytw

hruuje otyzxaizouty cnoin xkzaxt zu vrgmak znkox otbktzux

isvvkf puzaybjapvuz dopjo ylabyu av wshnbl aolpy pucluavy

jtwwlg qvabzckbqwva epqkp zmbczv bw xtiocm bpmqz qvdmvbwz

kuxxmh rwbcadlcrxwb fqrlq ancdaw cx yujpdn cqnra rwenwcxa

lvyyni sxcdbemdsyxc grsmr bodebx dy zvkqeo drosb sxfoxdyb

mwzzoj tydecfnetzyd hstns cpefcy ez awlrfp esptc tygpyezc

nxaapk uzefdgofuaze ituot dqfgdz fa bxmsgq ftqud uzhqzfad

< skipping 9 lines >

xhkkzu ejopnqypekjo sdeyd napqnj pk lhwcqa pdaen ejrajpkn

yillav fkpqorzqflkp tefze obqrok ql mixdrb qebfo fksbkqlo

zjmmbw glqrpsargmlq ufgaf pcrspl rm njyesc rfcgp gltclrmp

aknncx hmrsqtbshnmr vghbg qdstqm sn okzftd sgdhq hmudmsnq

bloody instructions which return to plague their inventor

cmppez jotusvdujpot xijdi sfuvso up qmbhvf uifjs jowfoups

dnqqfa kpuvtwevkqpu yjkej tgvwtp vq rnciwg vjgkt kpxgpvqt


Homework 5

Resources

Suppose we have a method that shifts a character c by n letters.

Assume these work...

char advanceChar(char c, int n)

advanceChar(‘h’, 4) is

advanceChar(‘z’, 2) is

String s = “more java”;

length() (tells the length of a String)

charAt(int n) (returns the nth char of a String)

s.length() is

s.charAt(2) is

s.charAt( ) is ‘v’


Homework 5

High-level plan

char advanceChar(char c, int n)

length() (tells the length of a String)

charAt(int n) (returns the nth char in a String, starting at 0)

We have

What to do ?


Homework 5

advanceChar

Now we need to worry about making this piece work...

public static char advanceChar(char c, int n)


Homework 5

Working with chars

99

122

97

98

123

_ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~

char c = ‘y’;

c = (char)(c - 2);

c += 5;

How do we get back?


Homework 5

Style note

// Name: advanceChar

// Inputs: a char (c) and an int (n)

// Output: the char that is n places

// to the right of c, where the

// alphabet wraps from ‘z’ to ‘a’.

// be sure to comment each method you write!

public staticchar advanceChar(char c, int n)


Homework 5

A message from our sponsor

public static void main(String[] args)

{

int x = H.in.nextInt();

int y = H.in.nextInt();

int z = confusing(x,y);

H.out.println(“z is ” + z);

}

public static int confusing(int y, int x)

{

int a = 0;

a = 10*y + x;

return a;

}


Homework 5

Problem 1 -- finding ex

Please input a power (a double) and I will raise e to that power: 2.5

Enter the number of terms you'd like to use (an int >= 1): 10

The result is 12.179115120485767

Would you like to continue (yes/no)? no

This is e2.5 computed using 10 terms of the series

x0

x1

x2

x3

+

+

+

+…

Inside main :

0!

1!

2!

3!

4 terms


Homework 5

What does exp do?

What are x and numTerms referring to?

exp

public static double exp(double x, int numTerms)


Homework 5

power

What does power do?

What are base and p referring to?

public static double power(double base, int p)


Homework 5

factorial

What does factorial do?

What is n referring to?

public static double factorial(int n)


  • Login