360 likes | 481 Views
14. CHAPTER. Programming. MIS105 Week-15/ Lec02 Irfan Ahmed Ilyas. Lecture Objectives. Phases in Software Development Cycle Phase1 : Program Specifications Phase2: Program Design ( Documentation Techniques ) Psuedo code Flow charting Phase 3 : Program Coding
E N D
14 CHAPTER Programming MIS105 Week-15/ Lec02 Irfan Ahmed Ilyas
Lecture Objectives • Phases in Software Development Cycle • Phase1: Program Specifications • Phase2: Program Design (Documentation Techniques) • Psuedo code • Flow charting • Phase 3: Program Coding • Phase 4: Program Testing • Phase 5: Installing the Program • Phase 6: Program Documentation • Phase 7: Program Maintenance Prepared By: Irfan Ilyas
21 4A5E 4096 A Machine Language Instruction 3. Program Code • Program design/ flow chart logics are transferred to Computer Language Code • Two main types of ComputerLanguages • Low Level (Machine Languages) • A computer’s own internal language • Different for every computer • Very complex to write programs • Memory addresses need to be used literally • Example: machine code of Intel x86 processors or Prepared By: Irfan Ilyas
LET TOTAL = AMT1 + AMT2 A program instruction in Quick Basic … 3. Program Code • ….Main types of Computer Languages • High Level (Symbolic Languages) • Uses English like syntax • Commonly used on different hardware platforms • Much easier to use than machine languages • Simple symbolic names can be used for Memory addresses • Needs a translator program (compiler) to generate the equivalent machine code • Examples: Quick BASIC, C++, Java Prepared By: Irfan Ilyas
….2- Example ( Advantage Advertising)C++ Code for“Compute time for Client A” Prepared By: Irfan Ilyas
…3. Program Code (Issues) • A variety of High Level Languages are available, including • Visual Basic, • Visual C • Java • Small Talk • Fortran • Selecting a particular language depends upon • The expertise of the programmer • Resources available for the program (hard-disk space, monitor type etc.) • The application area of the program Prepared By: Irfan Ilyas
4. Program Test (Debugging) • Process of removing bugs (errors) from a program • Possible error types • Syntax Errors (Coding Errors) • Coding incorrectly • Causes: Typing mistakes/ violating language rules • Example: • PRNT “Hello” ‘A syntax error in PRINT statement of Quick Basic • printf(“%s: %d”,”Result”,x) ‘In C++, statement does not end with a semicolon (;) Prepared By: Irfan Ilyas
…4. Program Test (Debugging) • ….Possible error types • Logic Errors (Algorithm Errors) • Mistakes in algorithm steps • Results in • incorrect outputs • Run-time crashes • Causes: • Mistakes in the instruction sequence • Using inappropriate instructions • Not very obvious when happening with some particular values of data inputs Prepared By: Irfan Ilyas
…4. Program Test (Debugging) • How to debug? • Syntax Errors • Carefully comparing the program with the language valid codes • Captured automatically by the translator programs (compilers) • Logic Errors • Running the program with test data (input values for which correct results are known) • Logic errors are pinpointed when • a known input-output pair doesn’t match • Program crashes for some input values. • Debugger Programs are available (with almost all language compilers) to pinpoint logic errors Prepared By: Irfan Ilyas
…4. Program Test (Debugging) • Standard program testing procedure • Desk checking • Manual testing with sample (test) data • Attempt at translation • Testing sample data on computer • Testing by a selected group of potential users (beta users) Prepared By: Irfan Ilyas
5. Installing the Program • A program is usually implemented as part of an overall, integrated information system • Example: • An Accounting Information System • Composed of many different programs (built independently) • Each program works for a different accounting area like general ledger, payroll etc. • The programs are then implemented in an integrated manner to bring up the overall information system Prepared By: Irfan Ilyas
6.Program Documentation • Documentation explains every facet of a program (usage, development, error-handling) • Should be on-going throughout program development • Should be compiled and organized at the final stages • Addresses three possible communities • Program Users • Program Operators • Program Developers Prepared By: Irfan Ilyas
7. Program Maintenance • Two broad Maintenance categories • Correction of emerging errors • Modification for changing user needs • Significantly consumes the share of total development time (>75%) • Mostly done by specially hired programmers (Maintenance Programmers) Prepared By: Irfan Ilyas
Introducing Object Oriented Programming Prepared By: Irfan Ilyas
Lecture Objectives • Introducing Object Oriented Programming (OOP) • Classes & Objects • Attributes & methods • Benefits of OOP • Reusability (inheritance) • Hiding complexity (encapsulation) • Context driven functionality (polymorphism) Prepared By: Irfan Ilyas
… Lecture Objectives • Introducing Microsoft Access VBA Programming • Concept of Microsoft Access application • VBA- Object based Programming • Microsoft Access Objects • Event driven programs • Event procedures Prepared By: Irfan Ilyas
Object Oriented Programming (OOP) • Object is a programming unit having • data (attributes) • methods (operations) • Every object represents some physical object in the real life situation (being programmed) • Every object in a program is created from its Class. • Programmers write Class code for every needed object (class) • Main program is just creating objects and make use of their functionalities Prepared By: Irfan Ilyas
Client_Bill Main Program ClientNameRegularHoursOvertimeHoursRegularRateOvertimeRate Client_Bill object for Client A computeClientBill( TimeCardRecords )printBill( ) Client_Bill object for Client B Example: Advantage Advertising Attributes Methods A class for client bill object Prepared By: Irfan Ilyas
Example: Advantage Advertising Psuedo code for the main program (using Client_Bill Objects) START PROGRAM Create object bill_for_clientA from class Client_Billbill_for_clientA = new Client_Bill() Setting client attributes bill_for_clientA.clientName= “ClientA” bill_for_clientA.RegularRates=100 …… Calling object method for computing the billbill_for_clientA.computeClientBill ( timecardRecords )Calling object method for printing the bill bill_for_clientA.printClientBill ()END PROGRAM Prepared By: Irfan Ilyas
Benefits of OOP • Maximize Code Reusability • Pre-written class codes can be used in any program development • New classes can be derived from pre-written classes with some added functionalities [Inheritance] • Example: Car class can be used for deriving more specific car classes Toyota, Lexus, Mercedes etc. • Simplify Program Writing • Users of an object do not need to know the exact mechanism of any of the object functionalities [Encapsulation] • Easier for the programmers to change the functionality mechanism any time without asking users to change their programs Prepared By: Irfan Ilyas
…Benefits of OOP • Context driven method calls • Some methods look similar in interface and semantics but implemented differently for different objects [Polymorphism] • User doesn’t need to worry about the mechanism • Example: • print method in Client_Bill class • For two different types of client bills (clilent_printed_bill & client_onscreen_bill), the methods print does the same (semantically), however using different mechanism Prepared By: Irfan Ilyas
Introducing Visual Basic for Applications • Visual Basic for Applications (VBA) is the language for building applications with Microsoft office products • VBA is an Object Based Language (not fully object Oriented) • It doesn’t allow you to use inheritance & polymorphism features • Encapsulation feature can be used to some extent. • VBA allows to program already existing objects in different Microsoft Applications Prepared By: Irfan Ilyas
…Introducing Visual Basic for Applications • VBA code helps in integrating the use of different objects (tables, queries, forms etc.) • Produces the effect of a completely customized application Prepared By: Irfan Ilyas
An Example Microsoft Access Database Tables -tblStudent -tblCourse -tblGradesQueriesForms -frmStudentManagement -frmCourseManagement -frmStudentGrades User needs to use database objects interactively (using the command interface available in Access) A Microsoft Access Database (college.mdb) Prepared By: Irfan Ilyas
An Example Microsoft Access Application Users use all objects in an integrated fashion College.mdb Database Objects Prepared By: Irfan Ilyas
VBA in Microsoft Access Environment • Microsoft Access provides an event driven programming environment • An event is a specific action that occurs on (or with) a certain Access object. • Every object in Microsoft Access has a series of events defined. • Command Button Events • Click, DblClick, GotFocus, LostFocus, MouseMove, MouseDown, MouseUp • Form Events • Load, LostFocus, MouseDown, MouseUp, OnConnect, OnDiscount etc. • And many others Prepared By: Irfan Ilyas
Event Driven Programming • An event may come into action (initiated/ triggered) because of • a user action (clicking, pressing a key, changing data etc.) • A time value reached (timing events) • A consequence of another event • Programmers are allowed to write a series of actions (VBA code/ Macro commands) in response to any event. Prepared By: Irfan Ilyas
Mouse Click Event Happens Private Sub Command5_Click() MsgBox "Command Button Works OK" End Sub Go to the event chart of the command button • Event Chart for a command button object • Click event has a VBA Procedure attached to it. Run the procedure attached to it. Program Output An Example Event Driven Program Prepared By: Irfan Ilyas
Main components of VBA Programming • Writing Procedures • VBA statements are written in form of procedures • A procedure is a series of VBA statements • A procedure may be • attached to any objects event (event procedure) Or • written separately (without linking it to any object) • Syntax: Sub procedure_name( ) statement 1 statement 2 : : End Sub Prepared By: Irfan Ilyas
….Main components of VBA Programming • What to write in VBA Procedures? • Data declaration statements • Syntax: • Dim variable_name As data_type_in_VBA • Example: • Dim X As Integer • Calling Microsoft Access standard Procedures\ Functions (e.g. MsgBox) • Syntax: • MsgBox(prompt[, buttons] [, title] [, helpfile, context]) • Example: • MsgBox(“My First VBA Program”, vbOK, “Test Message”) Prepared By: Irfan Ilyas
….Main components of VBA Programming • ..What to write in VBA Procedures? • Using Microsoft Access objects • Setting attributes/ calling methods from Microsoft Access Objects • Syntax: • ObjectName.attribute_name = <new value> • ObjectName.method_name [arguments] • Example: • DoCmd.OpenForm frmStudents • Forms!frmStudents.Caption = “New Caption” • Me.Caption = “Changed Caption” Prepared By: Irfan Ilyas
….Main components of VBA Programming • ..What to write in VBA Procedures? • Using VBA Control Structures • Selection Structure If condition Then Statement(s) [Else Statement(s)] End If • Example: If value = 0 Then AlertLabel.ForeColor = "Red" AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True End If Prepared By: Irfan Ilyas
….Main components of VBA Programming • ..What to write in VBA Procedures? • Using VBA Control Structures • Loop Structure • Example: Prepared By: Irfan Ilyas
Generations of Programming Languages • Occurring in “generations” • Levels • Machine languages to natural languages • Lower level closer to machine language • Higher level closer to human-like language Prepared By: Irfan Ilyas
Generations of Languages • 1st -- Machine languages • 2nd -- Assembly languages • 3rd -- High level procedural languages • 4th -- Problem-Oriented Languages • 5th -- Natural Languages & Visual programming Prepared By: Irfan Ilyas