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.
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.