Final Practice Write a function string char_replace(char replace, char with, string s) that replaces...

14
Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string s with the character with. Write a function void char_replace_arr(char replace, char with, string arr[], int size) that replaces all occurrences of the character replace in the array arr with the character with.

Transcript of Final Practice Write a function string char_replace(char replace, char with, string s) that replaces...

Page 1: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Final PracticeWrite a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string s with the character with.

Write a function void char_replace_arr(char replace, char with, string arr[], int size) that replaces all occurrences of the character replace in the array arr with the character with.

Page 2: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Databases

Page 3: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Think of all the data that Amazon has to manage

• Millions of different items for sale• Millions of customer accounts

• When I search on Amazon, how can it sift through all that stuff and find what I want so quickly?

• Databases!

Page 4: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

How you represent and organize data is important

• If we just had a list of items and people, we could never find anything, and you’d have to individually program every item’s webpage

• Let’s create some structure. – Structure for items and for people is completely

different, so we’ll create one database for items and one for people

– Structure to an Amazon webpage gives us clues to the way the data is structured when it’s stored

Page 5: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Relational databasesTitle (key field) Author/brand List

pricePrice Shipping

weightDescription, Reviews, format, categories, etc

Harry Potter and the Sorcerer’s Stone

J.K. Rowling 10.99 7.14 2 pounds …

Casio Men's MQ24-1E Analog Watch

Casio 21.95 8.49 2.9 ounces …

London Calling [Original Recording Reissued, Original Recording Remastered]

The Clash 6.99 …

South Shore Axess Collection 3-Shelf Bookcase, Chocolate

South Shore Furniture

119.00 45.98 46 pounds …

Casio Digital Camera Exilim EX-ZS6 BK, Black

Casio 90.75 9.6 ounces …

London Calling The Clash 5.00 …

Page 6: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Relational databases

• Can search on any field– Title, artist/brand, category, etc

• But how can we make search efficient across all fields at the same time????

• Using Binary Sort– If a list is sorted, it’s much easier to find stuff

• This isn’t quite how it works, but it’s the basic idea

– But keeping a list sorted is a total pain, and anyway, we can’t sort on everything at once!

• An index into a database is a file that is sorted based on a certain field, and once you find the item you want, it tells you where that full item is stored.

Page 7: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Index for AuthorAuthor/Brand Title(Key field) (optional) Position

Casio Casio Men's MQ24-1E Analog Watch

2

Casio Casio Digital Camera Exilim EX-ZS6 BK, Black

5

The Clash London Calling 6

The Clash London Calling [Original Recording Reissued, Original Recording Remastered]

3

J.K. Rowling Harry Potter and the Sorcerer’s Stone

1

South Shore Furniture South Shore Axess Collection 3-Shelf Bookcase, Chocolate

4

Position Title(Key field Author/brand

List price

Price Shipping weight

Description, Reviews, format, categories, etc

1 Harry Potter and the Sorcerer’s Stone J.K. Rowling 10.99 7.14 2 pounds …

2 Casio Men's MQ24-1E Analog Watch Casio 21.95 8.49 2.9 ounces …

3 London Calling [Original Recording Reissued, Original Recording Remastered]

The Clash 6.99 …

4 South Shore Axess Collection 3-Shelf Bookcase, Chocolate South Shore Furniture

119.00 45.98 46 pounds …

5 Casio Digital Camera Exilim EX-ZS6 BK, Black Casio 90.75 9.6 ounces …

6 London Calling The Clash 5.00 …

Page 8: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Purchases databasePosition Person Item Date Delivery status,

etc1 1 1 1/3/12 …

2 2 3 4/2/11 …

3 1 3 2/6/13 …

Position Title(Key field Author/brand

List price

Price Shipping weight

Description, Reviews, format, categories, etc

1 Harry Potter and the Sorcerer’s Stone J.K. Rowling 10.99 7.14 2 pounds …

2 Casio Men's MQ24-1E Analog Watch Casio 21.95 8.49 2.9 ounces …

3 London Calling [Original Recording Reissued, Original Recording Remastered]

The Clash 6.99 …

4 South Shore Axess Collection 3-Shelf Bookcase, Chocolate South Shore Furniture

119.00 45.98 46 pounds …

5 Casio Digital Camera Exilim EX-ZS6 BK, Black Casio 90.75 9.6 ounces …

6 London Calling The Clash 5.00 …

Position Name Address Purchases, etc

1 Bill Smith 1029 Main St …

2 Jim Johnson 139 1st Ave …

3 Sarah Pollard 231 4th St. …

Page 9: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Databases are interconnectedPosition Person Item Date Delivery status,

etc1 1/3/12 …

2 4/2/11 …

3 2/6/13 …

Position Title(Key field Author/brand

List price

Price Shipping weight

Description, Reviews, format, categories, etc

1 Harry Potter and the Sorcerer’s Stone J.K. Rowling 10.99 7.14 2 pounds …

2 Casio Men's MQ24-1E Analog Watch Casio 21.95 8.49 2.9 ounces …

3 London Calling [Original Recording Reissued, Original Recording Remastered]

The Clash 6.99 …

4 South Shore Axess Collection 3-Shelf Bookcase, Chocolate South Shore Furniture

119.00 45.98 46 pounds …

5 Casio Digital Camera Exilim EX-ZS6 BK, Black Casio 90.75 9.6 ounces …

6 London Calling The Clash 5.00 …

Position Name Address Purchases, etc

1 Bill Smith 1029 Main St …

2 Jim Johnson 139 1st Ave …

3 Sarah Pollard 231 4th St. …

Page 10: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Schema – who has access to what?Position Person Item Date Delivery status,

etc1 1/3/12 …

2 4/2/11 …

3 2/6/13 …

Position Title(Key field Author/brand

List price

Price Shipping weight

Description, Reviews, format, categories, etc

1 Harry Potter and the Sorcerer’s Stone J.K. Rowling 10.99 7.14 2 pounds …

2 Casio Men's MQ24-1E Analog Watch Casio 21.95 8.49 2.9 ounces …

3 London Calling [Original Recording Reissued, Original Recording Remastered]

The Clash 6.99 …

4 South Shore Axess Collection 3-Shelf Bookcase, Chocolate South Shore Furniture

119.00 45.98 46 pounds …

5 Casio Digital Camera Exilim EX-ZS6 BK, Black Casio 90.75 9.6 ounces …

6 London Calling The Clash 5.00 …

Position Name Address Purchases, etc

1 Bill Smith 1029 Main St …

2 Jim Johnson 139 1st Ave …

3 Sarah Pollard 231 4th St. …

Page 11: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Data mining

• But Amazon searching is smarter than this; I can do more than just search for “South Shore Axess Collection 3-Shelf Bookcase, Chocolate” or “J.K. Rowling”

• How does Amazon know that if you’re looking for The Clash, you might also want Joe Strummer?– By analyzing all the information it has on purchases• Btw, there is also probably a completely different database

for every purchase anyone has ever made on amazon• This database would have billions of entries• They might even have a db for views!!!

Page 12: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

Data mining

• Take a static copy of the DB at some point in time– Too hard to work with data that is changing

• Look for patterns– If we look just at people who bought Harry Potter and

the Sorcerer’s Stone, what are the other items that they were most likely to buy?

– What are some clusters of things that people liked to buy? Are there groups of items that occur a lot?

– A lot of techniques from statistics and artificial intelligence• Data mining is the future of AI

Page 14: Final Practice Write a function string char_replace(char replace, char with, string s) that replaces all occurrences of the character replace in the string.

S L

R 6 7

B 7 8

Write a procedure in pseudocode to compute the price of shirts. You are selling two sizes of shirts: Small and Large. You are also selling two colors of shirts: Red and Blue. The price is determined according to the chart below. If the user enters a size or a color that is not in your inventory, print out the message “Don’t got. :(”