Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Mapúa University
School of Electrical, Electronics and Computer
Engineering
Pre-Laboratory
Readings, Insights, and Reflection Python:
Fundamentals of Python Programming by Kenneth Lambert
(Chapter 9)
Core Python Programming by Negeswara Rao (Chapter 5)
Git:
Professional Git by Brent Laster Connected Lab 2
UML:
UML 2 Toolkit by Hans-Erik Eriksson (Chapter 5)
Dennis (9781119030263): Chap 5
Fundamentals of Python Programming by Kenneth Lambert Chapter 9 Insights
and Reflection
Insights
In the book Fundamentals of Python First Programs in chapter 9. We see how programmers use
objects and classes and how they are initiated. We will also use OOP or object oriented programming
as we will use pre written classes and at the same time we will make classes.
It is also discuss in the book the use of the two dimensional grid which includes basic types of data
structures from pythons like strings, lists, and tuples.
Also, it is shown how to implement and design your own abstraction mechanism, we will be using a
style of programming called “Object Oriented Programming” since we will be the one to create new
classes of objects, unlike in Object-Based Programming, we are only using codes that are ready
made.
Next, docstrings can occur at three different levels. The first level is located at the module, Second
level is located after the class header and lastly, the third level is located after each method header.
Lastly, the book discusses structuring classes with Inheritance and Polymorphism. With the use of
data encapsulation which manipulates the object's state to a set of method calls, inheritance which
allows class to be recuse to extend the code of the class, and lastly polymorphism which allows
multiple classes to use with the regard of using the same general method name.
Reflections
In this lesson I have learned that you can use simple class definitions to define a certain element.
Which can be separated and defined from each other. An object or class may have its own memory
of data space. It also allows the user of the class to provide initial values for the variables. The
method discussed that it contains a header and a body that makes a parameter or boundary on a
particular object. Some standard can be overloaded and use with the new classes in the program.
Once the program no longer references an object the program is already dead or unfunctional.
Moreover, the parameter self is always included in each method definition. This is used to refer to
the objects by name. You can directly call the specific element from the list by including the
parameter self.
Kenneth Lambert's Exercises
Exercise 1 Page 346
What are the benefits of having class B extend or inherit from class A?
To minimize the duplicated or multiple identical common code in several classes. It can count for not
rewriting codes as it can be reusable. Inheritance can also make application code more flexible to
change because classes that inherit from a common class can be used interchangeably. If the return
type of a method is class.
Exercise 2 Page 346
Describe what the __init__ method should do in a class that extends another class.
The method used for this is called Inheritance hierarchies. It provides an abstraction mechanism that
reduces the programmer to avoid writing redundant codes by simply reusing it. Moreover, the
subclass extends from its parents class by modifying the same methods.
Exercise 3 Page 346
Class B extends class A. Class B defines an __str__ method that returns the string
representation of its instance variables. Class B defines a single instance variable named age,
which is an integer, Write the code to define the __str__ method for class B. This method
should return the combines string information from both classes. Label the data for age with
the string "Age: "
Core Python Programming by Negeswara Rao Chapter 5 Insights and Reflection
Insights
Discussed on the first part of chapter 5 are the output statements. This part heavily focuses on the use
of print statements. Print statements is simply outputs any value that a user chooses. It is the
counterpart of cout() in C++ and console.log() in Javascript. Print statements does not only output
simple strings but also all kinds of data types like integer and booleans. Furthermore, print
statements can also print objects like lists, dictionaries and tuples.
Next are input statements, from what I already know, input functions are used to get values from a
user and then store it to a certain variable. As default, inputs from users are in type string unless
specified by the user. For example, my input is 89, by default, 89 will be stored as a string('89')
unless I put an int function to cover the input statement. Aside from integers and string, input
function also accepts list from the user.
From the readings, an eval() function is introduced. An eval() function takes a string and evaluates
the result of the string by taking it as a python expression. Eval function can be very helpful since it
allows user to input a whole expression.
Lastly are command line arguments. Command line arguments are the values passed to the program
from outside the program. These are values that user enters or inputs. For example, my program
requires the user to input a certain number in order for that number to be processed to whatever I
want to do. The command line arguments in the example are the numbers the I want the user to
input. These arguments are stored in in the form of strings in a list with the name 'argv'. In order to
know how many arguments there are, len(argv) function is used, len simply stands for length.
Reflections
Based from the readings in chapter 5, I can say that it is good to refresh the mind on the simple
topics like the print statement and input statement. It is vital for a programmer to always re-learn and
refresh the basics of programming. From there, I want to point out 2 things that I've learned outside
from what I already know. First is the eval() function. Eval function allows the user to input an
expression and solve it as a regular 1. Second is the command line arguments. The command line
argument simply tells us that the input form the users are in default stored in sys module as a string
waiting to be processed depending on what other functions are given. It is good to know that we
know how the language work from the inside, it is vital since we want to be able to utilize its full
capacity in order to make better programs.
Professional Git by Brent Laster Connected Lab 2 Insights and Reflections
Insights
For objective of Connected Lab 2 is for us to be able to create our own Git repository on our own
local disk. The first step is to create a directory on which we will put all the files the is going to be
uploaded in GitHub. In my case, I want to put my repository in git_workplace directory.
Now in we need to configure the settings and tell git our name and email address. Since I already
have one, I'll just show my config file.
If we want to see what files in our local drive are not yet uploaded in our GitHub account, the
command is git status.
From there we can see that file.txt is untracked meaning that it is not yet in my GitHub account.
Now if I want to add file.txt to my repository in github, the command is git add <file>.
From there we can see that file.txt is now ready to be committed. To commit in git, the syntax is git
commit -m "comment string".
Now if we want to edit a file to our current file the syntax is echo more >> <filename>. From the
example below, we can see that I added more text in file.txt using the syntax given above.
From there I just used the commit command to update what I edited in file.text. To skip the add
command we can just add a to the commit command.
Reflections
Comparing the things that I've learned and the things that I already knew, I can say that this book
really helped me to understand and be familiarized by the basic command in making my own local
repository in git. The readings also helped on understanding how I can add and commit files from
my local repository directly to my GitHub account. Furthermore, I've also learned how I can easily
modify or change the file that is in my repository using echo more. Overall, I found the book to be
very substantial to any beginner.
UML 2 Toolkit by Hans-Erik Eriksson Chapter 4 Insights and Reflections
Insights
UML is flexible to use since it supports static, dynamic and functional modeling. With this, you can
also create Class Diagrams which consists of classes and relationships. The following relationships
are namely: Association, Generalization, Dependencies and Abstractions.
The first part of the chapter showed us the difference between Classes and Objects and what is their
relationship to each other. Object was described as the representation of something that exists in the
real world, while Classes is used to classify the objects, this is the representation of elements with
common characteristics. Both of these are used to describe the elements in the system. With the use
of an UML (Unified Modeling Language), creating a system that can be more efficient since it gives
a course of action for the designer to show how to build and refine systems. Moreover, whether it
may be a business or a machine type of system, as long as it is an object-oriented model, using UML
can still be reliable and will still be easy for the models to understand the system.
Reflections
Based from the readings, I have learned the different types of relationships that can be used in class
diagrams. Class Diagram is used for modeling the system of application and for translating the
model into a programming code. Furthermore, Class is often divided into three compartments
namely: The Name Compartment – which contains the name of the class, and should be capitalized
and centered in Bold face. Next, The Attributes Compartment – which defines the features of an
object, an example of this is weight, color and length. Moreover, attributes can have different
visibility, which can be chosen between private and public. Lastly, The Operations Component, this
manipulates the attributes and operations.
Sytems Analysis and Design: An Object-Oriented Approach with UML by Allan
Dennis Chapter 5: Structural Modeling
Insights
In Chapter 5, it elaborates the use of CRC or class-responsibility-collaboration) which are presented
as class diagrams and objects diagrams that are used for making structural models. Structural models
who's the possible outcomes of the proposed projects.
Reflections
Structural modelling is very useful for making and visualizing how you want your project's outcome
to be finished. It shows your step by step process in creating your product from the start till the end.
CRC Cards also help as your documentation to keep track of your progress.
We learn also that there is 3 basic categories of data abstraction first generalization relationships,
second aggregation relationships, and third association relationships.
First is generalization relationship this data abstraction helps to create classes that inherits attributes
and operations.
Second is aggregation relationship this data abstraction helps in to relate parts or to relate different
classes and there relate their relationship.
Lastly is association relationship which helps to see classes that don’t fit neatly or a weak form of
aggregation.
In-Laboratory
Saturday, February 29, 2020 9:21 PM
In-Laboratory
Note: Leaders should assign the problems to members
• Objectives (you can have your own objectives)
• Steps Performed with screenshots of tools used (UMLet and VSCode), debugging, sample run
with DISCUSSION (Don’t copy and paste from ebook). Use the source of Lambert. Given the
source code (with classes), create the corresponding class diagram using UMLET
• IMPORTANT: Figure numbers and labels.
Objectives
The next thing that we need to learn are the instance attributes. Since we are delaing with
objects, we must understand that objects has different characteristics just like name, age, and
student numberes of students.
By using an __init__ () method, we can initialize these attributes or characteristics. The init
method is also called a constructor which gets invoked when an object is instantiated. The
example below shows the initialization of the name, number, and score of class Student:
Next are the methods. Methods are just similar to functions except they are inside a class and
are used to perform operations using the attributes of the object. Below are some of the
methods used in the student.py in Lambert's source codes.
Figure 2.1: Aggregation
Composition relationship is created when one of the classes is composed of one or more
instances of other classes. In other words, one of the classes plays a role of a container and
other place the role of a content and if the other container object is deleted then all of its content
objects are deleted as well. For example, you can think of human which has different body
parts, a human can live without body parts, whereas body parts cannot exist alone. So when a
human dies, all body parts die as well. Composition means that a relationship cannot stand
alone. Once you delete a subject your other subject will not exist.
Post-Laboratory
Note: Leaders should assign the problems to members
• Machine Problems Lambert: Chapter 9 projects page 349
• Debugging and Sample Run (with screengrabs and Projects 4, 5 and 6
discussion
• UMLET class diagram
Note:
1. Save all files (.py and .uxf) in one folder, upload the
folder to your OneDrive and put a tiny/bitly url in your
OneNote
Name the Folder: <Course and
Section>_Group#_Exp#.
Example: CPE106L-B1_Group01_Expt2
2. Commit all python source codes to Github (individual
Github account) Github Repository Name: Software
Design Lab Exercises
Put a tiny/bitly url of your Github repository
The ATM program allows a user an indefinite number of attempts to log in. Fix the program so
that it displays a popup message that the police will be called after a user had these successive
failures. The program should double the login button when this happens.
Figure 1.1. Sample output successful login
Based from Figure 1.1, it can be seen that the user has entered the correct credentials, thus the
user was able to access the savings account.
As shown from Figure 1.2, the user has entered the wrong credentials. Therefore, the status
shows that the name and pin is not found and the login button was also disabled.
As noticed from Figure 2.1, the program requires the user to respond to the question, as the user
answered the following question, the program will repeat the response of the user with a
different pronoun. This was created with the use of replacements, in which certain pronounced
are automatically changed when the user responds.
Since we need to randomly generate a value for the die, the random library was used. The Die
class simply represents a six sided die.
For the craps.py, the first thing we did was to debug the RollDice method in order for the count
of dice rolls to be initiated and for it to add 1 per round. The rollDice function also determines
the winner of the round by comparing the sum of 2 dices rolled for each player. On the other
hand, for the getRollsCount method, we simply made it return the number of dice that was
rolled.
For the playOneGame method, it simply allows user to play a single game and returns the
winner of that game. The playManyGames method on the other hand allows user to play many
games and return a statistics like the total number of games played, total number of wins, total
number of losses, average number of rolls per win and the average number of rolls per loss.
Link for OneDrive files