Module 2 - Using Apps and Databases
Module 2 - Using Apps and Databases
The following CompTIA ITF+ domain objectives and examples are covered in
this module:
Page 108
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1 Using Data Types and Units
Objectives
On completion of this unit, you will be able to:
□ Recognize and use different notational systems, data types, and units of
measure.
□ Discuss the importance of data and ways that a company can use it to
make business decisions.
□ 1.2 Compare and contrast fundamental data types and their characteristics.
Char • Strings • Numbers (Integers, Floats) • Boolean
Page 109
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1
Notational Systems
Decimal Notation
For most people around the world, when they want to count something, they
use a numbering system based on decimal. The decimal system (or base 10)
is so well understood, it’s actually quite easy to overlook how it actually works.
Decimal is based on the principle of expressing ten different numbers using a
single digit in the range 0 to 9. Once you have a value of more than ten, then
you require two digits of decimal to express it. Thus, when twelve is expressed
numerically in decimal as 12 that means 1*10 plus 2*1.
1000 100 10 1
0 0 1 2
1000*0 100*0 10*1 1*2
0 + 0 + 10 + 2
= 12
You will notice that the rightmost column is worth one, while the second
column is worth ten times that (10). The third column is worth ten times the
second column (100), and so on. In other words, each digit as we move from
right to left (from least to most significant) is worth the base number (ten) times
more than the preceding digit. This is referred to as place value.
Binary Notation
While people find decimal easy to use, computers use binary to calculate and
process information. Binary is a numbering system where each single digit can
express only two values, in the range 0 to 1. The reason binary works well with
computers is that these two values can represent the off/on states of the
transistors that make up computer memory. Binary can also be referred to as
base 2.
As with decimal, to express a value of more than one, you must use multiple
binary digits in a place value system. For example, the number 51 in decimal
can be expressed in binary as 110011. As with decimal, when you write the
number down, and assign the digit values, you can see that each column is
worth the base number (two) times more than the preceding column as we
move from least to most significant (right to left). Thus, the second column is
worth twice the first, the third column is two times the second, and so on.
Page 110
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
128 64 32 16 8 4 2 1 Using Data Types and Units
0 0 1 1 0 0 1 1
128*0 64*0 32*1 16*1 8*0 4*0 2*1 1*1
0 + 0 + 32 + 16 + 0 + 0 + 2 + 1
= 51
Hexadecimal Notation
When handling large values, expressing them in binary can consume many
digits. For example, 1234 in decimal uses four digits, whereas the same
number in binary is 100 1101 0010, which requires 11 digits. You can
express large numbers more efficiently by using hexadecimal, often shortened
to "hex." The hex notation system enables you to express 16 different numbers
using a single digit in the range 0 to F. For example, the number 1234 (in
decimal) can be expressed in hex as 4D2, using one fewer digit. In this
notation, the letters A through F are used to express numbers larger than nine
(which require two digits of decimal to express). Thus, A is 10, B is 11, C is 12,
D is 13, E is 14 and F is 15.
4096 256 16 1
0 4 D 2
4096*0 256*4 16*13 1*2
0 + 1024 + 208 + 2
= 1234
Hex is used in programming. You will also encounter this numbering system
when you plan and implement Internet Protocol (IP) networks. IPv6 network
and host addresses are expressed using a hexadecimal notation system.
Conversion
If you are going to get involved in computing, it’s worth the effort of learning
how to convert numbers from binary to decimal and back. You can do so
manually using the place value columns shown above. You can also use a
programming calculator to achieve this conversion. Windows 10 provides one,
as shown below.
Windows 10 Calculator app in Programmer mode. Screenshot used with permission from
Microsoft. Page 111
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1
Units of Measure
You need to understand the units used to describe computer storage and data
transfer technologies.
■ KiloByte (KB)—1000 bytes (or 103 or 10*10*10 bytes). Small files are often
measured in KB.
In practice the KiB, MiB, and GiB notation is rarely used, but the binary
measurement is. Consequently, you should understand what is generally meant
by terms such as "MB" and "GB" in different contexts.
■ In the context of the Microsoft Windows operating system, file sizes and
memory capacity are always quoted as binary measurements (base 2). For
example, when you see that Windows reports 2 GB memory, this means 2048
MB, not 2000 MB.
Page 112
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
■ Storage capacity is typically quoted by vendors in decimal measurements Using Data Types and Units
(base 10). For example, a hard disk advertised with a capacity of 300 GB
has an "actual" capacity of 286 GiB. Some operating systems, such as
Ubuntu Linux and macOS, also use the decimal notation for system
memory, disk capacity, and file sizes.
Throughput Units
When data is transferred between components in the computer or between
computers over a network, the throughput rate that a particular connection
can sustain is measured in bits per second (bps). As with storage, the basic
unit of bits per second would result in writing out very long values, so
throughput can be expressed more efficiently using the following multiples:
Page 113
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1
Data Types
The CPU and storage devices in a computer only process data as ones and
zeros. These hardware components have no conception of what the data
mean. When it comes to programming software applications though, data
types are very important because they determine what sort of operations can
be performed. For example, the characters 51 can be treated as a number
value, in which case you can use the data in additions and subtractions, or it
can be treated as a text string (representing a house number for instance). If
51 is stored as a string, it must be converted before it can be used in a
mathematical operation.
There are different types of number values and a variety of text forms. These
include:
Page 114
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Using Data Types and Units
Data Representation
When binary values (1s and 0s) are used for char and string data types, there
must be some means of data representation by which different value bytes
map to letters, numbers, and symbols in a character set. There are two
common ways of presenting character set data: ASCII and Unicode.
ASCII was designed a long time ago (1963) when using seven bits
rather than eight represented a significant cost saving. As most
systems now use byte-based storage (eight bits), various ways of
using extended ASCII to encode 256 values have been developed.
Unicode
ASCII, although widely adopted, is a very old standard (devised in early
1960s). More recently, Unicode has become more prevalent. Unicode enables
you to handle character data and express that data across platforms in a
uniform way.
Unicode comprises:
● Character properties.
Page 116
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
The Value of Data Using Data Types and Units
When you think about data, it is important that you understand that it
represents more than just encoded numbers and letters. For organizations,
and even for individuals, computer data can be considered an asset. An asset
is something of commercial value. Therefore, it is important that you take steps
necessary to protect this asset.
Investing in Security
A mechanism designed to protect an information asset or processing system is
called a security control. There are many types of security controls, and they
can be classed in different ways. Typically they are designed to prevent, deter,
detect, and/or recover from attempts to view or modify data without
authorization. Security controls can be costly, both in terms of purchasing
hardware and software and in terms of more complex procedures and staff
training. The business case for investing in security is made by a calculation
called Return on Security Investment (ROSI). To calculate ROSI, you
perform risk assessments to work out how much the loss of data would cost
your organization and how likely it is that data loss might occur. The use of
security controls should reduce both the impact and likelihood of losses,
justifying the investment made.
Security Controls
As mentioned above, a security control is something designed to ensure that
data is contained within the information processing system and is only
accessible with authorization. Some typical examples of security controls to
help protect your data might include:
■ Backup—ensure that you maintain copies of your data and that these
copies can be quickly and easily accessed when necessary.
■ High availability—it is often the case that temporary loss of access to data
can lead to high costs for an organization. Consider a situation when
financial transactions are not available to a banking institution. You can
implement technologies that enable you to ensure your data is available in
the event of one or several failures of hardware or software components
within your infrastructure. These technologies are referred to as fault
tolerance.
Any organization that does not take some, or all, of the preceding steps stands
to lose data and in all probability, suffer financial loss as a result.
Intellectual Property
Intellectual Property (IP) is often the most valuable information asset that an
organization owns. There are various different types of IP and different ways to
protect them from theft.
Copyright
Copyright is automatic legal protection granted to certain types of work
indicating that the copyright holder owns the right to control the use of the
work, including rights of publication, distribution, or sale.
There is no need to apply for copyright or display any copyright notice in order
to be protected by it. The creation of the work ensures copyright protection
automatically. Nonetheless, in case of a dispute, you might need to prove when
the work was created in order to defend yourself against charges of plagiarism.
Plagiarism is the unacknowledged or unauthorized use of someone else's work.
Page 118
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Most authors and publishers demonstrate that they hold copyright over a work Using Data Types and Units
by displaying the copyright symbol © with the date and their name. While
copyright laws vary throughout the world, demonstrating copyright in this way
is likely to protect the owner in most circumstances. In the USA, proof of
authorship can be demonstrated by registering the work with the Copyright
Office (copyright.gov).
Copyright does not apply to an idea that is not actualized, nor does it apply to
names, phrases, or titles. Copyright applies to both the original content of the
work and to original features of its layout, format, and appearance.
Copyright lasts for a number of years after the owner's death. The exact length
of time varies between 15 and 70 years depending on the nature of the work.
After this time, provided the copyright has not been extended for some reason,
the work becomes public domain and may be used freely. Also, in some
circumstances, a copyright holder may have waived their rights and designated
the work as public domain.
Most types of original, created work are covered by copyright whether the work
is printed, broadcast, distributed on a CD, CD-ROM, DVD, or other type of
computer disk, exhibited in a gallery or theatre, or published on the Internet.
Examples include books, films, plays, computer software, games, and artwork.
Note that a work does not have to be "artistic" to secure copyright; technical
subject matter (such as an automobile's driver's handbook) is protected too.
Also, if material is stored electronically, the type of file has no bearing on
copyright; text, graphic, audio, and video files are protected equally.
Page 119
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1 Trademarks
As copyright is not given to the selection of a name, if a company wants to
promote its goods it will normally trademark its name and/or logo. A trademark
must be distinctive within the industry in which the company is selling goods
and services. An ordinary trademark is indicated by the ™ symbol. A registered
trademark is indicated by ®.
If you re-use or imitate an existing trademark, you are liable to legal action from
the owner.
Patents
A patent is legal protection for some kind of invention. Unlike copyright, a
patent can apply to an idea so long as the idea is original (or novel), useful,
and distinctive or non-trivial. If you have registered the patent, you do not
actually have to have made a copy of the invention or put it into practice. A
patent must be applied for and registered; however, there is no automatic
protection, as there is for copyright. In a lot of cases the registration must be
international, or you have no basis for action against people in other countries
infringing upon your patent. This can be complex as different countries have
different standards for accepting patents. Patents are registered for a limited
time only.
Digital Products
A digital product is one that is sold or distributed as binary computer data.
Examples of digital products include software, computer games, ebooks, music
tracks, streaming video, video downloads, and so on. Digital products typically
have low manufacturing and distribution costs, though hosted products can
have substantial infrastructure costs. The downside is that digital products are
quite easy to copy and steal.
Page 120
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Data-driven Business Decisions Using Data Types and Units
As well as having importance and value as an asset, data and information are
critical in driving business decisions and strategies. For example, data can
help a company become more efficient and develop better products and
services:
■ Data is the raw values collected by the system. The system must have
some way of tagging or normalizing these values, similar to the way that
data is defined with different types, so that they can be used for
comparisons. For example, a web server might log whenever a page is
visited and record information about the visitor, such as the time, the
location, the type of browser, how long they spent viewing the page, or any
link from the page that was clicked. All these things are data points with
distinct types and formats.
Page 121
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 1 Facilitating Data-driven Business Decisions
Following the definitions of data, information, and insights set out above, it
follows that you need systems to support these processing, analyzing, and
reporting functions.
Page 122
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Using Data Types and Units
1) Which notation system supports presenting the largest numbers using the
fewest digits: Binary, Decimal, or Hexadecimal?
4) What is the difference between the char and string data types?
Page 123
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
Module 2 / Unit 2
Using Apps
Objectives
On completion of this unit, you will be able to:
Page 124
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Installing Applications Using Apps
Applications (or apps) are the software programs that let users do useful
things with their computer, such as create and edit documents, browse
websites, send email, watch videos, or play games. When you have installed
an operating system such as Windows, you are also likely to want to install and
manage software applications and perhaps enable or disable OS features and
components.
■ That you have a valid agreement or license to install and use the product.
■ Put the program disc in the drive and choose the option to install the
software.
■ Download the setup program from a website then locate and open the
setup program through Explorer.
Page 125
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
When you try to install a program, you will see another example of Windows'
User Account Control (UAC) security feature in action. UAC prompts you to
confirm any important change to the system, such as installing a program or
hardware device or changing a security setting. In the case of programs,
Windows also checks whether the program has a digital certificate proving it
has been created by a trustworthy software publisher; if a certificate is not
there or not valid, Windows displays another warning.
Untrusted publisher warning—this does not necessarily mean that the program is harmful as not
all publishers obtain valid certificates but do not run it if you do not know that it is from a reputable
source. Screenshot used with permission from Microsoft.
Confirm the UAC prompt if you are happy to proceed. The setup program will
then provide a wizard for you to choose the appropriate options, such as
choosing program components, selecting the install location (always choose
"Program Files" unless you have a good reason not to), and creating shortcuts.
Advanced Options
Most software installer packages offer a choice between a default installation
and a custom (or advanced options) installation. A custom installation allows
you to choose specific settings, such as where to install the software and what
icons or startup/autorun options to configure. A custom installation may also
involve the selection of specific feature sets or modules within the software
package.
Page 126
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Microsoft Store Apps Using Apps
In recent versions of Windows, you can install two types of software. Desktop
applications are installed and managed using Programs and Features, as
described above. Apps are installed and managed via the Microsoft Store.
Application Management
Once the application has been installed, there are various ways to perform
additional configuration and application management.
Page 127
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2 Windows features such as UAC and its greater protection for system folders
(Program Files and the system root) plus the redesigned desktop compositing
engine have made application compatibility more challenging. UAC problems
can be solved by running the program as an administrator, and there is an
option to turn off advanced desktop compositing effects.
Use the Details tab in a program's Properties dialog to find the version number and the
Compatibility tab to configure settings for legacy applications. Screenshot used with permission
from Microsoft.
If you need a user to tell you the version number, it is usually listed
by selecting the "About" menu option in the software. The "About"
option may be accessed via a “Help” menu.
Programs and Features—select a program then choose an option from the toolbar. Screenshot
used with permission from Microsoft.
If you click View installed updates, the list will display patches or hotfixes
installed for Windows. You can use the wizard to uninstall a patch.
Turning Windows features on or off. Screenshot used with permission from Microsoft.
Page 129
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
Managing Software Licensing
When installing an app, you need to ensure that the software is properly
licensed for use.
Usually, the software is activated using a product key, which will be a long
string of characters and numbers printed on the box or disk case. The product
key will generate a different product ID or serial number, which is often used
to obtain technical support. The product ID is usually displayed when the
application starts and can be accessed using the About option on the Help
menu.
A company may have hundreds of employees who need the same software on
their computers. Software manufacturers do not expect such companies to buy
individual copies of the software for each employee. Instead, they will issue
either a group use/site license, which means that the company can install the
software on an agreed number of computers for an unlimited number of
employees to use at the same time, or a concurrent license, which means
that the company can allow only a set number of users access to it at any one
time. It is important to monitor usage of the software to ensure that the
permitted number of host-installs or concurrent users is not exceeded.
Page 130
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Registration Using Apps
The software setup program will often prompt you to register the application,
either using an online form or the card supplied with the setup disc. Registering
is usually optional but may be required to obtain product support and updates
and validate the warranty.
■ Shareware is software that you can install free of charge so that you can
evaluate it for a limited period. If you decide to continue using the software
after this period, you must register it, usually for a fee. When you register
the software you often become entitled to extra features and support.
■ Open source is software that also makes the program code used to
design it available. The idea is that other programmers can investigate the
program and make it more stable and useful. An open source license does
not forbid commercial use of applications derived from the original, but it is
likely to impose the same conditions on further redistributions.
Page 131
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
Productivity Software
Spreadsheet Software
A spreadsheet consists of a table containing rows, columns, and cells. When
values are entered into the cells, formulas can be applied to them, enabling
complex calculations to be carried out. Spreadsheet packages can be used for
many tasks including tracking and analyzing sales data and working on
company accounts.
Microsoft Excel spreadsheet software. Note the lettered columns and numbered rows. Each
intersection is a cell that can contain data or a formula. Screenshot used with permission from
Microsoft.
Page 132
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Word Processing Software Using Apps
Word processing means applications that help users to write and edit
documents. A word processor will come with features enabling the user to edit
and review text quickly, using an automated spell checker for instance. Most
word processors also provide formatting and layout tools, allowing the use of
pictures and tables in a document for instance. They are also likely to allow
output to different formats, such as print or online web page.
Presentation Software
Presentation software enables users to create sophisticated slide shows.
Pictures, company logos, graphs, and text can be added to the slides, together
with a variety of animations.
Microsoft Visio diagramming software with a network diagram document open. In this sort of
diagram, you can add shapes from the stencil collections shown on the left of the window and then
draw connectors to link the shapes. Screenshot used with permission from Microsoft.
Page 133
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
Collaboration Software
Collaboration software means that multiple users can work together on the
same file or project.
As with email, this type of application uses servers and clients. The server
software, such as Microsoft's SharePoint Server, or cloud-based services,
such as Google Drive or Smartsheet, provide the storage and sharing features.
The workspace server hosts the document and contains the accounts and
permissions of the users allowed to access it.
Page 134
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
The client software provides the user with the tools to view and edit the Using Apps
document. The client software might be a productivity suite (such as Microsoft
Office) or might be provided with the workspace (Google Docs and Smartsheet
tools for instance).
Editing a document stored in Microsoft's OneDrive cloud storage solution with a cloud-based
version of Microsoft Word. Screenshot used with permission from Microsoft.
When multiple users are editing a document, there has to be a process for
managing changes. One option is to provide a "check out" feature, where a
user checks a document out for editing, and it becomes locked for other users.
Another option is to allow a master editor to view multiple revisions and
approve and merge or reject changes to a single published version.
An ordinary user might use remote desktop to connect from a field laptop to a
machine in the office. Remote desktop is also used by IT support staff to login
to a user's computer to provide support and assistance without having to travel
to the user's location.
Page 135
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
Operating a Windows 7 host from a Windows 10 client using Remote Desktop. Screenshot used
with permission from Microsoft.
Configuring audio devices in Skype. Screenshot used with permission from Microsoft.
Page 136
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
There are numerous different ways of implementing VoIP, each with different Using Apps
protocols which are often proprietary to a particular VoIP software vendor. To
implement VoIP to make calls from a computer in a typical Peer-to-Peer
configuration, you need software (such as Skype or Slack), an Internet
connection, and usually a headset (more convenient than using PC
microphone and speakers).
Business Software
■ Digital paint products such as Corel Painter allow the creation of bitmap
artwork on a computer.
Bitmap artwork means that the file records the color value of each
pixel in the image. Vector artwork records the plot points and color
values of the lines and shapes used. Vector artwork can be resized
without loss of quality whereas resizing a bitmap will require some
pixels to be lost or added, using some dithering process to
determine the color values of the remaining pixels.
Project Management
Project management involves breaking a project into a number of tasks and
assigning responsibilities, resources, and timescales to ensure the completion
of those tasks. Project management also involves identifying dependencies
between tasks. Software such as Microsoft Project or Smartsheet assists with
this process by visualizing task timelines and dependencies and recording
information about task properties and progress.
Database Software
Database packages enable the user to store, organize, and retrieve
information. Databases can search through thousands of records very quickly
and display data in a format specified by the user. They can be used to store
many different types of information, such as timetables, customer details, and
patient records. The database application in Microsoft Office is called Microsoft
Access. This is suitable for creating databases with tens of users.
Databases are also used at every level of IT infrastructure. Fast and reliable
database products are as important as operating systems for large
organizations. Examples of enterprise-level database products include SQL
Server and Oracle. The XML (eXtensible Markup Language) format is also
increasingly important for data storage, as it allows for a high level of
integration between different types of systems.
Business-specific
A company may also commission custom-made software to implement specific
Line of Business (LOB) functions. LOB applications would cover functions
that cannot be performed by "off-the-shelf" software. This might include
product design and manufacturing, fulfilment and inventory control, plus
marketing and sales.
Page 139
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2
3) Why would Windows prompt you to enter a password if you try to install a
software application?
4) Windows comes with web server software but it is not enabled by default.
How would you install this software?
Page 140
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Using Apps
The software application you will install displays technical information about
the system components installed on your computer. It is published by CPUID.
Optionally, browse CPUID's website (cpuid.com) before proceeding to learn
about the company and its products.
2) Open Microsoft Edge (or your preferred browser), and type the following
URL into the address bar:
http://download.cpuid.com/cpu-z/cpu-z_1.85-en.exe
3) In the prompt box displayed at the bottom of the window, click Run.
4) Optionally, click the CPUID link then inspect the publisher's digital
certificate. If you are happy to proceed, click Run.
Page 141
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 2 5) Complete the application's Setup wizard by making the following choices:
○ Select Install.
○ When installation is complete, uncheck the View readme box and click
Finish.
If you were not sure of the provenance of the software, you might
be suspicious of software that requests this level of access.
The program will execute and display a dialog showing detailed information
about the CPU, memory modules, motherboard, and graphics adapter
installed in your computer.
Page 142
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
8) Browse the information reported by selecting the tab headings for a few Using Apps
minutes, then click Close.
You can also display this shortcut menu by right-clicking the Start
button. It contains most of the "power" tools for configuring
Windows.
10) Select the CPUID CPU-Z icon and click the Uninstall button. Click
Uninstall to confirm.
11) Click Yes to confirm (again) then OK when the process is complete.
12) Take a moment to browse the programs installed on your computer. This
view shows you when a program was installed, its size, and (in some
cases) its version number.
13) Press START then type appwiz.cpl and click the icon for the Control
Panel applet returned in the search results.
14) In the left-hand pane of "Programs and Features," click Turn Windows
features on or off.
15) Browse the features already installed and available then click Cancel.
16) In the left pane of "Programs and Features," click View installed updates.
You can use this view to check whether a particular update is installed.
18) Optionally, shut down your computer if you are not continuing to use it after
this lab.
Page 143
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Module 2 / Unit 3
Programming and App Development
Objectives
On completion of this unit, you will be able to:
Page 144
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming Logic Programming and App
Development
Program Sequence
A program is just a sequence of instructions for your computer to perform. For
example, you might want to add two user-entered numbers together and
display the sum on the screen. In plain English, the program might look
something like this:
2) Ask the user for the first number and store that number for subsequent use.
3) Ask the user for the second number and store that number for subsequent
use.
It’s a simple set of instructions, but while English can tolerate ambiguity,
programming generally cannot. In designing a program, we have to consider
how input, processing, and output are all clearly defined. What if the user
entered a word instead of a number? What if the user doesn’t understand
what’s required? You could modify the program to address these issues:
a) If it is, proceed.
b) If it is not, remind the user what the valid range is and prompt again.
a) If it is, proceed.
b) If it is not, remind the user what the valid range is and prompt again.
With the steps shown visually in a diagram, it is easier to see that the program
is not completely linear. There are branches and loops. Also notice that the
program contains some duplicate steps; specifically, the verification steps and
the display instructions steps. We can use the diagram to analyze the
sequence of instructions and write better code to support that sequence.
Page 146
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Writing Pseudocode Programming and App
Development
Having analyzed the structure of our program, we can switch from writing out
the steps as a simple list and start to develop code blocks to support the
program's function.
For example, where there are duplicate steps, you could write those as
separate subroutines and then call them whenever needed.
'Main routine
Add It Up routine {
clear display
call Display Instructions routine
prompt for first number
call Verify subroutine
store first number Variable1
prompt for second number
call Verify subroutine
store second number Variable2
sum (Variable1, Variable2)
write sum to display
}
End routine
'Verify subroutine
Verify subroutine {
verify user input is number
if FALSE, call Display Instructions subroutine
return
}
End routine
'Instructions subroutine
Display Instructions subroutine {
clear display
write "instruction text" to display
prompt OK
clear display
return
}
End routine
Page 147
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 Features of Programming Code
We haven’t used the specific syntax of a particular programming language yet,
but already, this is starting to look like a program (pseudocode). Note some of
the features:
■ When a subroutine completes, it can return to the point in the main routine
from where it was called, and the main routine continues execution. Note
that when we use structures such as this, we have to be very careful not to
create infinite loops in the code by mistake.
■ There is a conditional statement (IF) that means part of the code only
executes when certain conditions are true or false.
■ There are functions (such as "sum" and "write") that we can assume are
provided as features of the programming language. We don't need to code
how to add two numbers together or write output to the display screen.
■ There is a user interface that the program interacts with (prompting for
input and displaying output).
Programming Languages
Having created the logic behind your program, you must then code it using the
appropriate programming language. It’s important to consider what
programming language to use. The choice that you make will be determined by
many factors, including:
A programming language provides the exact syntax for you to use for your
code. For example, the character used for a comment or the way conditional
statements are written out varies from language to language. Some languages
provide more built-in functions than others.
There are many programming languages to choose from, but the most popular
are:
Page 148
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
■ Java Programming and App
Development
■ Python
■ JavaScript
■ C++
■ C#
■ PHP
■ Perl
■ Ruby
■ C++
■ C#
■ COBOL
■ PASCAL
The interpreter can either be part of the operating system, or it can be provided
as a virtual machine, such as the Java VM. With a Java VM, you develop the
programming code in the Java environment and deploy it to your hosts. Each
host OS (Windows versus Linux versus macOS for instance) has a different
Java VM. When you package your Java program, your source code is
compiled to a form called bytecode for the Java VM and the VM converts it to
machine code to run on the hardware platform.
Page 149
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Query Languages
Code written in a query language, such as Structured Query Language (SQL),
is designed to retrieve specific records from a dataset. The code does not
need to be compiled.
See Unit 2.4 for more information about query languages and
databases.
Assembly Language
An assembly language represents machine code in human-readable text. An
assembly language is typically specific to a particular hardware architecture.
This is in contrast to compiled, interpreted, and query languages which you
can use to write code that can be run on a number of platforms, assuming you
have an appropriate compiler or interpreter. Even though it is in human-
readable text, assembly code is very difficult to follow and is only really used by
specialists trying to solve a very particular problem with an application. You
would not choose an assembly language to start your new development
project.
Markup Languages
A markup language is not a programming language but a means of making
data in a document accessible to a program. A markup language, such as the
HyperText Markup Language (HTML) or eXtensible Markup Language (XML),
defines a series of nested tags that describe the structure and/or meaning of
the tag contents.
<html>
<body>
<h1>Hello World</h1>
<p>Say hello back to <a href="mailto:[email protected]>
CompTIA</a>!</p>
</body>
</html>
The tags tell a client application (such as a browser) how to structure the
document:
■ html—this top-level parent element identifies the type of document. All the
other tags are nested within this one.
Page 150
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
■ body—indicates the main part of the content as a page to show to the Programming and App
Development
client. HTML files can also have head sections, which would not be shown
as part of the page display.
■ a—indicates that the content links to another resource. In the example, this
is an email address, but it could be another section of the page or another
file or a page on another web server.
Programming Concepts
Identifiers
An identifier is used in a program to access a program element, such as a
stored value, class, method, or interface. For example, you might assign the
identifier FirstName to a stored value that contains a user’s first name. In
essence, an identifier is a label for something within your program. If your
identifier stores data, then it will be either a variable or a constant.
Variables
A variable contains a value that can change during the execution of the
program. This value might be a text string, a number, or any other data type.
Using our example of a first name, it’s important to understand that although a
person’s name might not change, if you use a programmatic technique to refer
to a user’s name without knowing which user you’re referring to, then, as far as
the program is concerned, that is a variable. You can assign a value to a
variable using fairly simple code.
Page 151
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 For example, the following pseudocode declares our FirstName variable to
store a string value with an initial value Andy, then sets it to a value from a
data store:
James
Constants
A constant is a specific identifier that contains a value that cannot be changed
within the program. For example, you might want to store the numerical value
for the screen dimensions or resolution.
Containers
Container can be used as a term for a special type of identifier that can
reference multiple values (or elements). One example of a container construct
is a simple array. For example, say that you want your program to store a list
of user names who have logged on to the computer in the last 24 hours. You
would declare the array with the data type of the values it will contain and the
number of elements or "rows" that the array can contain:
Elements in the array are counted from zero so the Logons(9) array
contains up to 10 elements.
The following pseudocode would add a value to the first element in the array:
Page 152
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Branches Programming and App
Development
Your program runs from the start to the end unless you instruct it to deviate
from this path. One way of doing so is to create a branch; this is an instruction
to your computer to execute a different sequence of instructions. You use
branches to control the flow within your program. For example, you might
create a branch based on a condition. We saw this in our earlier example
when we verified a number had been entered correctly. If it had, then
something happened, and if it had not, then something else happened. This is
a conditional branch.
Loops
Loops are similar to branches in as much as they deviate from the initial
program path according to some sort of logic condition. However, with a loop,
you instruct your computer to perform, or repeat, a task until a condition is met.
For example, you might create a loop that continues until a certain amount of
time has elapsed or until a counter reaches a certain level. Then, a
predetermined action might occur, depending upon what you want. In the
following example, the program loops around until the value of i is 5. Then the
program proceeds to the next statement.
For i = 1 to 5
print i
Next
As well as "For" structures, loops can also be implemented by "While"
statements:
As mentioned above, you need to make sure your code does not
contain unintended or infinite loops. Without the statement to
increment i in the Do loop example above, the loop would continue
forever. An infinite loop will make the process hang.
Page 153
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 Operators
Looping and branching structures depend on logical tests to determine
whether to continue the loop or the branch to follow. A logical test is one that
resolves to a TRUE or FALSE value. You need to be familiar with basic
comparison operators:
■ <= and >= less than or equal to and greater than or equal to.
You might also want to test more than one condition at the same time. The
logical operators are as follows:
■ AND—if both conditions are TRUE, then the whole statement is TRUE.
■ XOR—if either condition is TRUE but not both, then the whole statement is
TRUE.
You can also use the negation operator NOT to reverse the truth value of any
statement.
Verify subroutine {
verify user input is number
if FALSE, call Display Instructions subroutine
return
}
Whereas, the following is a function:
Verify function {
IsNumber = verify user input is number
return IsNumber
}
Page 154
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
In the function, the value of IsNumber, which will either be TRUE or FALSE, is Programming and App
Development
returned to the main program for some further processing.
Comments
As noted above, it is important to use comments in code to assist with
maintaining it. A comment line is ignored by the compiler or interpreter. A
comment line is indicated by a special delimiter, such as double forward slash
(//), hash (#), or apostrophe (').
Object-Oriented Programming
■ Attributes are values and data types that define the object. The attributes
are stored within the object as fields or private variables. Other programs
cannot access or change the fields directly. They must call a particular
method (see below) to do that.
The important part is that the external code cannot interact with the
field directly.
Just to confuse things, most languages can call (or "wrap") system
commands as part of the code and can therefore also be used for
scripting.
Whatever language is used to create it, a script is a smaller piece of code than
a program. A script is generally targeted at completing a specific task, whether
that task is based within a web-based application or is used by a network
administrator to perform a repetitive administrative task. While a program
usually provides some sort of unique functionality, anything a script does could
usually be performed manually by a user.
Writing scripts is a good place to learn the basics about programming. They
are usually simpler to learn, require no compiling, and are well documented on
the Internet, should you require guidance or samples.
In Windows 10, you can create simple scripts using a number of different tools.
Batch Files
Batch files are a collection of command-line instructions that you store in a
.CMD file. You can run the file by calling its name from the command line, or
double-clicking the file in File Explorer. Generally, batch file scripts run from
end to end and are limited in terms of branching and user input.
Page 156
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Windows PowerShell Programming and App
Development
VBScript
VBScript is a scripting language based on Microsoft’s Visual Basic
programming language. It provides similar functionality to JavaScript. VBScript
is often used by network administrators to perform repetitive administrative
tasks. With VBScript, you can run your scripts from either the command line or
from the Windows graphical interface. Scripts that you write must be run within
a host environment. Windows 10 provides Internet Explorer, IIS, and Windows
Script Host (WSH) for this purpose.
Visual Basic Script in Windows 10. Screenshot used with permission from Microsoft.
Page 157
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Application Platforms and Delivery
Once you have written and tested your code, you need to package it as an
executable or script for deployment to the hosts that will run the software.
There are many different ways of packaging and deploying software
applications.
Single-platform Software
Some software applications are written to run under a particular operating
system (and sometimes a particular version or set of versions of an OS). The
software is written using a development environment suitable for that OS. The
developer writes the application in program code using a particular
programming language. When the application is compiled, it gets converted to
machine code that can run (or execute) in the target OS environment.
Editing a document in the Windows desktop edition of Microsoft Office. Screenshot used with
permission from Microsoft.
Cross-platform Software
Software written for PCs and laptops ("desktop" applications) is being
supplemented with software written for touch-based mobile devices and
operating systems. These are often referred to as apps. There is usually plenty
of interoperability between desktop and mobile platforms. For example, you
could create a document in Microsoft Word on a PC and send it to someone to
view on their smartphone.
Page 158
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
Editing a document in Office Mobile. Screenshot used with permission from Microsoft.
Another trend is for applications to be accessed over the web, often using a
"cloud" deployment model. When software is run from a web server as a web
application, it can usually support a wide range of different types of client
operating systems and devices. Usually the only client required is a compatible
web browser.
Editing a document in Word Online using a web browser. Screenshot used with permission from
Microsoft.
Page 159
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 This sort of cross-platform development is complicated by the different
hardware interfaces for different computing devices. The interfaces supported
by keyboard and mouse input devices for PCs and laptops do not always work
well with the touchscreens used by smartphones. The wide range of display
sizes, orientations, and resolutions are another factor making cross-platform
design challenging. There can be performance problems when software is
written for a "platform independent" environment, such as a Java virtual
machine, rather than code run natively by the OS.
A locally installed application such as this does not need network access to
run, though obviously the network has to be present if the application makes
use of network features.
For some enterprises, this locally installed model presents performance and
security issues. Another option is for the application to be installed to a
network server and executed on that server. Client workstations access the
application using a remote terminal or viewer. The most successful example of
this kind of application virtualization model is Citrix XenApp. Locating the
application and its data files on a server is easier to secure and easier to
backup. This model also does not require that client hosts be able to access
the Internet. The drawback is that if there is no local network connection or the
local network is heavily congested, users will not be able to use the
application.
A third option for deploying apps is the cloud hosted model. This is very
similar to the local network model except that clients connect to the application
servers over the Internet. This provides a lot of flexibility in terms of
provisioning the app to clients located in different regions. As with local
network applications, user-generated data files would normally be saved in the
cloud too, with the same benefits for creating security access controls and
backing up easily. The drawback is that clients and cloud service must both
have a reliable Internet connection. Outages on either side can cause serious
productivity problems.
Actually, Internet access for cloud apps isn't always necessarily the
case. There are different means of providing cloud services, some
of which use local networks. But it is the most dominant model.
Page 160
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
1) What shows the structure of code without using the specific syntax of any
one language?
6) You want to check whether a condition has been met, and if it has, perform
one action. Otherwise, you want your program to perform a second action.
What sort of programming operation would help achieve this?
10) What three scripting options are commonly used in Windows 10 to perform
administrative tasks?
11) True or false? You do not need to install a web application to your
computer; it would be accessed via a browser.
Page 161
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
@echo off
ipconfig /all > report.txt
echo Press a key to view report
pause > nul
notepad report.txt
Note the features of the script:
○ The remainder of the script waits for the user to press a key and then
opens the report file in Notepad.
8) Click Save.
9) Close Notepad.
10) Click Start, scroll down and expand Windows System, and then click
Command Prompt.
Page 162
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
11) In the command prompt window, type documents\test.cmd and then Programming and App
Development
press ENTER.
Running the batch file. Screenshot used with permission from Microsoft.
A notepad window opens and displays the output from the ipconfig.exe
command that you put in your batch file.
for i = 1 to 5
wscript.echo i
next
This program creates a simple loop and uses the echo statement to show
the current value of the variable i as the loop executes.
7) Click Save.
10) The script runs and a new window opens that displays the number 1. Click
OK, and then number 2 displays in a new window. Continue until 5 has
displayed.
Page 163
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Running the VBScript file. Screenshot used with permission from Microsoft.
11) Click Start, scroll down and expand Windows System, and then click
Command Prompt.
Running the VBScript from the command-line. Screenshot used with permission from Microsoft.
13) The script runs from the command line and displays each number in
sequence.
14) Switch to the Notepad window and update the script to read as shown
below:
iHigh = 50
iLow = 10
for i = 1 to 5
randomize
iDisplay = int((iHigh - iLow + 1) * rnd + iLow)
wscript.echo iDisplay
next
15) Save the file.
This script uses some additional integer variables and built-in VBscript
functions to return a random number between 10 and 50 during each
iteration of the loop.
Page 164
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
Running the edited VBScript. Screenshot used with permission from Microsoft.
17) What part of the code would you change to show 10 random numbers?
____________________________________________________________
for i = 1 to 10
19) Run the script again.
20) Switch to the Notepad window and update the script to read as shown
below:
iHigh = 50
iLow = 10
iCount = 0
sTitle = "Number count"
for i = 1 to 10
randomize
iDisplay = int((iHigh - iLow + 1) * rnd + iLow)
wscript.echo iDisplay
if iDisplay > 25 then
iCount = iCount + 1
end if
next
sMsg = cstr(iCount) + " numbers are greater than 25"
msgbox sMsg,vbOK,sTitle
21) Save the file.
Running the modified VBScript from the command-line. Screenshot used with permission from
Microsoft.
To save a bit of time, you can press the UPARROW to select the
original command and then edit it.
Page 166
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
Running a Windows PowerShell cmdlet. Screenshot used with permission from Microsoft.
Your computer name is displayed in a table. The command uses a pipe (|)
to send the output from one command to another command.
7) In the Windows PowerShell window, type the following command and then
press ENTER:
Get-Service
8) Examine the returned results. A list of all services on your computer is
displayed.
9) In the Windows PowerShell window, type the following command and then
press ENTER:
11) In the Windows PowerShell window, type the following command and then
press ENTER:
Page 167
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Running a piped Windows PowerShell cmdlet. Screenshot used with permission from Microsoft.
12) Examine the returned results. A list of all services on your computer is
displayed, sorted by state and then display name.
15) In the Untitled1.ps1 area, type the following code as a single line:
17) In the Save As window, in the navigation pane, expand This PC.
18) Expand Local Disk (C:), expand Windows, and then click System32.
19) In the File name box, type Sample.ps1 and then click Save.
Page 168
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
20) In the In the Administrator: Windows PowerShell ISE window, on the Programming and App
Development
toolbar, click Run . You receive an error. This is because unsigned
scripts are blocked by default. To enable scripts without a valid coding
certificate to run, switch to the Windows PowerShell window.
Set-ExecutionPolicy RemoteSigned
22) When prompted, type A and press ENTER.
23) Switch to Windows PowerShell ISE and click Run. Your simple one line
script runs.
25) At the prompt, type Sample.ps1 and then press Enter. Your simple one
line script runs.
Page 169
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Downloading Python.
3) When prompted, in the download bar at the bottom of the browser window,
click the Save button.
4) When the file has downloaded and the security scan is complete, in the
download bar, click the Run button.
Page 170
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
7) Setup will continue for a minute or two. When the "Setup was successful"
message is shown, click Close.
https://s3.amazonaws.com/comptia-learning/python.zip
9) When prompted, in the download bar at the bottom of the browser window,
click the Save button.
10) When the file has downloaded and the security scan is complete, in the
download bar, click the Open button.
11) Click-and-drag to select the Python01 and Python02 files, and then copy
them to the Documents folder.
1) Click in the Instant Search box and type idle. From the search results,
click IDLE (Python 3.x 32-bit).
The Python shell window opens. The shell window is used to interpret and
run Python scripts and programs during development.
2) Type the following function. As you type, note how tooltips appear to help
you complete the statement and how color-coding is used to validate your
syntax (purple for the function name and green for the string input).
print('Hello World')
Page 171
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 3) Press ENTER to execute the statement. The string "Hello World" is "printed"
as output to the shell.
4) From the File menu, select Open. Click the Documents object then
double-click the Python01 file. The program code is opened in an editor
window.
5) Take a few moments to identify what each line of this program does. The
line position of the cursor is shown in the status bar or you can press
ALT+G to select a particular line:
○ Line 2 uses the print() function we saw earlier but the output is
constructed from both static strings and the variable we declared. Note
the use of the + sign to concatenate (join together) string literals and
variables. Note also that we use double quotes to delimit the literal
strings. This allows us to use the single quote (') as an apostrophe
within the string.
Page 172
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
○ Line 4 sets up a loop using the for statement. A variable named Programming and App
Development
"counter" is used to track progress through the loop. To determine the
loop duration, the range() function sets an initial value of 1, an exit
value of 3, and a step value of 1. The intention is to run the loop three
times, but as we shall see the current code might not accomplish that.
○ Note the use of a colon to complete the line containing the for
statement. While "For" type constructs in general are common to all
programming languages, this statement syntax is specific to Python. It
will often be the case that you may understand the general operation of
logic components, but will need to learn the specific syntax of different
development languages.
○ Lines 5 and 6 are executed during the loop. Note that these lines are
indented. In Python, indentation is used to structure the code and is
critical to compilation and execution. In many other programming
languages, indentation is used for clarity but whitespace is ignored by
the interpreter or compiler.
○ Also in line 5, note the use of the str() function to convert the integer
variable "counter" to a string data type.
○ Line 7 is executed once the loop has completed and is also the final
statement in the procedure.
7) In the shell window, respond to the prompts by typing any names you wish
and pressing ENTER.
1) In the editor window, right-click line 5 (the first statement in the for loop)
and select Set Breakpoint.
2) In the editor window, right-click line 7 (the last line) and select Set
Breakpoint.
3) In the shell window, select Debug > Debugger. A Debug Control window
opens and the shell shows the message "DEBUG ON."
Page 173
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3
Because debug control is active, you now need to start execution manually.
The Go button proceeds normally with execution until a breakpoint is met.
For this exercise, we will investigate the use of tools to step through code
in increments.
The first line of the program is executed. Note that user_name is added to
the list of locals (variables).
7) Click the Out button. Using "Step Out" completes processing of the
function and advances execution to the next statement (line 3).
8) Click the Over button. Using "Step Over" processes the statement without
pausing for each part of any functions it contains.
Note that program execution is still paused on line 3 however. The input()
function is waiting for user input. Note that the debugger buttons are
greyed out.
Page 174
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
9) Switch to the shell window, click at the prompt, type any name, and press Programming and App
Development
ENTER.
10) In the Debug Control window, note the new value of the user_name
variable. Click the Go button.
Program execution is next halted by the breakpoint you set for line 5. Note
that the counter variable is now listed, with the value 1.
12) Switch to the shell window, click at the prompt, type any name, and press
ENTER.
14) Switch to the shell window, click at the prompt, type any name, and press
ENTER.
15) In the Debug Control window, click the Out button. Note the value of
counter as the program exits the loop and processes line 7. Can you
explain why the loop only executes twice?
We can make the range() function work inclusively by adding one to the
stop value. We could also just set the stop value to 4 but adding one
makes the intent of the code clearer.
18) Step through the program to confirm that the loop executes three times.
Page 175
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 3 ○ Out—complete any remaining parts within a function and pause at the
next statement in the main program flow.
21) In the shell window, select Debug > Debugger. The debugger is disabled.
While using this basic program, you may have noticed that some of the output
is not grammatical. Rather than state "You are the 2 person I've met today" it
would be better for the output to state "You are the 2nd person I've met today."
To do this, we can use a function that returns the correct ordinal suffix ("th,"
"st," "nd," or "rd") for a given cardinal integer.
1) From the File menu, select Open. Click the Documents object then
double-click the Python02 file. The program code is opened in an editor
window.
2) You can see the new function has been added in the first ten lines. Note
the use of "def" to declare the function and the use of indents to show
which statements belong to the function. Other languages are more likely
to use brackets to delimit the statements belonging within a function.
The previous code has been assigned to the function main(). The last line
of code calls this main() function if the script is executed directly. This
structure allows the file containing these functions to be imported by
another module without necessarily running the main() code.
3) Note that line 1 contains a comment (#) with attribution for the source code
Page 176
that this function is derived from.
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Programming and App
Development
The original function is more concise than this version. We've
added an additional step to illustrate the use of some different code
operations.
4) In line 16, note the way that the ordinal_suffix() function is called. The
function expects an integer as input (an argument). The main() function is
passing the value of the integer variable "counter" to the ordinal_suffix()
function.
6) Look at line 3. The function assigns its own variable (i) to the integer value.
Note that ordinal_suffix() does not manipulate the value of the "counter"
variable.
7) Look at the if conditional blocks in lines 4-9 and make sure you understand
what they do:
○ In the first if statement, we check whether the integer is over two digits
long. If it is, we truncate it, using functions to convert between integer
and string and back. For example, if the value of i is 112, this statement
will convert it to 12. The code snippet [-2:] is a slice, which is the
method used in Python to return part of a string (in this case the last
two characters). We're doing this because we only need to evaluate the
values from 0 to 99 to determine the appropriate suffix.
○ The second if statement checks whether i has the value of 11, 12, or 13
because in these special cases, the suffix is "th" not "11st" or "12nd."
The code uses the comparison operator less than (<) to accomplish
this.
○ The else statement returns the correct suffix in any other case. It does
this by using the mod operator (%). Mod returns the remainder after
division. For example, if i is 2 then the remainder after division by 10 is
also 2. If i is 22, the remainder is still 2. The get() function is used to
lookup this remainder value in the SUFFIX_DICT list. If the value is not
found (if it is zero or four for instance), "th" is returned by default.
8) Use F5 to run the new program and test that it returns correctly formatted
suffixes in the output.
Page 177
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4
Module 2 / Unit 4
Using Databases
Objectives
On completion of this unit, you will be able to:
□ List the ways that users and applications can interface with databases.
Page 178
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Database Concepts Using Databases
Databases are used everywhere in today’s connected world. Every time you
make an online purchase with an e-commerce retailer, many databases are
accessed by a variety of different applications in order to facilitate your
purchase.
This user record is backed by a database. Each form field you can see shows and updates a
column in a database table while this record is a row in the table.
Database Usage
A database is used both to store information securely and to report on the
information it contains. Consequently, database usage involves the following
processes and tools:
Page 179
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 ■ Storage (data persistence)—databases are often used with applications.
While an application processes variables and other temporary data
internally, this information is lost when the application is terminated. A
database represents a way for an application to store data persistently and
securely.
Spreadsheets are not the only kind of flat file data store. Another example is a
plain text file with delimiters for each column. A Comma Separated Values
(CSV) file uses commas to identify the end of a column and a line feed for
each row.
Comma Separated Values file—the column headers are shown at the top with commas separating
each. Every line in the file corresponds to a row of data.
While flat file systems are easy to create they have many drawbacks compared
to database systems.
■ Databases can enforce data types for each column and validate
information entered as fields and records. Spreadsheets can mimic some
of this functionality but not as robustly. Databases consequently support a
wider variety of data formats.
Page 180
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
■ Databases can manage multiple tables and link the fields in different tables Using Databases
to create complex schemas. In a flat file, all the information is stored within
a single table.
■ Databases are also more scalable. Scalability means being able to expand
usage without increasing costs at the same rate. For example, in a non-
scalable system, doubling the number of users would also double the costs
of the system. Database architecture means that extra capacity can be
added later with much less investment.
Database Structures
There are different types of databases and data stores with different levels of
structure.
Relational Databases
A relational database is the type we have been describing so far. A relational
database is a highly structured type of database. Information is organized in
tables (known as relations). A table is defined with a number of fields,
represented by the table columns. Each field can be a particular data type.
Each row entered into the table represents a data record.
■ Oracle Database.
■ MySQL.
For this to work, in any given table, each record has to be unique in at least
one way. This is usually accomplished by designating one column as a
primary key. Each row in the table must have a unique value in the primary
key field. This primary key is used to define the relationship between one table
and another table in the database. When a primary key in one table is
referenced in another table, then in the secondary table, that column is
referred to as a foreign key.
The structure of the database in terms of the fields defined in each table and
the relations between primary and foreign keys is referred to as the schema.
Page 182
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
You can see that the customer information and book information that appears Using Databases
in the Lending table is drawn from the Customer and Book tables respectively.
Specifically, the Customer ID is drawn from the Customer table and the Title is
drawn from the Book table. The advantage of this approach is that if you must
update customer information, you only need to do so in one place—the
Customer table.
A query can be used to reconstruct the information. For example, if you want to
check the customer associated with a particular lending record, your query
would select the record from the Lending table then use the join between the
Lending and Customer tables to show the values of the name and address
fields from the related Customer table record.
Constraints
One of the functions of an RDBMS is to address the concept of Garbage In,
Garbage Out (GIGO). It is very important that the values entered into fields
conform are consistent with what information the field is supposed to store.
When defining the properties of each field, as well as enforcing a data type,
you can impose certain constraints on the values that can be input into each
field. A primary key is an example of a constraint. The value entered or
changed in a primary key field in any given record must not be the same as
any other existing record. Other types of constraints might perform validation
on the data that you can enter. For example, you could add constraints to
prevent a field from being left blank, to define the format of a telephone
number, or to check that the value entered to choose an order delivery date is
not in the past. Another example of a constraint is to enter a default value in a
field if the user makes no selection.
Unstructured data, on the other hand, provides no rigid formatting of the data.
Images and text files, Word documents and PowerPoint presentations are
examples of unstructured data. Unstructured data is typically much easier to
create than structured data. Documents can be added to a store simply and
the data store can support a much larger variety of data types than a relational
database can.
Page 183
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 Sitting somewhere between these two is semi-structured data. Strictly
speaking, the data lacks the structure of formal database architecture. But in
addition to the raw unstructured data, there is associated information called
metadata that helps identify the data.
Key Value
user01_surname Warren
user01_firstname Andy
user01_age 27
user02_surname Pengelly
user02_town Bigtown
user_01_marketingconsent TRUE
user_02_marketingconsent FALSE
As you can see, not all properties have to be defined for each object. One
widely used key/value format is JavaScript Object Notation (JSON). For
example, "user01" could be expressed as the following JSON string:
These relational methods can be split into two types; those that define the
database structure and those that manipulate information in the database.
■ ALTER TABLE—this allows you to add, remove (drop), and modify table
columns (fields), change a primary key and/or foreign key, and configure
other constraints. There is also an ALTER DATABASE command, used for
modifying properties of the whole database, such as its character set.
The following examples show some of the ways that a SELECT statement can
be used to build a query:
Permissions
SQL supports a secure access control system where specific user accounts
can be granted rights over different objects in the database (tables, columns,
and views for instance) and the database itself. When an account creates an
object, it becomes the owner of that object, with complete control over it. The
owner cannot be denied permission over the object. The owner can be
changed however, using the ALTER AUTHORIZATION statement.
Other accounts can be granted specific rights over an object using the
statement:
Page 186
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Using Databases
SQL also supports a CONTROL permission where the user has all
rights to the object by default but can subsequently be denied
some rights.
Database access methods are the processes by which a user might run SQL
commands on the database server or update or extract information using a
form or application that encapsulates the SQL commands as graphical controls
or tools.
Direct/Manual Access
Administrators might use an administrative tool, such as phpMyAdmin, to
connect and sign in to an RDBMS database. Once they have connected, they
can run SQL commands to create new databases on the system and interact
with stored data. This can be described as direct or manual access.
Query/Report Builder
There are many users who may need to interact closely with the database but
do not want to learn SQL syntax. A query or report builder provides a GUI for
users to select actions to perform on the database and converts those
selections to the SQL statements that will be executed.
Programmatic Access
A software application can interact with the database either using SQL
commands or using SQL commands stored as procedures in the database.
Most programming languages include libraries to provide default code for
connecting to a database and executing queries.
Page 187
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4
It may also be necessary to export data from the database for use in another
database or in another type of program, such as a spreadsheet. A dump is a
copy of the database or table schema along with the records expressed as
SQL statements. These SQL statements can be executed on another
database to import the information.
Most database engines support exporting data in tables to other file formats,
such as Comma Separated Values (.CSV) or native MS Excel (.XLS).
3) How does an RDBMS such as Microsoft SQL Server differ from Microsoft
Excel when used to store a dataset?
Page 189
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4
3) If necessary, accept the use of cookies by the site. On the main page, click
the Agree and Start Free Download button.
4) In the prompt at the bottom of the window, click Save. When download is
complete, in the prompt, click Run.
6) If necessary, on the taskbar, click the Java icon . In the Java Setup
wizard, click Install. At the license terms warning prompt, click OK.
Having installed the Java Runtime Environment, you can now download
and install Open Office.
10) If necessary, accept the use of cookies by the SourceForge site. In the
prompt at the bottom of the window, click Save.
Windows does not trust the installer. In this case you have to trust
the site that you downloaded the file from (sourceforge.net). You
can find out more about how to verify the installer by browsing
Open Office's FAQs (www.openoffice.org/security/faq.html#verify).
12) In the User Account Control window, read the warning but click Yes.
15) On the Welcome to the Installation Wizard for OpenOffice page, click
Next.
Page 191
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 16) On the Customer Information page, click Next.
17) On the Setup Type page, click Custom and then click Next.
19) On the File Type page, clear all check boxes and then click Next. This
step is very important if you already have Microsoft Office installed.
25) Complete the User name information and then click Finish.
26) From the Tools menu, select Options. In the Options dialog, select Java.
After a few seconds, the dialog should update to show a path to the Java
runtime environment.
Page 192
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Exercise 2 / Creating a New Database Using Databases
In this exercise, you will create a new database and create database tables.
3) In the Database Wizard, on the Select database tab, click Create a new
database and then click Next.
6) In the File name box, type CompTIA and then click Save.
7) In the open database window, click Tables and then click Create Table in
Design View.
As a first step, we will create a primary key for the table. As the primary key
must always be unique, it is a good idea to use an automatically generated
number for this field.
8) In the new table window, in the Field Name column, type CustomerID
10) In the lower panel, from the AutoValue box, select Yes.
The database engine automatically picks this field to use as a primary key.
A key icon appears in the row selector in the far left (the grey box) to show
this.
Page 193
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 12) Click in the Field Name column in the next row and type Name
13) In the Field Type column, leave Text [ VARCHAR ] selected, and in the
Description column, type Enter the company name
This creates a field with a string data type (variable number of characters).
14) In the lower panel, set the Entry required value to Yes and the Length to
20
This sets constraints for the field. Note that the length constraint sets a
maximum length, so the user can enter fewer characters if needed. If we
used a fixed length CHAR field data type, the same number of characters
would have to be input each time—obviously that would not be suitable for
a company name.
15) Add an address field to the table with the following properties:
○ Required: No
○ Length: 50
Page 194
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
16) Add a telephone field to the table with the following properties: Using Databases
○ Required: No
○ Length: 10
18) In the Save As box, type the name Customer and click OK.
19) Close the Customer table. In the database window, click Create Table in
Design View.
20) In the new table window, in the Field Name column, type ContactID
21) In the Field Type column, select Integer [ INTEGER ], and in the
Description column, type Primary key for the Contact table
22) In the lower panel, from the AutoValue box, select Yes.
23) Click back in the field name area. The field is set as a primary key
automatically.
Page 195
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 As each contact will be connected with an associated company record, we
now need to add the CustomerID field as a foreign key in the Contact table.
25) In the Field Type column, select Integer [ INTEGER ], and in the
Description column, type Select a customer record
26) In the lower panel, from the Entry required box, select Yes.
27) Add a first name field to the table with the following properties:
○ Required: Yes
○ Length: 25
28) Add a surname field to the table with the following properties:
○ Required: Yes
○ Length: 25
30) In the Save As window, in the Table Name box, type Contact and click
OK.
33) In the Add Tables dialog, with Customer selected, click Add then select
Contact and click Add. Click Close.
34) Drag the CustomerID field from the Customer table over the Customer
field in the Contact table.
Page 196
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Using Databases
Note the symbols on the join line. The customer table side is shown with a
"1" while the contact side is labelled "n." This represents a one-to-many
relationship. Each single record in the Customer table can have many
related records in the Contact table. This is the most common type of
relation.
35) Close the Table Relationships window. Click Yes to save when prompted.
36) On the menu bar, click Save to save the database tables.
4) In the Available fields list, select Name, Address, and Telephone then
click > .
Page 197
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4
As the ID field is automatically generated for each new record, it does not
need to be added to the form.
5) Click Next.
6) Check the Add Subform box and the Subform based on existing
relation option button. Select Contact.
Adding a subform.
7) Click Next.
Page 198
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
9) On the Arrange controls tab, under Arrangement of the main form, click Using Databases
Columnar – Labels Left icon. Under Arrangement of the subform, click As
Data Sheet.
12) Click Next twice to accept the default style and name.
14) In the open form, type the following data in the appropriate fields:
○ Name: Widget
○ Telephone: 9990001111
15) Click in the subform data sheet and enter the following information:
○ FirstName: Dave
○ Surname: Martin
○ FirstName: Sue
○ Surname: Smith
Page 199
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 17) Click back in the main form (in the Name field for instance) then click the
18) In the open form, type the following data in the appropriate fields:
○ Name: Grommet
○ Telephone: 8880002222
19) Click in the subform data sheet and enter one or two contacts.
21) In the database window, select the Tables object. Open the Customer
table. Make a note of the values in the CustomerID primary key field for the
two records:
Widget: _____________________________________________________
Grommet:____________________________________________________
23) Open the Contact table and check the Customer field—you should see the
values you recorded above entered in the foreign key.
Page 200
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Exercise 4 / Working with Queries Using Databases
In this exercise, you will use a query to extract data and display it using a
report.
3) In the Query Wizard window, from the Tables list, select Table:
Customer.
7) Click Next.
8) On the Sorting order tab, in the Sort by list, select Customer.Name and
in the Then by list, select Contact.Surname.
9) Click Next.
10) With Match all of the following selected, from the Fields list box, select
Contact.FirstName. From the Condition box, select is not equal to, and
in the Value box, type Dave
____________________________________________________________
Page 201
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4
To fix the output, we need to re-state the join (relationship) between the
tables in the query builder.
13) Drag the CustomerID field from the Customer table over the Customer
field in the Contact table.
Page 202
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
This runs the query within the builder interface. You should see that the join Using Databases
is now working properly and the query is returning one row per contact
record rather than generating rows for each unique combination of
customer and contact records.
Page 203
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit 4 Everything you have done in the database GUI is using underlying SQL.
Note the features of this statement:
○ The FROM keyword lists the data sources (Customer and Contacts).
○ The WHERE keyword states the join and the criteria excluding "Dave."
Page 204
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Summary Using Apps and Databases
In this module you learned the basics of using a computer, Windows, and
software applications.
□ Consider the importance and use of data and analytics to defining business
goals.
□ Procedures and functions enable you to create pieces of code that you will
reuse within your program. Object oriented techniques help to design
robust code.
Page 205
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM
Module 2 / Unit Summary □ Applications can be packaged for standalone installation on a single
computer but other architectures, such as network hosted and cloud
hosted, are becoming more popular.
□ Flat file systems, such as Microsoft Excel, can be used to handle small
volumes of data, and support one or two users. RDBMS-based databases
typically support SQL and scale well to support high numbers of users and
transactions. Also be aware of semi-structured datastores.
□ You should know typical data definition and data modification commands
and the basics of database permissions and access methods. Also
consider how application architecture can use tiers to separate data from
presentation and application layers.
Page 206
Licensed For Use Only By: Byte Back Student 1 BB1 Jun 10 2021 11:32AM