Assignment 1 - Advanced Programming - PASS, Assignments of Computer Science

Assignment 1 - Advanced Programming - PASS

Typology: Assignments

2021/2022

Uploaded on 11/08/2022

minh-huy-huynh
minh-huy-huynh 🇻🇳

4.7

(58)

39 documents

1 / 42

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 20: Advanced Programming
Submission date
14/10/2022
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Huynh Minh Huy
Student ID
GCD210173
Class
GCD1001
Assessor name
Pham Thanh Son
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
Huy
Grading grid
P1
P2
M1
M2
D1
D2
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

Partial preview of the text

Download Assignment 1 - Advanced Programming - PASS and more Assignments Computer Science in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date 14/10/2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Huynh Minh Huy Student ID GCD Class GCD1001^ Assessor name Pham Thanh Son 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 Huy

Grading grid P1 P2 M1 M2 D1 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

  • CHAPTER 1: INTRODUCTION.
  • CHAPTER 2: OOP GENERAL CONCEPTS.
    • I. Object – Oriented Programming.
        1. What is Object – Oriented Programming?
        1. The benefits of Object – Oriented Programming.
        1. Criticism of Object – Oriented Programming.
    • II. General concepts of Object – Oriented Programming.
        1. Class.
        1. Object.
        1. Methods.
        1. Constructor.
    • III. Characteristics of Object – Oriented Programming.
        1. Encapsulation.
        • a. What is Encapsulation.
        • b. Access Modifier.
        • c. Properties.
        • d. OOP Scenario for access modifier.
          • i. Private Access Modifier............................................................................................................................
          • ii. Public Access Modifier..............................................................................................................................
          • iii. Protected Access Modifier.
        • e. OOP Scenario for Encapsulation.
        1. Inheritance.............................................................................................................................................................
      • a. What is Inheritance?
      • b. OOP Scenario.
      • c. Class Diagram.
      • d. Code Example.
      1. Polymorphism.
      • a. What is Polymorphism?
      • b. Overriding method.
      • c. Overloading method.
      • d. OOP Scenario.
      • e. Class Diagram.
      • f. Code Example.
      1. Abstraction.
      • a. What is Abstraction........................................................................................................................................
      • b. Abstract Method.
      • c. Abstract Class.
      • d. Interfaces.
      • e. OOP Scenario.
      • f. Class Diagram.
      • g. Code Example.
  • IV. Relationship between classes.........................................................................................................................
      1. Introduction.
      1. Types of relationships in Object – Oriented Programming (OOP).
      • a. Association.
      • i. Unary Association.
      • ii. Binary Association.
    • b. Aggregation.
    • c. Composition.
    • d. Generalization.
  • References
  • Figure 1: Object-Oriented Programming. Table of Figures
  • Figure 2: Example of Structure of OOP...........................................................................................................................
  • Figure 6: Class Diagram for Inheritance.
  • Figure 7: Inheritance Code Example.
  • Figure 8: Result......................................................................................................................................................................
  • Figure 9: Class Diagram for Polymorphism................................................................................................................
  • Figure 10: Polymorphism Code Example.
  • Figure 11: Result.
  • Figure 12: Class Diagram for Abstraction.
  • Figure 13: Class Diagram for Interface.
  • Figure 14: Abstraction Code Example.
  • Figure 15: Result.
  • Figure 16: Interface Code Example................................................................................................................................
  • Figure 17: Result.
  • Figure 18: Association.
  • Figure 19:Association Class Diagram.
  • Figure 20: Association Code Example.
  • Figure 21: Result.
  • Figure 22: Class Diagram for Unary Association.
  • Figure 23: Unary association Code Example..............................................................................................................
  • Figure 24: Result.
  • Figure 25: Class Diagram for Binary Association.
  • Figure 26: Binary Association Code Example.
  • Figure 27: Result.
  • Figure 28: Aggregation.
  • Figure 29: Aggregation Class Diagram.
  • Figure 30: Aggregation Code Example.
  • Figure 31: Aggregation Code Example Result.
  • Figure 32: Composition.
  • Figure 33: Composition Class Diagram.
  • Figure 34: Composition Code Example.
  • Figure 35: Result.
  • Figure 36: Inheritance.
  • Figure 37: Generalization Class Diagram.
  • Figure 38: Inheritance Code Example.
  • Figure 39: Inheritance Code Example Result.............................................................................................................

CHAPTER 1: INTRODUCTION.

I need to apply Object oriented research and design to a specific example to define the attributes of the Object-oriented programming paradigm. Although the situation is not grave, some OOP characteristics should be addressed. The second purpose is to convey to the audience certain design trends by utilizing actual case situations and corresponding trends depicted with UML class diagrams. I will cover object-oriented programming aspects like as encapsulation, inheritance, polymorphism, and so on, as well as other class interactions, in this assignment. After that, I'll draw a class diagram based on a specific code scenario. CHAPTER 2: OOP GENERAL CONCEPTS. I. Object – Oriented Programming.

  1. What is Object – Oriented Programming? The Object – Oriented Programming paradigm (OOP) organizes software architecture around data rather than functions and logic. An object is a sort of data field with distinct characteristics and behavior. OOP focuses on the objects that developers want to work with rather than the logic required to do so. This programming technique is appropriate for large, complex projects that must be updated or maintained on a regular basis. This includes industrial and design software, as well as mobile applications; for example, OOP might be used to construct simulation software for production systems. (Gillis, n.d.) Figure 1 : Object-Oriented Programming.

Imperative programming: This OOP alternative, which includes C++ and Java, focuses on functions rather than models.  Declarative programming: This programming style includes statements describing the job or intended outcome but not how to do it. Prolog and Lisp are two programming languages.  Logical programming: This strategy, which is primarily based on formal logic and employs programming languages such as Prolog, consists of a series of sentences that define facts or rules about a problem area. It focuses on problems where rule-based logical inquiries might help. II. General concepts of Object – Oriented Programming. Figure 2 : Example of Structure of OOP.

  1. Class. A class is an object's model, blueprint, or prototype that defines or specifies all of the object's characteristics. In general, a class declaration begins with the term class and ends with the class's identifier. However, certain optional properties can be used with class definition based on the application requirements. These components can be seen in class declarations in general.

Modifiers: For example, a class can be public or private. Internal is the class's default modifier.  Class keyword: The class keyword is used to specify the kind of class.  Class Identifier: A class variable is provided as the class identifier. By convention, the identifier (or class name) should begin with an initial letter that is capitalized.  Base class or Super class: If applicable, the name of the class's parent (superclass), preceded by the: (colon). This is completely optional.  Interfaces: A list of any interfaces implemented by the class, separated by commas, followed by: (colon). A class can implement a large number of interfaces. This is completely optional.  Body: The class's body is surrounded by (curly braces).

  1. Object. An object is a type of entity or instance of a class. Objects are often physical things, but they may also be mental beings. Every object has a state as well as a set of behaviors. Objects are the basic building blocks of a C# OOP program. Data and methods make form an object. The data and methods of an object are referred to as its members. The objects are made with OOP software Methods allow these items to communicate with one another. Each object may receive messages, send messages, and process data. A class declaration often consists of merely the term class, followed by the class's identifier (name). However, depending on the application requirements, there are certain optional properties that can be utilized with class definition. In general, class declarations can have the following components in the following order:  State: The features of an object describe its state. It also reflects an object's characteristics.  Behavior: The methods of an object express behavior. It also illustrates the interaction of a thing with other objects.

 In constructor declarations, access modifiers can be used to limit who else can invoke the constructor. III. Characteristics of Object – Oriented Programming.

  1. Encapsulation. a. What is Encapsulation. According to this technique, an object contains all important information and just a portion of it is accessible. Within a given class, the implementation and state of each object are kept private. Other objects have no access to or authority over this class. They can only invoke a limited selection of public functions or methods. This data masking capability increases program security and prevents data destruction inadvertently. b. Access Modifier. C# access modifiers, also known as specifiers, are keywords that are used in C# applications to indicate the accessibility or scope of variables and functions.  Public: The code is available to all classes.  Private: The code can only be accessed inside the same class.  Protected: The code is available within the same class or in a class derived from it. In a subsequent chapter, you will learn more about inheritance.  Internal: The code is only available from within its own assembly, not from another. This will be covered in greater detail in a later chapter.  Protected Internal: It states that access to the current assembly or inherited types from the contained class is limited.

c. Properties. A property is a sort of class member that allows you to read, write, or compute the value of a private field in a variety of ways. Properties can be used in the same manner as public data members can, although they are accessors rather than members. This improves process flexibility and safety while also simplifying data availability. Data may also be encapsulated and concealed using properties. It uses pre-defined methods such as "get" and "set" to access and update properties.  Read and Write Properties: A property is considered to be read and write if it has both get and set methods.  Read-Only Properties: A property is considered to be read-only if it only has the get method.  Write Only Properties: A property is considered to be write only if it only includes the set method.  Auto Implemented Properties: Auto Implemented Properties: Introduced in C# 3.0 when the property accessors do not require any further logic. d. OOP Scenario for access modifier. i. Private Access Modifier. When you declare a field with the private access modifier, it can only be accessed inside the same class.  Class Diagram.

iii. Protected Access Modifier. The code is available within the same class or a class derived from that class. In this access modifier I have created 2 table which is School and Student. The name protected field is only accessible to the School and The Inherited classes. The function, however, cannot be accessible through the inherited class.  Class Diagram.Code Example.Result.

e. OOP Scenario for Encapsulation. As a result, we have several attributes set to private, such as name and age. The problem is that if we call for the properties in the Main program, the program will not be performed since the properties are private and can only be utilized within the class that contains them. Instead of utilizing the original properties, we will create constructors and methods to retrieve the data from the keyboard and place it into the new variables.  Class Diagram.Code Example.Result.

d. Code Example. Figure 4 : Inheritance Code Example. In this case, we can see that the sub-class Dog inherits all of the super-class Animal's properties and methods, including the property of name and the method of eat. The method that the sub-class inherits, on the other hand, will be fixed and cannot be modified while the code is being executed. The actions will be the same as in the super-class. Figure 5 : Result.

  1. Polymorphism. a. What is Polymorphism? Objects are intended to share behaviour and can take on several forms. The software will identify which meaning or usage is required for each execution of that object from a parent class, which reduces the requirement for duplicating code. The parent class's functionality is then extended by creating a child class. Polymorphism enables several sorts of objects to flow via the same interface. b. Overriding method. Method overriding implies that the code has two or more methods with the same name, but each one performs a distinct function that is distinct from the others. Taking the phrase literally, this means that one strategy must take precedence over another. This concept relates to redefining a base class method with the same method signature in a derived class. Overriding is a feature that enables a subclass or child class to provide a modified implementation of a method provided by one of its parent or super- classes. A method in a subclass is said to override a method in its superclass if it has the same name, parameters or signature, and return type (or sub-type) as the method in the superclass. c. Overloading method. Polymorphism is commonly implemented by method overloading. It is the capacity to redefine a function in several ways. Function overloading may be implemented by declaring two or more functions in the same class with the same name. C# may differentiate between methods by using various method signatures. Within the same class, methods can have the same name but distinct parameter lists (i.e. the number of parameters, order of the parameters, and data types of the parameters).