Object-Oriented Programming (OOP) Concepts: Classes, Objects, Inheritance, and Interfaces, Assignments of Programming Languages

Assignment 2 programming 1618 This ASM has( D pass )

Typology: Assignments

2020/2021

Available from 11/13/2021

flex.lowey
flex.lowey 🇻🇳

4.8

(104)

33 documents

1 / 51

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 FRONT SHEET
Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 20: Advanced Programming
Submission date Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Student ID
Class Assessor name
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature
Grading grid
P3 P4 M3 M4 D3 D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Object-Oriented Programming (OOP) Concepts: Classes, Objects, Inheritance, and Interfaces and more Assignments Programming Languages in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 20: Advanced Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Student ID

Class Assessor name

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that

making a false declaration is a form of malpractice.

Student’s signature

Grading grid

P3 P4 M3 M4 D3 D

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

  • INTRODUCTION....................................................................................................................................................................................................
    • SCENARIO............................................................................................................................................................................................................................................................
    • REPORT................................................................................................................................................................................................................................................................
  • RELATIONSHIP BETWEEN THEM........................................................................................................................................................................... EXPLANATIONS OF WHAT PROCEDURAL, OBJECT-ORIENTED AND EVENT-DRIVEN PARADIGMS ARE; THEIR CHARACTERISTICS AND THE
      1. Procedure-Oriented Programming.......................................................................................................................................................................................................
      • 1.1. What is procedure-oriented programming (POP).................................................................................................................................................................
      1. Object-Oriented Programming...............................................................................................................................................................................................................
      • 2.1. What is Object-Oriented Programming (OOP).........................................................................................................................................................................
      • 2.2. What is Object and Class in OOP?..................................................................................................................................................................................................
      • 2.3. 4 basic characteristics of OOP.........................................................................................................................................................................................................
      1. Event-driven programming...................................................................................................................................................................................................................
      • 3.1. What is Event-Driven Programming?.......................................................................................................................................................................................
      • 3.2. Characteristics of event-driven programming......................................................................................................................................................................
      1. Relatioship BEETWEN POP, OOP, EDP.............................................................................................................................................................................................
  • WRITE A PROGRAM THAT IMPLEMENTS AN ALGORITHM USING AN IDE............................................................................................................
      1. Introduction about library managerment system........................................................................................................................................................................
      • 1.1. Scenario................................................................................................................................................................................................................................................
      • 1.2. Use Case Diagram..............................................................................................................................................................................................................................
      • 1.3. Class Diagram.....................................................................................................................................................................................................................................
      1. Source code and Display of Library managerment system......................................................................................................................................................
      • 2.1. Source Code.........................................................................................................................................................................................................................................
      • 2.2. Result Student....................................................................................................................................................................................................................................
      • 2.3. Result Teacher....................................................................................................................................................................................................................................
  • EXPLAIN THE DEBUGGING PROCESS AND EXPLAIN THE DEBUGGING FACILITIES AVAILABLE IN THE IDE.............................................................
      1. What is debugging?...................................................................................................................................................................................................................................
      • 1.1. Bug?........................................................................................................................................................................................................................................................
      • 1.2. Debug?...................................................................................................................................................................................................................................................
      • 1.3. Why uses Debug?..............................................................................................................................................................................................................................
      1. Debugging facilities available in the IDE..........................................................................................................................................................................................
  • OUTLINE THE CODING STANDARD YOU HAVE USED IN YOUR CODE...................................................................................................................
      1. Coding Standard.........................................................................................................................................................................................................................................
      1. Apply coding standard in my project................................................................................................................................................................................................
  • CONCLUTION......................................................................................................................................................................................................
  • References..........................................................................................................................................................................................................
  • Figure 1: Introduction......................................................................................................................................................................................................................................... FIGURE
  • Figure 2: OOP..........................................................................................................................................................................................................................................................
  • Figure 3: Class and Object..................................................................................................................................................................................................................................
  • Figure 4: Example..................................................................................................................................................................................................................................................
  • Figure 5: Encapsulation......................................................................................................................................................................................................................................
  • Figure 6: Use Case Diagram............................................................................................................................................................................................................................
  • Figure 7: Class Diagram....................................................................................................................................................................................................................................
  • Figure 8: Debug Breakpoint............................................................................................................................................................................................................................
  • Figure 9: Step 1 debug......................................................................................................................................................................................................................................
  • Figure 10: Run project......................................................................................................................................................................................................................................
  • Figure 11: Step to debug..................................................................................................................................................................................................................................
  • Figure 12: Watch.................................................................................................................................................................................................................................................
  • Figure 13:Get values..........................................................................................................................................................................................................................................
  • Figure 14: coding standard...........................................................................................................................................................................................................................
  • Figure 15: coding standard 1.........................................................................................................................................................................................................................
  • Figure 16: Coding standard 2.........................................................................................................................................................................................................................
  • Figure 17: coding Standard 3.........................................................................................................................................................................................................................
  • Figure 18: Decorator Coding Standard.......................................................................................................................................................................................................

EXPLANATIONS OF WHAT PROCEDURAL, OBJECT-ORIENTED AND

EVENT-DRIVEN PARADIGMS ARE; THEIR CHARACTERISTICS AND THE

RELATIONSHIP BETWEEN THEM.

1. PROCEDURE-ORIENTED PROGRAMMING

1.1. What is procedure-oriented programming (POP)

POP is a common way of programming. Procedural programming is where the focus is on completing

tasks in a sequential order. Flowchart of the program's control flow organization. If the program is

extensible, it is structured in several small units called functions, which share data system-wide. Here,

concerns about data security arise, as there is an unexpected change in the program by further

developed functions.

1.2. Characteristics of POP

 While designing a program, POP follows a top-down programming approach.

 Most functions allow system-wide data to be shared.

 It also divides larger programs into smaller parts called functions.

 It allows to move data freely around the system.

 Data is converted by functions from one form to another.

1.3. Pros and Cons of POP

PROS

 Its relative simplicity, and ease of implementation of compilers and interpreters

 The ability to re-use the same code at different places in the program without copying it.

 An easier way to keep track of program flow.

 The ability to be strongly modular or structured.

 Needs only less memory.

CONS

 Data is exposed to whole program, so no security for data.

 Difficult to relate with real world objects.

 Difficult to create new data types reduces extensibility.

 Importance is given to the operation on data rather than the data.

1.4. Example of POP (C# Programming Language)

using System; namespace new { class Program { static void Main(string[] args) { Console.Write("Enter Number: "); int n = int.Parse(Console.ReadLine()); Double so = Math.Sqrt(n); if (so * so == n) { Console.WriteLine("Square numbers"); } else { Console.WriteLine("Not Square numbers"); } Console.ReadKey(); } } }

2. OBJECT-ORIENTED PROGRAMMING

2.1. What is Object-Oriented Programming (OOP)

The main concern of OOP is how to hide data from functions that are not objects of the class, that is how

it works with important data. Data is tightly bound to the functions of a class, which operate on it. It does

not allow any non-member function to modify the data within it. Objects interact with each other

through member functions to access the system's data.

OOP is developed on the basis of basic concepts of objects, classes, cryptographic or data abstraction,

inheritance, and polymorphism or overloading. In OOP, programs can be divided into modules by

partitioning data by functions, which can further be used as templates to create new copies of modules,

if needed. It is therefore an approach that facilitates the modularization of programs by building

partitioned memory for data and functions.

To make it easier to imagine, we have a real-life example of an object that is a smartphone. This object

will have:

Attributes : color, memory, operating system…

Methods : calling, taking photos, texting, recording...

- Class (Class)

Class is an abstraction of the object. Objects with similar properties are grouped into a class. The class

will also include two pieces of information: properties and methods.

An object will be treated as an instance of the class.

Continuing the example in the object section above, we have a smartphone class consisting of 2

components:

Attributes : color, memory, operating system…

Methods : calling, taking photos, texting, recording...

Objects of this class can be iPhone, Samsung, Oppo, Huawei...

Figure 4 : Example

2.3. 4 basic characteristics of OOP

ENCAPSULATION

Figure 5 : Encapsulation

Encapsulation allows hiding information and the internal processing properties of the object. Other

objects cannot directly affect the data inside and change the state of the object but must go through

public methods provided by that object.

This property helps to increase the security of the object and avoid unintentional data corruption.

EXAMPLE:

class Program { int x; public Program(int iX) { this.x = iX; } public void MySquare() { int Calc = x * x; Console.WriteLine(Calc); } static void Main(string[] args) { customer obj = new customer ( 20 ); obj. MySquare(); } }

We can see, the Intellisense only shows the father class functions but at class Child, the Child class object

is able to access both class methods.

POLYMORPHISM

Polymorphism is the ability to treat the various objects in the same manner. It is one of the significant

benefits of inheritance. We can decide the correct call at runtime based on the derived type of the base

reference. This is called late binding.

EXAMPLE:

In the following example, instead of having a separate routine for the hrDepart, itDepart and

financeDepart classes, we can write a generic algorithm that uses the base type functions. The method

LeaderName() declared in the base abstract class is redefined as per our needs in 2 different classes.

public abstract class Employee { public virtual void LeaderName() { } } public class hrDepart : Employee { public override void LeaderName() { Console.WriteLine("Mr. jone"); } } public class itDepart : Employee { public override void LeaderName() { Console.WriteLine("Mr. Tom"); } } public class financeDepart : Employee { public override void LeaderName() { Console.WriteLine("Mr. Linus"); } } class PolymorphismDemo {

static void Main(string[] args) { hrDepart obj1 = new hrDepart (); itDepart obj2 = new itDepart (); financeDepart obj3 = new financeDepart (); obj1.LeaderName(); obj2.LeaderName(); obj3.LeaderName(); Console.ReadKey(); } }

ABSTRACTION

Abstraction eliminates the unnecessary complexity of the object and focuses only on what is essential

and important.

- ABSTRACT CLASSES

C# allows both classes and functions to be declared abstract using the abstract keyword. You can't create

an instance of an abstract class. An abstract member has a signature, but no function body and they

must be overridden in any non-abstract derived class. Abstract classes exist primarily for inheritance.

Member functions, properties and indexers can be abstract. A class with one or more abstract members

must be abstract as well. Static members can't be abstract.

- EXAMPLE:

In this example, we are declaring an abstract class Employess with a method displayData() that does not

have an implementation. Then we are implementing the displayData() body in the derived class. One

point to be noted here is that we have to prefixe the abstract method with the override keyword in the

derived class.

//abstract class public abstract class Employess { //abstract method with no implementation public abstract void displayData(); } //derived class public class test : Employess { //abstract class method implementation

 An Abstract class can contain constructors and destructors, but an interface can't.

 An Abstract class contains fields, but interfaces don't.

So, the question is, which of these to choose? Select interfaces because with an interface, the derived

type still can inherit from another type and interfaces are more straightforward than abstract classes.

- EXAMPLE: // interface public interface xyz { void methodA(); void methodB(); } // interface method implementation class test : xyz { public void methodA() { Console.WriteLine("methodA"); } public void methodB() { Console.WriteLine("methodB"); } } class interfaceDemo { static void Main(string[] args) { test obj = new test (); obj.methodA(); obj.methodB(); } }

An interface can be inherited from other interfaces as in the following:

public interface xyz { void methodA(); void methodB(); }

public interface abc : xyz { void methodC(); }

3. EVENT-DRIVEN PROGRAMMING

3.1. What is Event-Driven Programming?

Event-driven programming known as a computer programming paradigm that used the occurrence of

events to determine the control flow of the program. This type of application is designed to detect

events as they occur and use an appropriate event-handling procedure to deal with it, which normally

use a callback function or method.

Theoretically, event-driven style of programming is supported in all programming languages, but they

may be different in the way of implement it, for example, it’s easier to implement in languages that

provide high-level abstractions, such as closures. Besides, for other programming environments such as

Adobe Flash, they are specifically tailored for triggering program code by events.

Generally, there is a main loop in an event-driven application that used to listen for events and triggers a

callback function when there are events is detected.

3.2. Characteristics of event-driven programming

Service Oriented

Service oriented is a key feature in event-driven programming that used to write programs that are

made for services, and it takes does not slow down the computer as service oriented only consume little

of the computer processing power and usually services run in the background of OS.

Time Driven

In event driven programming, time driven is a paradigm, it’s a code that runs on a time trigger, time

driven can be a specific code that runs on a specific time, which could be once an hour, once a week or

once a month, this means it’s a pre-set to do task. For example, windows update is the example of time

driven, which user can set when to update or when to check and download the update.

Event Handlers

Event handlers is a type of function or method that run a specific action when a specific event is

triggered. For example, it could be a button that when user click it, it will display a message, and it will

close the message when user click the button again, this is an event handler.

Console.WriteLine(String.Format("{0} notified about the GPA {1}", Name, pGPAScore.ToString())); } }

4. RELATIOSHIP BEETWEN POP, OOP, EDP

Simply speaking, the basic concept of programming is procedural only. The event driven and object-

oriented concepts just help the programmer to manage the complexity of very large programs.

Programs may often become very large and contain hundreds of thousands of lines of code. Old

programming languages like COBOL handled this complexity by allowing the creation of paragraphs or by

moving some code to external programs which can be called from a main, central or controlling program

which assigns values to those variables which will be used as parameters by the called program. The

called program would return the control to the calling program on termination and may or may not

return some values as instructed. Calling can be nested when a called program calls another sub-

program with or without parameters and may or may not receive some return value and so on.

This methodology appears simple but can become extremely frustrating and unmanageable when

program design and coding is assigned to many programmers who may be spread across several

locations e.g., Bengaluru and Silicon Valley.

Event driven programming simply uses event handlers to keep a large amount of code handy and

available for use if and when required. If there is no requirement for this code, then it just rests on the

sidelines without interfering with or cluttering the other code. Now the program is a cluster of

subprograms, each assigned to a distinct and different event of a command button, drop down list or

text box etc. The controlling program (for example, a form in Visual Basic) simply keeps track of various

events and fires the code inside the event handler set aside for that event.

Object oriented programming combines the programming capabilities of procedural and event driven

programming and goes one step further. The functions and variables of a module are kept in an object.

Objects cannot be created randomly. Each object emerges from a class. A class is a blueprint, a design or

an architecture for creating objects. A class encapsulates a lot of functions. Variables can exist in a class

or inside its functions. A function can encapsulate other functions and variables and so on. It's just like a

good doctor would prescribe a medicine that is neatly packaged in capsules rather than in a big bottle or

box.

Classes can be created from other classes. This is called inheritance. A function or a variable belonging to

one object can be given the same name as given to one belonging to another object. This is called

polymorphism.

Objects, which are created from classes interact with the main, controlling function and with other

functions, variables and objects in a disciplined, well defined and organized way.

WRITE A PROGRAM THAT IMPLEMENTS AN ALGORITHM USING AN

IDE

1. INTRODUCTION ABOUT LIBRARY MANAGERMENT SYSTEM

1.1. Scenario

SMS (School Management System) is a student management program that assists instructors in a variety

of ways, including maintaining background information, score management, learning results, conducting

training management, tracking reward and discipline, and attentive follow-up.

1.2. Use Case Diagram

Figure 6 : Use Case Diagram