CIS 3100 Structured Programming Intro

Curbalself balance deposits checks print deposits

This preview shows 23 out of 27 pages.

 
Image of page 23

Subscribe to view the full document.

CurBal(self) balance = deposits - checks print "Deposits $" + deposits + " Checks $" + checks + " Balance = $" + balance return toString(self) print "Deposits $" + deposits + " Checks $" + checks + " Balance = $" + balance return - These PYTHON methods are defined with public access and can be called by the main program  to access class variables or run class modules.     Logic Tip:  Class methods are the functional equivalent of the modules we have discussed in  earlier chapters. They contain a module header and program statements inside the body of the  method.   INSTANTIATING THE CLASS OBJECT IN THE APPLICATION   If you remember the structured programming programs shown earlier, the programs contained all  of the statements necessary for the program to execute. In my OOP version, the main program  has fewer statements and calls and the class object to perform much of the programs logic.   Below, the class file is inside the source file but outside the main body of our pseudo code  application. The very first statement of that main body identifies an object variable called cb.  When we instantiate the Checkbook class it will map of a block of memory which represents the  members of the Checkbook class which we will call using the object variable cb. This block of  memory will hold both the instance variables and also the class methods. Whenever we wish to  communicate to one of these variables or methods we use a dot notation to call out that member.  
Image of page 24
  Figure 4: Instantiating a class from file to memory.   Each time we create an object variable we can instantiate a different class object and create in a  different block of memory. For this program, we use only one class object called cb.   #start of program cb = CheckBook()
Image of page 25

Subscribe to view the full document.

  Status Check Differenciate between a class and instance variable? How is a method similar to a module?   THE MAIN LOGIC   In my sample program, I set the initial value of deposits to equal 100 and then I double deposits  by adding 100 to the current value of deposits (100) for a total of 200. I set the checks instance  variable to be 100. Finally, I call the CurBal method to return the difference between the values  stored in deposits less the value stored in checks.   cb.deposits = 100 print "Banking Summary" cb.deposits = (100 + cb.deposits) cb.checks = 100 cb.CurBal() - Note the dot that separates the object name and instance variable   CACTUS CASE STUDY   In the spirit of this chapter’s goal of introducing OOP only, we will not be creating our own class  object but instead we will be using one that was created by another programmer. Since the  Chavez sisters are implementing its audio book ordering system over the Internet, it will be  necessary for the application to accept credit card payments online. For the payment to be  processed correctly, certain information has to be captured from the web page and then sent as a  web service method call on the credit card company’s web site.
Image of page 26
Image of page 27
You've reached the end of this preview.

{[ 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