BIT104 SLM Library - SLM - Unit 01
BIT104 SLM Library - SLM - Unit 01
Structure:
1.1 Introduction
Objectives
1.2 Programming Languages
Machine Level Languages
Assembly Level Languages
High Level Languages
1.3 Programming Domain
Scientific Applications
Business Applications
Artificial Intelligence
Systems Programming
World Wide Web and Web Application
Data Mining
1.4 Program Development Cycle
1.5 Case study: Converting Temperature from Centigrade to
Fahrenheit
1.6 Program Translation Process and Execution Process
Program Translation Process
Program Execution Process
1.7 Problem solving using Algorithms and Flowcharts
Algorithm
Flow Charts
1.8 Performance Analysis and Measurements
1.9 Summary
1.10 Terminal Questions
1.11 Answers
1.12 Exercises
1.1 Introduction
Presently computers are part of our day to day life. We use them to solve
complex problems in scientific application, at the workplace to perform day
to day activities and solve complex problem, or look for driving directions,
have fun and communicate. They have several applications in the business
Self-Assessment Questions
1. ________ are who create sequence of instructions depending upon the
requirement of application.
2. In ________ languages, Names and Symbols are used to represent
the program instruction.
3. __________ level languages allows programmer to write program
closer to language understand by human being.
We are going to use top down design. In top-down design, we first list major
steps or sub problem that needed to solve. Once we know the sub problem,
we can solve each one individually and write the algorithm for it. In general,
most computer algorithms consists of at least one of the following steps:
should understand user needs. Here are some sample answers for the
above questions:
Input required for the problem is: Temperature in degree centigrade -
Centigrade
Output produced by the problem is: Temperature in Fahrenheit -
Fahrenheit
Once you know the input and outputs, you list out the formulas required for
the solution of problem.
Formula for conversion of centigrade to Fahrenheit is as:
Fahrenheit =1.8 * Centigrade + 32;
2. Solution Design and algorithm:
The algorithm for the problem to convert from degree centigrade to
Fahrenheit is as:
1. Get temperature in degree.
2. Convert the degree to Fahrenheit
3. Display the temperature in Fahrenheit.
We have to decide whether any steps of the algorithm, need further
refinement or whether are perfectly clear as stated. Step 1 and 3 are basic
steps, require no further refinement. Step 2 is fairly straightforward, but
some detail might help.
Step 2 - refinement:
2.1 The temperature in Fahrenheit is 1.8 times the temperature in
centigrade and then addition of 32.
We list the complete algorithm with refinements below, shows you how it all
fits together.
Algorithm with refinements:
1. Get temperature in degree centigrade.
2. Convert the degree centigrade to Fahrenheit
2.1 The temperature in Fahrenheit is summation of 1.8 times the
temperature in centigrade and then addition of 32.
3. Display the temperature in Fahrenheit.
3. Implementation: To implement the solution, we will write the program in
C language. Program 1.1, is a C program along with a sample output of the
program after execution. The bold lines in the program correspond to the
algorithm steps. Do not worry about detail understanding of program for now.
We will study how to write program in C language from next chapter
onwards. The printf function, which is used to display the result and scanf
function, which is used to get input from the user. The printf and scanf
function are defined in library called stdio.h.
centi and fah are variable corresponding to Centigrade degree and
Fahrenheit degree temperature respectively.
Program 1.1: problem to convert from degree centigrade to Fahrenheit
#include<stdio.h>
int main(void)
{
// input centigrade in variable centi
//output Fahrenheit in stored in variable fah
float centi, fah;
clrscr();
printf(“Enter temperature in centigrade :”);
scanf(“%f”,¢i); // input - centigrade
fah= (1.8 * centi ) + 32; // conversion to Fahrenheit
pritnf(“\nTemperature in Fahrenheit = %f”,f); // display
result
getch();
}
Sample Output
Enter temperature in centigrade :32
Temperature in Fahrenheit = 89.59998
Self-Assessment Questions:
8. The _________approach of programming involves breaking a program
down into sub components called modules.
9. State True/False: Testing involves writing test cases with different sets
of data.
compiler generates an error. Linker also links user defined library functions
with program. We will discuss user defined function later. Generally, the
compiler automatically invokes the linker as the last step in compiling a
program.
Loader: A loader is the part of an operating system that is responsible for
loading programs. It is one of the essential stages in the process of starting
a program, as it places programs into memory and prepares them for
execution. Loading a program involves reading the contents of executable
file, the file containing the program text, into memory, and then carrying out
other required preparatory tasks to prepare the executable for running.
Once loading is complete, the operating system starts the execution of
program.
Fig. 1.4 shows the complete process of translation of source code into
executable program and execution of program.
Object Code
Source Code Compiler (Convert.obj) Linker
(Convert.c)
Executable
Main Memory Loader program
(Convert.exe)
Figure 1.4: Source code translation into Executable code and Loading
Self-Assessment Questions
10. ________ is a language translator, which translate source code written
high level language into object code.
11. An interpreter is a program which translates statements of a program
into machine code and execute it, one statement of the program at a
time. (State True/False)
Start
Read length
Read breadth
Display area
Stop
Start
Read a, b
Yes No
Is a<b?
Print a Print b
Stop
Self-Assessment Questions:
12. The __________ is defines as “A step-by-step procedure to solve a
given problem”.
13. A _______ is a pictorial representation of an algorithm.
14. __________ is a function describing the amount of memory an
algorithm takes in terms of the amount of input to the algorithm.
1.9 Summary
Programs are means to organize and control the computers working
through sequences of instructions. Programmers are people who create
a sequence of instructions depending upon the requirement of the
application.
There are different categories of programming languages: Machine
Language, Assembly Language, High level languages.
Computers are used in different areas like in scientific application,
business application, and Artificial intelligence.
Programming is a form of problem-solving. It involves identifying the
problem, analyzing it, writing algorithm, writing the program for it, testing
the program and finally, writing a documentation for it.
Compiler is a program which translates a high level language program
into a machine language program.
An interpreter is a program which translates statements of a program
into machine code and executes it, one statement of the program at a
time.
The Algorithm is defines as “a step-by-step procedure to solve a given
problem”. A flow chart is a pictorial representation of an algorithm.
Performance of algorithm is measured in terms of the amount of data
the algorithm must process. We can measure the performance of an
algorithm by computing two factors: Space and Time Complexity.
1.11 Answers
Self-Assessment Questions
1. Programmers
2. Assembly
3. High
4. Operating System
5. World Wide Web
6. Common Business-Oriented Language
7. C
8. Modular
9. True
10. Compiler
11. True
12. Algorithm
13. Flowchart
14. Space complexity
Terminal Questions
1. Computers are used in different areas like in scientific application,
business application, Artificial intelligence etc. (Refer 1.3 for more detail)
2. Programming is a form of problem-solving. (Refer 1.4 for more detail)
Computers are strange in that they only understand a sequence of 1s
and 0s. High Level languages are more for human understanding and
thus make the task of programming much easier. (Refer 1.6.1 for more
detail)
In the execution of program two more system software plays important
role they are linker and loader, which are discussed below. (Refer 1.6.2
for more detail)
3. The Algorithm is defines as “A step-by-step procedure to solve a given
problem”. (Refer 1.7.1 for detail)
4. A flow chart is pictorial representation of an algorithm. (Refer 1.7 for
detail)
1.12 Exercises
Write Algorithm and draw flow chart for the following problem.
1. To find the area of triangle.
Area = 0.5 * b * h;
2. To find the largest of three number.
3. To calculate net salary of employee. Assume necessary data.
4. To find the simple interest.
Simple interest= (principle * time-period * rate-Of-Interest)/ 100
5. To find type of triangle when its three sides are given
If a, b and c are the sides of triangle then,
If all sides are equal, it is equilateral triangle
If any two sides are equal, it is isosceles triangle
If all the sides are different, it is acute triangle.