Appointment checktimetime t calendar c appointment

Info icon This preview shows pages 15–22. Sign up to view the full content.

View Full Document Right Arrow Icon
add this! Appointment *checkTime(Time &t) Calendar c; ... Appointment *appt; appt = c.checkTime(“5pm”); if (appt == NULL)    cout << “No appt at 5pm”; So far, so good.  Now, can we determine  who’s at an appointment ? Hmmm… Appointment bool setStartTime(Time &st) bool setEndTime(Time &st) bool addParticipant(string &user) bool setLocation(string &location) Appointment() &  virtual  ~Appointment() private: Time m_startTime; Time m_endTime; string m_participants[10]; string m_location; Nope.  We’ll need to add this to our  Appointment class! bool isAttendee(string &person) else if (appt->isAttendee(“Joe”))     cout << “Joe is attending!”;
Image of page 15

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Class Design Conclusions First and foremost,  class design is an iterative process .   Before you ever start to program your class implementations, it helps to  determine your  classes , their  interfaces , their  data , and their  interactions . It’s important to go through all of the  use cases  in order to make sure you  haven’t forgotten anything. This is something that you only get better at with   experience , so   don’t feel bad   if its difficult at first!
Image of page 16
Recursion! Building a  SuDoKu  solver! Even cracking  codes  and  ciphers ! Recursion is one of the most  difficult topics  in Computer  Science… But once you master it, you  can  solve  all sorts of  cool  problems !         Writing a computer         program that can          play  chess  or  checkers !
Image of page 17

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Recursion! Before we talk about recursion, its important to understand how parameters  are passed to functions in C++. void bar(int b) { cout << b << endl; } void foo(int a) { cout << a << endl; bar(a*2); } void main(void) { int x = 1; foo(x); foo(3); }   1 x a 1 b 2 Output: 1 2 a 3 3 b 6 6 Watch our  variable diagrams  very  carefully! What  data structure  does this remind  you of?
Image of page 18
Recursion! When you  pass a value to a function , C++  pushes  that value onto a  stack   in the computers memory.   Every time you  declare a local variable , your program puts it on the PC’s  stack automatically!  Recursion , as we’ll learn, relies heavily on the stack. … and when your  function returns , the values are  popped  off the stack  and go away.
Image of page 19

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Recursion! Recursion  is a programming technique where a  function calls itself recursive function  works by applying itself on a simpler sub-problem over  and over until the most basic subproblem is reached and handled trivially.  Recursive algorithm to a sort a deck of index cards:  1. Compute the  median number  in the deck  2. Put cards with values  less than the median  in a pile on the       left  3. Put cards with values  greater than the median  in a pile on       the right  4. Repeat steps 1-4 on each sub-pile of more than one card
Image of page 20
Recursion!
Image of page 21

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 22
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern