SlideShare a Scribd company logo
1 of 17
EECS 183
Discussion #3: “Netflix and Code”
January 27th, 2016
Kevin Lee (mrkevin)
SPECIAL DISCUSSION TODAY
• Minimal reviewing, mostly coding!
• Plan for Today:
• Start with a quick function review
• Then review conditionals (if, else if, else)
• Then, Netflix or Code! (a.k.a. SpringBreak.cpp)
FUNCTION REVIEW! – “MYSTERY CODE”
THE WELCOME
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Welcome” – This program should say “Hello” to whoever (the name) is passed
in.
__________ theWelcome(string __________) {
cout << __________ << __________ << endl;
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE WELCOME ANSWER
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Welcome” – This program should say “Hello” to whoever (the name) is passed
in.
void theWelcome(string name_in) {
cout << “Hello ” << name_in << endl;
}
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Duplicate” – This program will look at two people’s names, passed in as
parameters. If they are the same, it will return true, if not it will return false.
_________ theDupe(string name1, string name2) {
____ (name1 ____ name2) { _________ ______; }
____ { _________ ______; }
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE DUPLICATE
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Duplicate” – This program will look at two people’s names, passed in as
parameters. If they are the same, it will return true, if not it will return false.
bool theDupe(string name1, string name2) {
if (name1 == name2) { return true; }
else { return false; }
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE DUPLICATE ANSWER
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Duplicate” – This program will look at two people’s names, passed in as
parameters. If they are the same, it will return true, if not it will return false.
bool theDupe(string name1, string name2) {
if (name1 != name2) { return false; }
else { return true; }
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE DUPLICATE ANSWER (2)
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Debt” – This program should return the amount of money owed to the mystery
company multiplied by the amount of days overdue. These are passed in as
parameters.
_______ theDebt(_______ debt, _______ daysOverdue) {
_________ _________ * _________;
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE DEBT
• You’re a detective with your boss, Mister K. We just got word of this mystery code,
but some parts of it are missing! Fill in the missing areas, marked red.
• “The Debt” – This program should return the amount of money owed to the mystery
company multiplied by the amount of days overdue. These are passed in as
parameters.
double theDebt(double debt, int daysOverdue) {
return debt * daysOverdue;
}
FUNCTION REVIEW! – “MYSTERY CODE”
THE DEBT ANSWER
ASK_QUESTIONS();
Any questions regarding functions?
CONDITIONALS
• Definition: A statement with a condition.
• If something evaluates to true, do something.
• If something evaluates to false, do something.
IF (STUDENTS_WANT_EXAMPLES == TRUE)
BRANCHES
• Conditionals are often in a group of statements comprised of:
if (. . .) { }
else if (. . .) { } // There can be many else ifs
else (. . .) { }
• These are called branches.
IF (STUDENTS_WANT_EXAMPLES == TRUE)
IF (QUESTIONS) { ASK(); }
SPRINGBREAK.CPP
(ALSO KNOWN AS NETFLIX OR CODE :D)
• Take 5 minutes to try and write out the following scenario in pseudocode – we will
turn it into real code as a class!
• Scenario:
• You’re planning your Spring Break (woo)! You want your friends to come too, so you
decide to make a program to ask them.
• Your two main locations are: Egypt and London. Egypt costs $10,000 and London $7,000.
• Your friend will run your program and you will read in how much money the friend has.
If your friend has enough for Egypt, prompt them to go there. If not enough for Egypt, try
London. If that fails too, then prompt them to go somewhere with you in the US.
• You will also make a function called haveVacationTime(), which asks the user if they have
time for a vacation with you and returns true or false. They can only go on a vacation
with you if true.
THANKS!
Class solution will be posted online in:
www.eecs183.org > Files > Discussion Sections > Kevin

More Related Content

Similar to Discussion 3

Emergence of Invariance and Disentangling in Deep Representations
Emergence of Invariance and Disentangling in Deep RepresentationsEmergence of Invariance and Disentangling in Deep Representations
Emergence of Invariance and Disentangling in Deep RepresentationsSangwoo Mo
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REAkenbot
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part IIEugene Lazutkin
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable CodeBaidu, Inc.
 
Hadoop Streaming Tutorial With Python
Hadoop Streaming Tutorial With PythonHadoop Streaming Tutorial With Python
Hadoop Streaming Tutorial With PythonJoe Stein
 
Zero to Testing in JavaScript
Zero to Testing in JavaScriptZero to Testing in JavaScript
Zero to Testing in JavaScriptpamselle
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Omar Abdelhafith
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012cobyst
 
Algorithms - Future Decoded 2016
Algorithms - Future Decoded 2016Algorithms - Future Decoded 2016
Algorithms - Future Decoded 2016Frank Krueger
 
Forgot password for protected sheet on Microsoft Excel!?
Forgot password for protected sheet on Microsoft Excel!?Forgot password for protected sheet on Microsoft Excel!?
Forgot password for protected sheet on Microsoft Excel!?perfectpredesti94
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanshipbokonen
 

Similar to Discussion 3 (20)

Emergence of Invariance and Disentangling in Deep Representations
Emergence of Invariance and Disentangling in Deep RepresentationsEmergence of Invariance and Disentangling in Deep Representations
Emergence of Invariance and Disentangling in Deep Representations
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REA
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
Hadoop Streaming Tutorial With Python
Hadoop Streaming Tutorial With PythonHadoop Streaming Tutorial With Python
Hadoop Streaming Tutorial With Python
 
Zero to Testing in JavaScript
Zero to Testing in JavaScriptZero to Testing in JavaScript
Zero to Testing in JavaScript
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Jquery2012 defs
Jquery2012 defsJquery2012 defs
Jquery2012 defs
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Code smells in PHP
Code smells in PHPCode smells in PHP
Code smells in PHP
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Normalisation revision
Normalisation revisionNormalisation revision
Normalisation revision
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Algorithms - Future Decoded 2016
Algorithms - Future Decoded 2016Algorithms - Future Decoded 2016
Algorithms - Future Decoded 2016
 
Forgot password for protected sheet on Microsoft Excel!?
Forgot password for protected sheet on Microsoft Excel!?Forgot password for protected sheet on Microsoft Excel!?
Forgot password for protected sheet on Microsoft Excel!?
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 

Discussion 3

  • 1. EECS 183 Discussion #3: “Netflix and Code” January 27th, 2016 Kevin Lee (mrkevin)
  • 2. SPECIAL DISCUSSION TODAY • Minimal reviewing, mostly coding! • Plan for Today: • Start with a quick function review • Then review conditionals (if, else if, else) • Then, Netflix or Code! (a.k.a. SpringBreak.cpp)
  • 3. FUNCTION REVIEW! – “MYSTERY CODE” THE WELCOME • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Welcome” – This program should say “Hello” to whoever (the name) is passed in. __________ theWelcome(string __________) { cout << __________ << __________ << endl; }
  • 4. FUNCTION REVIEW! – “MYSTERY CODE” THE WELCOME ANSWER • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Welcome” – This program should say “Hello” to whoever (the name) is passed in. void theWelcome(string name_in) { cout << “Hello ” << name_in << endl; }
  • 5. • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Duplicate” – This program will look at two people’s names, passed in as parameters. If they are the same, it will return true, if not it will return false. _________ theDupe(string name1, string name2) { ____ (name1 ____ name2) { _________ ______; } ____ { _________ ______; } } FUNCTION REVIEW! – “MYSTERY CODE” THE DUPLICATE
  • 6. • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Duplicate” – This program will look at two people’s names, passed in as parameters. If they are the same, it will return true, if not it will return false. bool theDupe(string name1, string name2) { if (name1 == name2) { return true; } else { return false; } } FUNCTION REVIEW! – “MYSTERY CODE” THE DUPLICATE ANSWER
  • 7. • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Duplicate” – This program will look at two people’s names, passed in as parameters. If they are the same, it will return true, if not it will return false. bool theDupe(string name1, string name2) { if (name1 != name2) { return false; } else { return true; } } FUNCTION REVIEW! – “MYSTERY CODE” THE DUPLICATE ANSWER (2)
  • 8. • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Debt” – This program should return the amount of money owed to the mystery company multiplied by the amount of days overdue. These are passed in as parameters. _______ theDebt(_______ debt, _______ daysOverdue) { _________ _________ * _________; } FUNCTION REVIEW! – “MYSTERY CODE” THE DEBT
  • 9. • You’re a detective with your boss, Mister K. We just got word of this mystery code, but some parts of it are missing! Fill in the missing areas, marked red. • “The Debt” – This program should return the amount of money owed to the mystery company multiplied by the amount of days overdue. These are passed in as parameters. double theDebt(double debt, int daysOverdue) { return debt * daysOverdue; } FUNCTION REVIEW! – “MYSTERY CODE” THE DEBT ANSWER
  • 11. CONDITIONALS • Definition: A statement with a condition. • If something evaluates to true, do something. • If something evaluates to false, do something.
  • 13. BRANCHES • Conditionals are often in a group of statements comprised of: if (. . .) { } else if (. . .) { } // There can be many else ifs else (. . .) { } • These are called branches.
  • 15. IF (QUESTIONS) { ASK(); }
  • 16. SPRINGBREAK.CPP (ALSO KNOWN AS NETFLIX OR CODE :D) • Take 5 minutes to try and write out the following scenario in pseudocode – we will turn it into real code as a class! • Scenario: • You’re planning your Spring Break (woo)! You want your friends to come too, so you decide to make a program to ask them. • Your two main locations are: Egypt and London. Egypt costs $10,000 and London $7,000. • Your friend will run your program and you will read in how much money the friend has. If your friend has enough for Egypt, prompt them to go there. If not enough for Egypt, try London. If that fails too, then prompt them to go somewhere with you in the US. • You will also make a function called haveVacationTime(), which asks the user if they have time for a vacation with you and returns true or false. They can only go on a vacation with you if true.
  • 17. THANKS! Class solution will be posted online in: www.eecs183.org > Files > Discussion Sections > Kevin