Lab #1
Lab #1
Lab Summary:
In this lab students were given a brief introduction to programming environment. This lab
aims to give a basic background of computer programming and various process involved
in execution of program. The importance of IDE was discussed, which enabled students
to differentiate between various programming languages.
Theory:
Computer Systems
A computer system consists of all the components (hardware and software) Used to execute the
desires of the computer user.
Hardware
Hardware is the electronic physical components that can retrieve process and store data. It is
generally broken down into five basic components:
• CPU is the unit where programs are executed. It consists of the control unit,
which oversees the overall operation of program execution and the A.L.U.
(Arithmetic/Logic Unit), which performs the Mathematical and comparison
operations.
• Main memory is the area where programs and data are stored for use by the
CPU.
• Secondary Storage is the area where programs and data are stored for later use.
• Input devices are used to get programs and data into the computer.
• Output devices are used to get programs and data from the computer.
Software
Software consists of a sequence of instructions given to perform some pre-defined tasks. These
labs concentrate on the software portion of a computer system.
Lab Manual PROGRAMMING FUNDAMENTALS
Computer Program
A computer program is a series of instructions written in some computer language that performs
a particular task. Many times, beginning students concentrate solely on the language code;
however, quality software is accomplished only after careful design that identifies the needs,
data, processes and anticipated outcomes. For this reason, it is critical that students learn good
design techniques before attempting to produce a quality program. Design is guided by an
algorithm, which is a plan of attacking some problem.
Translation Process
Computers are strange in that they only understand a sequence of 1s and 0s. The following looks
like nonsense to us but, in fact, is how the computer reads and executes everything that it does:
10010001111010101110010001110001000
Because computers only use two numbers (1 and 0), this is called binary code. Can you imagine
how complicated programming would be if we had to learn this very complex language. That, in
fact, was how programming was done many years ago; however, today we are fortunate to have
what are called high level languages such as C++. These languages are geared more for human
understanding and thus make the task of programming much easier. However, since the
computer only understands low level binary code (often called machine code), there must be a
translation process to convert these high-level languages to machine code. This is often done by
a compiler, which is a software package that translates high level languages into machine code.
Without it we could not run our programs. The figure below illustrates the role of the compiler.
The compiler translates source code into object code. The type of code is often reflected in the
extension name of the file where it is located. Example: We will write source (high level
language) code in C++ and all our file names will end with .cpp, such as:
firstprogram.cpp
secondprogram.cpp
When those programs are compiled, a new file (object file) will be created that ends with .obj,
such as:
firstprogram.obj
secondprogram.obj
Lab Manual PROGRAMMING FUNDAMENTALS
The compiler also catches grammatical errors called syntax errors in the source code. Just like
English, all computer languages have their own set of grammar rules that must be obeyed. If we
turned in a paper with a proper name (like John) not capitalized, we would be called to task by
our teacher, and probably made to correct the mistake. The compiler does the same thing. If we
have something that violates the grammatical rules of the language, the compiler will give us
error messages. These must be corrected, and a grammar error free program must be submitted to
the compiler before it translates the source code into machine language. In C++, for example,
instructions end with a semicolon. The following would indicate a syntax error:
cout << "Hi there" << endl
Since there is no semicolon at the end, the compiler would indicate an error, which must be
corrected as follows:
cout << "Hi there" << endl;
After the compile process is completed, the computer must do one more thing before we have a
copy of the machine code that is ready to be executed. Most programs are not entirely complete
in and of themselves. They need other modules previously written that perform certain
operations such as data input and output. Our programs need these attachments in order to run.
This is the function of the linking process. Suppose you are writing a term paper on whales and
would like a few library articles attached to your report. You would go to the library, get a copy
of the articles (assuming it would be legal to do so), and attach them to your paper before turning
it in. The linker does this to your program. It goes to a “software library” of programs and
attaches the appropriate code to your program. This produces what is called the executable code,
generated in a file that often ends with .exe.
Example: firstprogram.exe secondprogram.exe The
following figure summarizes the translation process:
Once we have the executable code, the program is ready to be run. Hopefully it will run
correctly, and everything will be fine; however, that is not always the case. During “run time”,
we may encounter a second kind of error called a run time error. This error occurs when we ask
the computer to do something it cannot do. Look at the following sentence: You are required to
Lab Manual PROGRAMMING FUNDAMENTALS
swim from Naples, Italy to New York in five minutes. Although this statement is
grammatically correct, it is asking someone to do the impossible. Just as we cannot break the
laws of nature, the computer cannot violate the laws of mathematics and other binding
restrictions. Asking the computer to divide by 0 is an example of a run time error. We get
executable code; however, when the program tries to execute the command to divide by 0, the
program will stop with a run time error. Run time errors, particularly in C++, are usually more
challenging to find than syntax errors. Once we run our program and get neither syntax nor run
time errors, are we free to rejoice? Not exactly. Unfortunately, it is now that we may encounter
the worst type of error: the dreaded Logic error. Whenever we ask the computer to do
something, but mean for it to do something else, we have a logic error. Just as there needs to be a
“meeting of the minds” between two people for meaningful communication to take place, there
must be precise and clear instructions that generate our intentions to the computer. The computer
only does what we ask it to do. It does not read our minds or our intentions! If we ask a group of
people to cut down the tree when we really meant for them to trim the bush, we have a
communication problem. They will do what we ask, but what we asked and what we wanted are
two different things. The same is true for the computer. Asking it to multiply by 3 when we want
something doubled is an example of a logic error. Logic errors are the most difficult to find and
correct because there are no error messages to help us locate the problem. A great deal of
programming time is spent on solving logic errors.
Integrated Development Environments
An integrated development environment (IDE) is a software package that bundles an editor (used
to write programs), a compiler (that translates programs) and a run time component into one
system. For example, the figure below shows a screen from the Microsoft Visual C++ integrated
environment. Other systems may have this component separate which makes the process of
running a program a little more difficult. You should also be aware of which Operating System
you are using. An Operating System is the most important software on your computer. It is the
“grand master” of programs that interfaces the computer with your requests. Your instructor will
explain your system and C++ environment so that you will be able to develop, compile and run
C++ programs on it.
Activity 1.2:
Lab 1.1 Installing IDE for C++ :
Procedure:
Lab Manual PROGRAMMING FUNDAMENTALS
Rubrics
Absent Student is Student can Student has Student Student
unable to understand followed has perfectly
follow the the instruction constructe implemente
provided provided s to d the d a working
instruction laboratory construct functional/ model/
s properly. instruction the working logic/
The s and fundament schematic/ circuit/
student familiar al model/ block
can name with the schematic/ block diagram/
the lab block diagram/ code and
Demonstratio hardware environme diagram/ code, and successfull
n or nt (Trainer/ code/ have y executed
simulation software/ model on successfull the lab
platform, IDE), but the y executed objective in
but unable cannot protoboard the Realtime or
to implement / trainer/ program/ in a
implement on the simulation run circuit simulation
anything platform software. on environmen
practically practically software t and
or on the or on the platform produced
software software the desired
results
Category Ungrade Very Poor Fair Good Excellent
d Poor
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
0.20
Date Total Instructor’s Signature
Marks
Marks