Docsity

Assignment 2 programming 1618 ( D pass ), Assignments of Programming Languages

Toggle sidebar
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
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Assignment 2 programming 1618 ( D pass ) 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 1 ST

SUBMISSION

RE-SUBMISSION DATE

DATE RECEIVED 2 ND

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

Figure 1 : Introduction

SCENARIO

I'm have applied for a post as a trainee with a software development company and have been invited for

an interview. I'm have been passed the presentation to demonstrate my problem solving and basic

programming skills. Now I’m given a more challenging task to create a fully working, secure application

that has been developed using an IDE and adheres to coding standards for a detailed business problem.

REPORT

I will discuss a suitable problem with my mentor and list the user requirements before designing,

implementing (coding) and testing a solution. I will create a report that should include:

 Introduction to your program (list of requirements and screenshots of the program)

 Explain some of the programming paradigms. Evaluate why and how your program uses these (or

some of) paradigms.

 Explain the common features of an IDE should have and evidence of how the IDE was used to

manage the development of your code.

 An evaluation of developing applications using an IDE versus developing an application without

using an IDE.

 An explanation and evaluation of the debugging process in the IDE used and how it helped with

development.

 An explanation and evaluation of coding standards used in your program and the benefits to

organizations of using them.

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.

Figure 2 : OOP

2.2. What is Object and Class in OOP?

Figure 3 : Class and Object

- Object (Object)

Objects in OOP consist of 2 main components:

Attributes: are the information and characteristics of the object

Methods : are the behaviors that the object can perform

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

Within an object, code, data or both may be private or public to that object. Private code is known to

and accessible only by another part of the object, that is private code or data may not be accessible by a

piece of the program that exists outside the object. When the code and data is public, other portions of

your program may access it even though it is defined within an object.

INHERITANCE

This is a feature that is used quite a lot. Inheritance allows building a new class (Child class), inheriting

and reusing properties and methods based on the old class (Parent class) that existed before.

Child classes inherit all the members of the Parent class and do not need to be redefined. Subclasses can

extend inherited components or add new ones.

EXAMPLE:

//Base Class public class Father { public void FatherMethod() { Console.WriteLine("this property belong to Father"); } } //Derived class public class Child : Father { public void ChildMethod() { Console.WriteLine("this property belong to Child"); } } class Inheritance { //Entry point static void Main(string[] args) { Father fObj = new Father (); fObj.FatherMethod(); //Here Child object can access both class methods Child cObj = new Child (); cObj.FatherMethod(); cObj.ChildMethod(); } }

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 {

public override void displayData() { Console.WriteLine("Abstract class method"); } } class abstractClass { static void Main(string[] args) { // class instance new test ().displayData(); } }

- SEALED CLASSES

Sealed classes are the reverse of abstract classes. While abstract classes are inherited and are refined in

the derived class, sealed classes cannot be inherited. You can create an instance of a sealed class. A

sealed class is used to prevent further refinement through inheritance.

- EXAMPLE:

Suppose you are a developer of a class library and some of the classes in the class library are extensible

but other classes are not extensible so in that case those classes are marked as sealed.

sealed class SealedClass { void myfunv(); } public class test : SealedClass //wrong. will give compilation error { }

- INTERFACE

An interface is a set of related functions that must be implemented in a derived class. Members of an

interface are implicitly public and abstract. Interfaces are like abstract classes. First, both types must be

inherited; second, you cannot create an instance of either. Although there are several differences as in

the following.

 An Abstract class can contain some implementations, but an interface can't.

 An Interface can only inherit other interfaces, but abstract classes can inherit from other classes

and interfaces.

 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(); }

Trigger Functions

Trigger functions in event-driven programming are a function that decide what code to run when there

are a specific event occurs, which are used to select which event handler to use for the event when there

is specific event occurred.

Events

Events include mouse, keyboard, and user interface, which events need to be triggered in the program in

order to happen, that mean user have to interacts with an object in the program, for example, click a

button by a mouse, use keyboard to select a button and etc.

EXAMPLE:

static void Main(string[] args) { Student oStudent = new Student(); oStudent.Name = "James"; oStudent.GPAScore = 80; Parent oParent = new Parent(); oParent.Name = "Daddy Cool"; oStudent.NotifyToParent += new NotifyGpaDelegate(oParent.NotifyMe); oStudent.RecordGPAScore(); } } public delegate void NotifyGpaDelegate(int GPAScore); class Student { public event NotifyGpaDelegate NotifyToParent; public String Name { get; set; } public int GPAScore { get; set; } public void RecordGPAScore() { if (NotifyToParent != null) NotifyToParent(GPAScore); } } class Parent { public String Name { get; set; } public void NotifyMe(int pGPAScore) {

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.