discussion 3

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

Upload: kevin-lee

Post on 14-Apr-2017

31 views

Category:

Documents


0 download

TRANSCRIPT

EECS 183Discussion #3: “Netflix and Code”

January 27th, 2016Kevin 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 ifselse (. . .) { }

• 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