ASM 2 1618: Programming: Computer Programming FPT University
ASM 2 1618: Programming: Computer Programming FPT University
Computer Programming
FPT University
29 pag.
Unit 1: Programming
ASSIGNMENT 2
Page | 1
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
Page | 2
Page | 3
Submission Date:
Date:
Submission Format:
Page | 4
LO2 Explain the characteristics of procedural, object-oriented and event-driven programming, conduct
an analysis of a suitable Integrated Development Environment (IDE)
LO3 Implement basic algorithms in code using an IDE
LO4 Determine the debugging process and explain the importance of a coding standard
Page | 5
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.
Case Studies
You can choose one of following case studies to implement
Page | 6
This system involves the scheduling of flights, air ticket reservations, flight cancellations, customer
support, and staff management. Daily flights updates can also be retrieved by using the system. 1.
Customers should be able to search for flights for a given date and source/destination airport.
2. Customers should be able to reserve a ticket for any scheduled flight. Customers can also build a
multi-flight itinerary.
3. Users of the system can check flight schedules, their departure time, available seats, arrival time,
and other flight details.
4. The admin of the system can add new aircrafts, flights, and flight schedules. Admin can cancel
any pre-scheduled flight (all stakeholders will be notified).
Page | 7
Page | 8
Page | 9
Page | 10
1. Procedural paradigm:
3.1. Predefined function: is a predefined function in the library of the system you are using.
Therefore, you can reuse the code in the system library
3.2 Libraries: In procedural programming, there are many libraries that contain functions and
subroutines within them. Programmers can easily use those functions by declaring them first.
3.3 Local variables: A local variable is declared within an initialized method, block or method and
it is limited to that one method. It only works within the method it's defined in, and it stops
working when it's out of the scope of that method.
3.4 Global variables: Unlike local variables, global variables are declared outside of any defined
methods, so they can be used by all functions.
3.5 Modularity:
It is a popular programming concept that involves breaking down a program into subroutines,
each of which has the necessary components to complete its work before being assembled into
an executable application program.
Page | 11
3.7 Procedures
When procedures are used, the program executes them in a top-down step-by-step manner. The
program does exactly what it is supposed to do by default.
2. Object-oriented paradigm:
Object Oriented Programming (OOP) is a programming paradigm that uses classes and objects
to organize data. It's used to break down a software program into simple, reusable code
blueprints and to make individual instances of things. Object-oriented programming languages
include Ruby, C#, PHP and Python.
Our Case class, for example, might contain a component replacement function that modifies the
attributes of the computer case. Because this function is only relevant for objects like that, we
declare it as a method in the Case class.
Classes can also include functions, which seem to be functions that are exclusively available to
objects of that kind. These functions are defined in the class and perform various important tasks
for that specific object type. Individual objects are created using class templates as a blueprint.
They are concrete representations of abstract classes such as myCase. For properties defined in
the class, each object can have its own set of values.
Let's imagine we constructed a class called computer case that contains all of the necessary
attributes for a case, such as color, brand, and case style. To represent my computer's case, we
build an instance of an object of type Case, myCase.
To describe my computer's case, we can change the values of properties defined in the class
without impacting other objects or the class template. This class can then be used to represent
any number of computer scenarios.
Page | 12
Class definitions– OOP's essential building elements and a single entity that integrates data and
data operations.
Object – instances of a class, including their variables and actions, that are employed in real-
world functioning.
Abstraction - Specifying what to do but not how to do it, a useful feature for gaining a
comprehensive understanding of an object's capabilities.
Encapsulation – a class attribute that unifies data and data operations into a single unit.
Polymorphism – Functions with the same name but different functionality, saves time by not
having to invest in a large number of function names. Operator and function overloading
Page | 13
Message Passing – a feature that allows you to transmit and receive data between objects via
function parameters.
3. Event-driven paradigm:
A main loop in an event-driven application normally listens for events and then fires a callback
function when one of them is identified. Instead of a continually running main loop, hardware
interrupts can be used in embedded systems to achieve the same result. Event-driven programs
can be developed in any programming language, although languages with a high level of
abstraction, such as await and closure, make the work easier.
Service Oriented:
It is a crucial aspect in event-driven programming that is used to design programs for services. It
does not cause the computer to slow down because service-oriented programming uses less
processing power and services are normally operated in the background of the operating system.
Time Driven:
It's a pattern, it's code that runs on a timer, and it may also be specific code that runs at a specific
time, such as once an hour, once a week, or once a month, indicating that Time Driven is already
set up to do the work.
Event Handlers:
It's a type of function or method that performs a specific action in response to a certain event.
Consider the following scenario: When a user clicks on an event handler, it displays a message or
launches a program, and when the user clicks on it again, it closes.
Page | 14
Events:
It contains the mouse, keyboard, and user interface, as well as what events in the program must
be triggered, implying that the user must interact with a program object. To "Pay respect" for a
character who died in a game, for example, double-click the mouse to open the application or
use the "F" key on the keyboard.
In OOP with EDP, all OOP principles (encapsulation, inheritance, and polymorphism) are intact.
Objects with EDP in OOP can notify events and subscribe to event notifications from other
objects.
Control flow between objects is the difference between OOP and EDP.
In OOP without EDP, control moves from one object to another when a method is called. Objects
can effectively call the methods of other objects.
On event messages, go from object to object in OOP with EDP control. An object that receives
notifications from other objects waits for notifications from those objects, some of which act on
the message, before publishing its own message.
Page | 15
1. Explain my code:
❖At first, I'll declare the product's price and serial number. These declaration lines can be seen
in the image below. Every program requires a declaration because it works as a repository for the
program's values.
After that, I added a few lines of code to allow the software to output the product's name and
price, which may also be liked to think of as a menu.
Page | 16
❖ I also use a while statement to tell customers when they entered the wrong serial number.
For example, the product I show here is 6, however if they type a number higher than 6, it will
print "This product does not exist" and then show an additional line below it that says "re-enter
here: ".
Page | 17
❖ I used an If-else expression to create a product discount. In this scenario, I believe if-else is the
best option. When the quantity of a product reaches 5, the software reduces the price for the
customer by 2/5, and if the quantity does not exceed 5, the program prints the original price. The
else statement is used to apply the If statement to a different product. To get a better
understanding, take a look at the images below.
Page | 18
2. Result:
In this part, I will divide it into 3 pictures to be able to show the different uses of the
program.
Figure 8: No discount
Page | 19
And here is the program that notifies customers when they enter the wrong serial number:
Page | 20
1. Debugging process:
1.1. Definition:
Debugging is the act of finding and removing existing defects as well as hidden bugs in software.
Hidden bugs in software frequently make the software crash. Debugging is a technique for
locating and correcting faults or problems. Debugging gets more challenging when several
subsystems or modules are tightly connected, because each change in one module can cause
more bugs to arise in another.
1.2. Description:
To debug a software, the user must first identify the problem, extract the code, and then correct
it. At various stages of development, debugging tools are used to uncover coding mistakes.
They're used to recreate the error's circumstances, then evaluate the program's state at the
moment to figure out what went wrong. A debugger is included in certain programming language
packs to test the errors while the code is being created at run time.
Page | 21
❖ Code editor: GDB is the IDE debugger's primary debugging tool. Each GUI action is translated
into a series of GDB commands, which are then processed to keep track of the debugged
program's current state.
❖ Code highlighting: When an IDE discovers a syntax error, it will typically assist you by
highlighting the code portion where the error was found.
❖ Breakpoints: An IDE breakpoint is a handy tool for pausing a program at a specific line of code
to examine the value of variables.
❖ Step over: You may need to run the line of code after the debugger reaches the breakpoint.
The command "Step Over" is used to run the code.
❖ Simply Inspect Variables: In a data tip, you can see the current value of a variable by hovering
over it.
❖ Step into: Step Over is a similar game. The only difference is that the debugger will travel into
the method if the current highlighted part contains a method call. Step's shortcut key
❖ Step out: This has something to do with debugging within a method. If you press Shift + F11
while in the middle of a method, the execution will finish the method and pause at the next
sentence from where it was called.
❖ Run to cursor: To place the cursor on a line of executable code, run to the cursor point in the
source window. This is akin to setting a temporary breakpoint.
❖ Inspect Variables:
+ Variables specified in the local scope are displayed in the Locals pane.
+ The Autos window shows the variables that have been utilized in the current line.
+ During a debugging session, we can utilize Watch and QuickWatch to see variables and
expressions.
Page | 22
1. Rule of brackets:
Page | 23
+As you can see in Figure 12, I've moved back to a tab so that it's easier to see the relationship
between the command lines.
+In Figure 13, I created a space between the "Add Student Grade" and "Add Student ID" sections,
which separates the two lines of code mainly to help programmers easily identify them.
Page | 24
You can see green text on my lines, which are also relatively important for large projects. It is
used to explain the purpose of lines of code, so that other programmers working on that
project will know what the code does.
Page | 25
namespace ConsoleApp_ASM_1
{
class program
{
static void Main(string[] args)
{
//declare the cost for product
double a1 = 10000;
double b2 = 20000;
double c3 = 30000;
double d4 = 40000;
double e5 = 50000;
double f6 = 60000;
//create menu
Console.WriteLine("Welcome to The God Damn Store");
Console.WriteLine("========================== #
==========================");
Console.WriteLine("1. God Damn Gun ($10000)");
Console.WriteLine("2. God Damn Sword ($20000)");
Console.WriteLine("3. God Damn Bomb ($30000)");
Console.WriteLine("4. God Damn Pet ($40000)");
Console.WriteLine("5. God Damn Helmet ($50000)");
Console.WriteLine("6. God Damn Suit ($60000)");
Console.WriteLine("========================== GOD DAMN
==========================");
//error line
while (product > 6)
{
Console.WriteLine("This product doesn't exist");
Console.WriteLine("re-enter here: ");
product = Convert.ToDouble(Console.ReadLine());
}
Page | 26
Page | 27
7. mok (2014). What is the relation of “Event Driven” and “Object Oriented”
programming? [online] Stack Overflow. Available at:
https://stackoverflow.com/questions/22101731/what-is-the-relation-of-event-driven-
and-object-oriented-programming.
9. CodeLearn (n.d.). Coding Standards Và Cách Viết Code C++ Chuẩn Đẹp. [online]
codelearn.io. Available at: https://codelearn.io/sharing/coding-standards-va-cach-viet-
code-cpp?fbclid=IwAR03A5oGlEedwVTyf5SfEa1FY2r4rKItL62jyuvhdVjFUA6G5iT1sCZ3lfE
[Accessed 6 Mar. 2022].
Page | 28
Page | 29