Professional Documents
Culture Documents
Lưu Minh Huy GCS190572 Assignment 2
Lưu Minh Huy GCS190572 Assignment 2
Unit 1: Programming
ASSIGNMENT 2
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
P2 P3 P4 P5 M2 M3 M4 D2 D3 D4
❒ Summative Feedback: ❒ Resubmission Feedback:
Academic Year
Unit Tutor
Submission Format:
Format: The submission is in the form of an individual written report. This should be written in a
concise, formal business style using single spacing and font size 12. You are required to make
use of headings, paragraphs and subsections as appropriate, and all work must be supported
with research and referenced using the Harvard referencing system. Please also provide a
bibliography using the Harvard referencing system.
Submission Students are compulsory to submit the assignment in due date and in a way requested by
the Tutors. The form of submission will be a soft copy in PDF posted on corresponding
course of http://cms.greenwich.edu.vn/
Note: The Assignment must be your own work, and not copied by or from another student or from
books etc. If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you
must reference your sources, using the Harvard style. Make sure that you know how to reference
properly, and that understand the guidelines on plagiarism. If you do not, you definitely get fail
Assignment Brief and Guidance:
Scenario: You have applied for a post as a trainee with a software development company and have
been invited for an interview. You have been passed the presentation to demonstrate your problem
solving and basic programming skills. Now you are given a more challenge 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.
Tasks
You will discuss a suitable problem with your mentor and list the user requirements before designing,
implementing (coding) and testing a solution. You will create a report that should include:
● Introduction to your program (list of requirements and screenshots of program)
● Explain some of programming paradigms. Evaluate why and how your program use 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
organisations of using them.
The working application produced must also be demonstrated together with the presentation.
P2 Give explanations of what M2 Analyse the common features D2 Critically evaluate the source
procedural, object-oriented that a developer has access to in code of an application which
and event-driven paradigms an IDE. implements the programming
are; their characteristics and paradigms, in terms of the code
the relationship between structure and characteristics.
them.
LO3 Implement basic algorithms in code using an IDE
LO4 Determine the debugging process and explain the importance of a coding standard
P3 Write a program that M3 Use the IDE to manage the D3 Evaluate the use of an IDE
implements an algorithm development process of the for development of applications
using an IDE. program. contrasted with not using an
IDE.
P4 Explain the debugging M4 Evaluate how the debugging D4 Critically evaluate why a
process and explain the process can be used to help coding standard is necessary in
debugging facilities available develop more secure, robust a team as well as for the
in the IDE. applications. individual.
Contents
Unit 1: Programming ASSIGNMENT 2......................................................................................................................1
P2 Give explanations of what procedural, object-oriented and event-driven paradigms are; their characteristics
and the relationship between them........................................................................................................................1
1. Object-oriented programming:...................................................................................................................1
1.1. Definition:............................................................................................................................................1
1.2. Characteristics:....................................................................................................................................1
2. Procedural programming:...........................................................................................................................1
2.1. Definition:............................................................................................................................................1
2.2. Characteristics:....................................................................................................................................1
3. Event-driven programming:........................................................................................................................1
3.1. Definition:............................................................................................................................................1
3.2. Characteristics:....................................................................................................................................1
4. The relationship between procedural, object and event driven paradigms:...............................................1
P3 Write a program that implements an algorithm using an IDE............................................................................1
1. Request:......................................................................................................................................................1
2. Coding:............................................................................................................................................................1
2.1. EmployeeCheck:.......................................................................................................................................1
2.2. Employee:.................................................................................................................................................1
2.3. EmployeeFullTime:...................................................................................................................................1
2.4. EmployeePartTime:..................................................................................................................................1
2.5. EmployeeManage:....................................................................................................................................1
2.6. Application structure in Visual Studio IDE (Visual Studio tool):................................................................1
2.7. Run application:........................................................................................................................................1
P4 Explain the debugging process and explain the debugging facilities available in the IDE...................................1
1. Definition of debugging:..............................................................................................................................1
2. Debugging process:.....................................................................................................................................2
3. How to implement debug in visual Studio IDE:...........................................................................................2
P5 Outline the coding standard you have used in your code..................................................................................2
1. What is coding standard?............................................................................................................................2
2. The coding standard which I used in my code:............................................................................................2
REFERENCES............................................................................................................................................................2
ASSIGNMENT 2 ANSWERS
1. Object-oriented programming:
1.1. Definition:
Object-oriented programming (OOP) is a fundamental programming paradigm used by nearly
every developer at some point in their career. OOP is the most popular programming paradigm
and is taught as the standard way to code for most of a programmers educational career.
Today we will break down the basics of what makes a program object-oriented so that you
can start to utilize this paradigm in your own projects and interviews.
1.2. Characteristics:
Object:
- Object-oriented programming (OOP) is a computer programming model that
organizes software design around data, or objects, rather than functions and logic. An
object can be defined as a data field that has unique attributes and behavior.
- OOP focuses on the objects that developers want to manipulate rather than the logic
required to manipulate them. This approach to programming is well-suited for
programs that are large, complex and actively updated or maintained.
Page |1
Classes:
- In object-oriented programming, a class is a blueprint for
creating objects (a particular data structure), providing initial values
for state (member variables or attributes), and implementations of
behavior (member functions or methods).
Data abstraction:
- In Abstraction, by using access modifiers we can hide the required details
of the object and expose only necessary methods and properties through
the reference of an object.
Data encapsulation:
- Encapsulation is defined as the wrapping up of data under a
single unit. It is the mechanism that binds together code and the
data it manipulates. Another way to think about encapsulation is, it
is a protective shield that prevents the data from being accessed by
the code outside this shield.
Inheritance:
- Inheritance is one of the fundamental attributes of object-oriented
programming. It allows you to define a child class that reuses (inherits),
extends, or modifies the behavior of a parent class. The class whose
members are inherited is called the base class. The class that inherits the
members of the base class is called the derived class.
Polymorphism:
Polymorphism means providing an ability to take more than one
form and it's one of the main pillar concepts of object-oriented
programming, after encapsulation and inheritance. Generally,
the polymorphism is a combination of two words, one is poly and
another one is morphs.
2. Procedural programming:
2.1. Definition:
Procedural Programming may be the first programming paradigm that a new developer will
learn. Fundamentally, the procedural code is the one that directly instructs a device on how to
finish a task in logical steps. This paradigm uses a linear top-down approach and treats data and
procedures as two different entities. Based on the concept of a procedure call, Procedural
Programming divides the program into procedures, which are also known as routines or
functions, simply containing a series of steps to be carried out.
Page |2
Simply put, Procedural Programming involves writing down a list of instructions to tell the
computer what it should do step-by-step to finish the task at hand.
2.2. Characteristics:
Predefined functions: A predefined function is typically an instruction identified by a name.
Usually, the predefined functions are built into higher-level programming languages, but they
are derived from the library or the registry, rather than the program. One example of a pre-
defined function is ‘charAt()’, which searches for a character position in a string.
Local Variable: A local variable is a variable that is declared in the main structure of a
method and is limited to the local scope it is given. The local variable can only be used in the
method it is defined in, and if it were to be used outside the defined method, the code will
cease to work.
Global Variable: A global variable is a variable which is declared outside every other function
defined in the code. Due to this, global variables can be used in all functions, unlike a local
variable.
Modularity: Modularity is when two dissimilar systems have two different tasks at hand but
are grouped together to conclude a larger task first. Every group of systems then would have
its own tasks finished one after the other until all tasks are complete.
3. Event-driven programming:
3.1. Definition:
Event-driven programming is one that largely responds to user events or other similar input. The
concept of event-driven programming is an important one in application development and other kinds
of programming, and has spawned the emergence of event handlers and other resources.
Page |3
Event-driven programming is also known as an event-driven application.
3.2. Characteristics:
Event-driven development known as a computer programming paradigm which used the event of
events to look for the control move of this program. This sort of application is designed to detect
incidents as they appear, and use a proper event-handling procedure to deal with it, which normally
use a callback function or method.
Theoretically, event-driven style of programming is recognized in all programming languages,
nevertheless they may different in the form of use it, for example, it's easier to implement in dialects
that provide high-level abstractions, such as closures. Besides, for other coding environments such as
Adobe Display, they may be specifically designed for triggering program code by occasions.
Generally, there's a main loop in an event-driven application which used to pay attention for
occasions and sets off a callback function whenever there are events is diagnosed.
Page |4
P3 Write a program that implements an algorithm using an IDE.
1. Request:
Write an employee management application with the following requirements:
Declare the Employee abstract class with the following information:
There are attributes: String id, String name, String address.
Write constructors.
Write properties for properties.
Write method inputInfo : enter employee information.
Write method printInfo : output information about employee to figure.
Declare abtract method: public abstracy dobule calculateSalary.
Declare the EmployeeFullTime class inheriting from Employee with the following information:
Declare additional attributes: double basic_salary, int overtime (overtime), int typeOfPosition
(employee position type, 1: employee, 2: director, 3: manager).
Write constructors that call the constructror of the parent class.
Override the inputInfo method to enter the necessary information, this method calls the
inputInfo method from the parent class.
Override the printInfo method and call the printInfo method from the parent class.
Override the calculateSalary method again. Salary is calculated as follows: basic_salary +
allowance + overtime amount. Know that:
If the position is an employee: allowance = 200.
If the position is a manager, then: allowance = 300.
If the position is a director: allowance = 500.
Amount of overtime = overtime * 50 for all positions.
Declare the EmployeePartTime class with the following information:
Declare additional attributes: int work_hour (number of hours worked)
Write the necessary constructors and call the constructor of the superclass.
Override methods inputInfo and printInfo.
Override the calculateSalary method again. Salary for part time employees is calculated as
Page |5
follows: work_hour * 15 (every hour worked is 15 $).
Declare the EmployeeManage class with the following information:
Declare variables: List <Employee> empList.
Constructors initialize variables.
Method: addEmployee: add a new employee. Attention must be handled when adding full time
or part time employees.
Method: showEmployees: show all information about the employees to the screen.
Method: showPartimeEmployees: show all employees part time.
Method: searchEmployeeById (String id): search for employee by id.
Declaring the EmpolyeeCheck class with the main method displaying the menu as follows:
Add a new employee.
Show all employees.
Show part time employees.
Search employee by id.
Exit.
2. Coding:
2.1. EmployeeCheck:
static void Main(string[] args)
{
EmployeeManage manage = new EmployeeManage();
string option;
do
{
Console.WriteLine("\n----Employees Management System---");
Console.WriteLine("\ta. Add new employee\na. Show all
employees\n" +
"c.Show part time employees\nd. Search employee by
id\ne. Exit");
Console.Write("Please enter your option:");
option = Console.ReadLine();
switch(option)
{
case "a":
manage.AddEmployee();
break;
case "b":
manage.ShowEmployee();
Page |6
break;
case "c":
manage.ShowPartTimeEmployee();
break;
case "d":
Console.Write("Input employee id:");
string id = Console.ReadLine();
manage.SearchEmployeeById(id);
break;
case "e":
break;
default:
break;
}
} while (!option.Equals("e"));
}
2.2. Employee:
public abstract class Employee
{
protected string id;
protected string name;
protected string address;
public string Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Address
{
get { return address; }
set { address = value; }
}
public Employee()
{
}
public Employee(string id, string name, string address)
{
this.id = id;
this.name = name;
this.address = address;
Page |7
}
public virtual void InputInfo()
{
try
{
Console.Write("Input employee id:");
id = Console.ReadLine();
Console.Write("Input employee name:");
name = Console.ReadLine();
Console.Write("Input employee address:");
address = Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
public virtual void PrintInfo()
{
Console.WriteLine("\n Id:" + id);
Console.WriteLine("\n name:" + name);
Console.WriteLine("\n address:" + address);
}
public abstract double CalculateSalary();
}
2.3. EmployeeFullTime:
public class EmployeeFullTime : Employee
{
private double basicSalary { get; set; }
private int overTime { get; set; }
private double typeOfPosition { get; set; }
public EmployeeFullTime(string id, string name, string address,
double salary,
int time, int position): base (id,name, address)
{
this.basicSalary = basicSalary;
this.overTime = overTime;
this.typeOfPosition = typeOfPosition;
}
public EmployeeFullTime()
{
}
2.4. EmployeePartTime:
public class EmployeePartTime : Employee
{
private int workHour;
public int WorkHour
{
get { return workHour; }
set { workHour = value; }
}
public EmployeePartTime() : base()
{
Page |9
public EmployeePartTime(string id, string name, string address, int
hour) : base(id, name, address)
{
this.workHour = hour;
}
public override void InputInfo()
{
base.InputInfo();
try
{
Console.WriteLine("Input employee work hour: ");
workHour = int.Parse(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
public override void PrintInfo()
{
base.PrintInfo();
Console.WriteLine("Work hour: " + workHour);
Console.WriteLine("Actual wages: " + CalculateSalary());
}
public override double CalculateSalary()
{
return (workHour * 15);
}
}
2.5. EmployeeManage:
public class EmployeeManage
{
private List<Employee> empList;
public EmployeeManage()
{
empList = new List<Employee>();
}
public void AddEmployee()
{
Employee e;
Console.Write("What type of employee do you want to add?(1:
full time, 2: part time)");
int option = Int32.Parse(Console.ReadLine());
switch (option)
{
case 1:
P a g e | 10
e = new EmployeeFullTime();
e.InputInfo();
empList.Add(e);
break;
case 2:
e = new EmployeePartTime();
e.InputInfo();
break;
default:
Console.WriteLine("Please choose again!( 1: Full Time,
2: Part Time ");
break;
}
}
public void ShowEmployee()
{
foreach (Employee e in empList)
e.PrintInfo();
}
public void ShowPartTimeEmployee()
{
foreach ( Employee e in empList)
{
if(e is EmployeePartTime)
{
e.PrintInfo();
}
}
}
public void SearchEmployeeById(string id)
{
Console.WriteLine("Enter employee ID:");
var employee = empList.FindAll(e => (e.Id.Equals(id))).First();
if(empList != null)
{
employee.PrintInfo();
}
else
{
Console.WriteLine("\nNot found!\n");
}
}
}
P a g e | 11
2.6. Application structure in Visual Studio IDE (Visual Studio tool):
Step 3: Capture the program snapshot when the bug appears. Try to get all the
variable values and states of the program at that time.
Step 4: Analyse the snapshot based on the state and action. Based on that try to find
the cause of the bug.
Step 5: Fix the existing bug, but also check that any new bug does not occur.
P a g e | 14
Declare all member variables at the top of a class, with static variables at the very top.
Use the switch statement to select one of many code blocks to be executed.
P a g e | 15
P a g e | 16
REFERENCES
1. https://hackr.io/blog/procedural-programming.
2. https://brilliant.org/wiki/classes-oop/#:~:text=In%20object%2Doriented%20programming%2C
%20a,created%20using%20the%20class%20keyword.
3. https://www.tutlane.com/tutorial/csharp/csharp-abstraction .
4. https://www.geeksforgeeks.org/c-sharp-encapsulation/#:~:text=As%20in%20encapsulation%2C
%20the%20data,get%20the%20values%20of%20variables.
5. https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/inheritance#:~:text=Inheritance%20is
%20one%20of%20the,is%20called%20the%20base%20class.
6. https://www.tutlane.com/tutorial/csharp/csharp-polymorphism#:~:text=In%20c%23%2C
%20Polymorphism%20means%20providing,and%20another%20one%20is%20morphs.
7. https://www.techopedia.com/definition/7083/event-driven-program .
8. https://studybay.com/blog/event-driven-development-features/
9. https://www.multidots.com/importance-of-code-quality-and-coding-standard-in-software-
development/
10. https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour?view=vs-2019
P a g e | 17