Top Banner
EECS 183 Discussion #3: “Netflix and Code” January 27 th , 2016 Kevin Lee (mrkevin)
17

Discussion 3

Apr 14, 2017

Download

Documents

Kevin Lee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Discussion 3

EECS 183Discussion #3: “Netflix and Code”

January 27th, 2016Kevin Lee (mrkevin)

Page 2: Discussion 3

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)

Page 3: Discussion 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;

}

Page 4: Discussion 3

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;

}

Page 5: Discussion 3

• 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

Page 6: Discussion 3

• 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

Page 7: Discussion 3

• 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)

Page 8: Discussion 3

• 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

Page 9: Discussion 3

• 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

Page 10: Discussion 3

ASK_QUESTIONS();Any questions regarding functions?

Page 11: Discussion 3

CONDITIONALS

• Definition: A statement with a condition.

• If something evaluates to true, do something.• If something evaluates to false, do something.

Page 12: Discussion 3

IF (STUDENTS_WANT_EXAMPLES == TRUE)

Page 13: Discussion 3

BRANCHES

• Conditionals are often in a group of statements comprised of:

if (. . .) { }else if (. . .) { } // There can be many else ifselse (. . .) { }

• These are called branches.

Page 14: Discussion 3

IF (STUDENTS_WANT_EXAMPLES == TRUE)

Page 15: Discussion 3

IF (QUESTIONS) { ASK(); }

Page 16: Discussion 3

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.

Page 17: Discussion 3

THANKS!Class solution will be posted online in:

www.eecs183.org > Files > Discussion Sections > Kevin