Professional Documents
Culture Documents
Computer Programs
Computer programs are collections of instructions that tell a computer how to interact with
the user, interact with the computer hardware and process data. The first programmable
computers required the programmers to write explicit instructions to directly manipulate the
hardware of the computer. This "machine language" was very tedious to write by hand since
even simple tasks such as printing some output on the screen require 10 or 20 machine
language commands. Machine language is often referred to as a "low level language" since
the code directly manipulates the hardware of the computer.
By contrast, higher level languages such as "C", C++, Pascal, Cobol, Fortran, ADA and Java
are called "compiled languages". In a compiled language, the programmer writes more
general instructions and a compiler (a special piece of software) automatically translates these
high level instructions into machine language. The machine language is then executed by the
computer. A large portion of software in use today is programmed in this fashion.
Program Structure
#include <stdio.h>
"C" void main() {
printf("Hello World");
}
C++
#include <iostream>
Page 1 of 18
int main()
{
cout << "Hello World";
return 0;
}
Variable Declaration
Variables are place holders for data a program might use or manipulate. Variables are given
names so that we can assign values to them and refer to them later to read the values.
Variables typically store values of a given type. Types generally include:
#include <stdio.h>
void main() {
int age;
float salary;
char middle_initial;
Page 2 of 18
begin
age := 21;
salary := 29521.12;
middle_initial := 'K';
There are three Boolean operators: AND, OR and NOT. These operators are written
differently depending on the language being used. In mathematics, the logical operators are
written as
The following table compares how AND OR and NOT are written in different programming
languages:
Mathematics
Perl & || !
Java & || !
The Boolean operators are evaluated in the following fashion. For the AND operator, the
combination of two "True" values results in "True" all other combinations evaluate to False.
For example:
Page 3 of 18
True AND True evaluates to True
True AND False evaluates to False
False AND True evaluates to False
False AND False evaluates to False
For the OR operator, as long as one of the value is True, then the expression evaluates to
True:
True OR True evaluates to True
True OR False evaluates to True
False OR True evaluates to True
False OR False evaluates to False
The NOT operator is called the "complimentary" operator. It reverses the truth value of the
operand:
NOT True evaluates to False
NOT False evaluates to True.
The Boolean operators and their evaluations are often expressed in Truth Tables. We
write T and F to signify the values of True and False respectively. The following are truth
tables for the three operators:
T F T F T F
T T F T T T F T
F F F F T F
To use a truth table, choose a value from a row on the top and from a column on the left side
and then see where they intersect to determine what they evaluate to. For example, looking at
the truth table for AND, pick the value F for False on the top and then pick the value T for
True along the left side. Where these two intersect shows an F for False meaningTrue AND
False evaluates to False.
Comparison Operators
Boolean expressions often involve comparison operators that can be evaluated to determine if
they are True or False. Comparison operators
include:
Page 4 of 18
Language Equality Greater than Less than Inequality
Comparison operators are used to form expressions that can be evaluated as True or False.
For example, we might ask if there are more than 30 students in the class using the following
expression:
Number_of_Students > 30
If there are more than 30 students in the class, then this expression will evaluate to True. If
there are 30 or fewer students in the class, then this expression will evaluate to False.
Question Expression
Does Alice make more than $35,000 per year? Alice_Salary > 35000
Did the NY Giants defeat the Dallas Cowboys? Giants_Points > Cowboys_Points
For each of these examples, supplying values for each of the expressions allows us to
determine if that expression is True or False. For example, if Alice only makes $31,000, then
the first expression would evaluate to False.
Page 5 of 18
Combining Boolean and Comparison Operators
In the previous sections, we have seen how the Boolean operators and Comparison operators
can be used to form expressions. In this section, we combine the two types of operators to
form more complex expressions.
For example, suppose we ask the question: Are there more than 30 students in the class, and
are there more than 30 seats in the room? This might be expressed as:
Number_of_Students > 30 AND Number_of_Seats > 30
We evaluate such an expression by determining the value (True or False) of each of the
comparison expressions, and then use those values to evaluate the Boolean expression. In our
example, suppose the class is a very large one that is held in a large room. In other words,
there are more than 30 students and the room has more than 30 seats. Therefore, we would
evaluate the expression as follows:
Given the above 5 items are facts, consider the truth values of the following expressions:
Expression Evaluation
Page 6 of 18
Alice_salary < 25000 is
NOT Alice_salary < 25000 False
NOT False is True
Control statements "control" which sections of code in a program are executed. For example,
we might want a set of statements to execute only if certain conditions are met, otherwise, the
statements would not be executed. There are three general types of control statements:
Decision or Conditional statements are a type of Control statement and are often referred to
as IF..THEN..ELSE statements as can be seen in these examples:
if (condition) {
statements
"C", C++, Java, Perl } else {
else_statements
}
if (condition)
then
Pascal begin
statements
end;
Page 7 of 18
Iterative Constructs
Virtually all programming languages have a facility to allow a section of code to be repeated
(iterated). There are several variations to iterative or looping constructs. For the most part,
they fall into two categories: FOR loops and WHILE/DO loops.
FOR loops
WHILE loops
Page 8 of 18
Arcs represent a way to transition from one node to the next. They can represent actions that
move form one node to another or relationships between nodes. Arcs always begin and end at
some node. It's possible for an arc to begin and end at the same node.
In the following figure, nodes 1, 2 and 3 of the graph have been joined by arcs
labeled a and b.
Tree Structures
Tree structures are quite common in computer science. They can represent a sorted collection
of numbers or names, or a series of decisions that need to be made. Like graphs (described in
another section), trees are made up of nodes and directed arcs. Nodes represent some value
and arcs point from one node to another. Trees are in many ways like graphs with restrictions
on how the arcs are arranged.
In computer science trees grow upside down. The root is at the top and the leaves are at the
bottom. Below is an example of a tree that is being used to hold some integers in a particular
order:
Page 9 of 18
The nodes in this tree represent integers. In this case, the integers 1, 3, 4, 5, 7, 8 and 10 have
been used. The root node is labeled as "5" and appears at the top of the tree. Severalinterior
nodes (nodes that are neither root nor leaves) labeled 3 and 8 appear in the middle of the tree.
Finally, leaf nodes with labels 1, 4, 7 and 10 appear at the bottom of the tree.
A Parent node is one that has at least one node below it. In the above tree, node 3 is a parent
and its Child nodes are 1 and 4. (Can you find the other 2 parent nodes in the graph?) Child
nodes with a common parent are called sibling nodes. In the example, nodes 1 and 4 are
siblings. As a rule, child nodes in a tree may only have one parent.
Installing Fedora 7
Now that you’ve planned your installation and prepared the computer, you’re ready to
actually install Linux. The following procedure describes the steps you must follow to install
Fedora 7 on a computer that has a bootable DVD-ROM drive:
1. Insert the Fedora 7 CD in the DVD drive and restart the computer.
The computer boots from the DVD drive and displays a Linux boot prompt, which looks like
this: Boot:
2. Press Enter.
The computer starts Linux from the installation disk. The screen shown in Figure 1-1 soon
appears. This screen gives you several options for starting the installation. The most common
is to simply press Enter.
3. Press Enter.
Now a bunch of text messages fly by your screen as Linux starts up. Eventually, the screen
shown in Figure 1-2 appears, offering to test the CD media you’re installing from to make
sure you have downloaded and burned the CD images correctly.
Page 10 of 18
Figure 1-2: Testing the CD media.
4. Press the Tab key and then press Enter to skip the test.
Still more text messages fly by, but soon Fedora switches into graphics mode and displays the
Welcome to Fedora Core screen, as shown in Figure 1-3.
5. Click Next.
The Language Selection screen appears, offering quite a few language choices, as shown in
Fig1-4.
6. Choose your language and then click Next.
The Keyboard Configuration screen appears. It lets you choose from about 55 different
keyboard styles.
Page 12 of 18
Figure 1-5: Choosing the host name.
Page 13 of 18
Figure 1-7: Setting the root password.
Using the Setup Agent When Fedora restarts the first time after completing the installation
program, it launches a handy feature called the Setup Agent, as shown in Figure 1-14.
(The Setup Agent runs only if you installed a GUI.) The Setup Agent resembles the
installation program, but it asks a few questions that the installation program forgot to ask.
Page 16 of 18
Figure 1-14: The Setup Agent.
When the Setup Agent starts, follow these steps to see it through to completion:
1. On the Welcome screen, click Forward to get started.
The Setup Agent displays the License Agreement, as if after going through the previous 15
steps to install Fedora, you’re now going to decide you don’t agree to their terms. It’s useless
to resist.
2. Click Forward to confirm your acceptance of the license agreement.
The Setup Agent asks you to create a user account so that you don’t have to access the system
by using the root account, as shown in Figure 1-15.
3. Type a name and password for the user account and then click Forward.
The Setup Agent now asks you to set the date and time.
4. Select the correct date and time and then click Forward.
Now the Setup Agent asks if you want to submit details about your hardware configuration as
part of an effort to improve Linux’s support for various hardware devices.
5. Click Send Profile or Do Not Send Profile and then click Finish.
That’s all there is. Your Linux system is now set up and ready to go.
Page 17 of 18
Figure 1-15: Creating a user account.
Page 18 of 18