0% found this document useful (0 votes)
28 views

Unit 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Unit 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Unit-1

Planning the Computer Program: Concept of problem solving, Problem definition, Program design,
Debugging, Types of errors in programming, Documentation.
Planning the Computer Program
Problem Solving
Today, we use computers in every field for various purposes. But, we know that they cannot solve the problems all
by themselves. Furthermore, we have to give step by step instructions to the computer for solving the problem.
We can define problem-solving as a process of understanding the problem, designing an algorithm for it, and finally
implementing the solution to it.
Therefore, we can say that a successful problem-solving process depends on the following factors:
 Understanding the problem and defining it precisely.
 Designing a proper algorithm (solution) for it.
 Implementing the algorithm successfully.
When the problems are easy we can easily search out a solution. Whereas, complex problems require step by step
process to solve. Hence, this means that we have to apply problem-solving techniques to solve the problem.
Furthermore, this starts with finding a precise definition of the problem and ends with a successful solution.
Here, we will study understanding the problem in detail.
Understanding the Problem
It is very obvious that before finding the solution we should understand the problem well. Moreover, if we fail to
understand the problem we may end up with a useless solution for it. Hence, a wrong solution will not solve our
purpose of problem-solving. Therefore, we need to read the problem carefully and decide the different functions which
the solution will contain.
Moreover, we need to understand that what is the required output and how we can generate it. Besides, for proper
output, we surely need an input. The input can be single or multiple as per the problem. Hence, it is quite important to
maintain the necessary relationship between the input and the output.
Furthermore, we need to keep in mind that there should be all the number of inputs required to produce the output. At
the same time, the programmer should make sure that the number of inputs should be limited. Moreover, any
irrelevant input will result in consuming more space and time. Hence, unnecessary inputs should be avoided.
Therefore, we can say that spotting the minimum number of input for the correct output is an important point in
understanding the problem.
Important points in Understanding the Problem
Some of the important points that we should keep in mind while understanding the problem are as follows:
 Read the problem very carefully.
 Identify the functions that the solution (algorithm) should have.
 Identify the required output.
 Find a way to produce the required output.
 Draw a proper relationship between the input and output.
 Take all the necessary number of inputs.
 Avoid unnecessary inputs.
 Identify the correct number of the required input.
Further steps in problem-solving
After understanding the problem, the further steps are as follows:
Designing an algorithm
After understanding the relationship between input and output and the functionalities required we have to design an
algorithm. Furthermore, the algorithm should contain all the necessary functions to solve the problem. Moreover, it
should produce a proper output for every input.
Implementing the algorithm
After designing the algorithm we should implement and design a program to solve the problem. We can develop the
program using any programming language.
Evaluation
After developing the program we should run and test if it produces the correct output.

PROGRAM DEVELOPMENT STAGES

Program development includes the following stages:


PLANNING
 The Planning stage is the stage where programmers decide and define the tasks that should be performed by the
program.
 This involves identifying the problem, defining the problem in simpler terms, identifying the program requirements
(inputs, outputs the formulas needed), and finally, planning for the solution
PROGRAM DESIGN
 This stage deals with the flow of the program, the way it should produce output and gather inputs, the interface or the
working environment of the program, and how it should be used.
 In planning and designing the program, you need to have an understanding of the logic behind the programs
performance.
 You also need to be knowledgeable in the theory, algorithms, pseudo codes, and flowcharts.
CODING
 It is the process of expressing the fully detailed algorithm to a standard high-level programming language.
 This stage of program development requires following the rules of format and syntax (vocabulary, grammar and
punctuation.
 This stage requires an extensive knowledge in the programming language user will use.
 Coding is the act of actual writing of the computer program.
 It means generating the “source code” in the language of the programmer’s choice.
 A computer program is generated through the source code.
TESTING & DEBUGGING:
 The Testing Stage is where the programmer makes sure that the program performs the way it is intended.
 Programs are tested by running them and observing the output they produce.
 The process of correcting mistakes in a program is called debugging
Program Testing
 Program Testing is the stage in which the programmer runs their programs to discover if it is free from syntactical
and logical errors thus making it capable of doing what it was intended for.
 Testing a program requires three separate activities: desk checking, translation and debugging
Desk Checking
 Desk Checking Process of sitting in a desk and checking the source code, proofreading it for obvious
syntax errors as well as looking for logical errors which are not immediately detectable.
Translation
 Translation is the conversion of the source code to the internal instructions that the computer required.
 During translation, another computer program called the translator checks for and finds all syntax
errors which may be corrected once the computer issues diagnostic messages which inform the user of
the errors.
Debugging
 Debugging is the process of detecting, locating and correcting logic errors (bugs) by submitting a
translated program to the computer for execution and seeing what happens.
 For this purpose, valid test data must be administered to see how the program will fare in a similar
situation
Errors
Errors are the problems or the faults that occur in the program, which makes the behavior of the program
abnormal.
Programming errors are also known as the bugs or faults, and the process of removing these errors or bugs is
known as debugging.
These errors are detected either during the time of compilation or execution. Thus, the errors must be removed
from the program for the successful execution of the program.
Types of errors:
1. Syntax Errors
2. Logical Errors / Semantic errors
3. Runtime Errors
4. Linker error
5. Compilation Errors
6. Resource Errors
7. Interface Errors
Syntax errors:
Just like human languages, computer languages have grammar rules. But while humans are able to communicate
with less-than-perfect grammar, computers can’t ignore mistakes, i.e. syntax errors.
For example, let’s say the correct syntax for printing something is print('hello'), and we accidentally forget one of
the parentheses while coding. A syntax error will happen, and this will stop the program from running.
As our proficiency with programming language increases, we will make syntax errors less frequently.
The easiest way to prevent them from causing our problems is to be aware of them early.
Many text editors or IDEs will come with the ability to warn us about syntax errors at the time of writing.
A syntax error occurs when the code given does not follow the syntax rules of the programming language.
Examples include:
 misspelling a statement, eg writing pint instead of print
 using a variable before it has been declared
 missing brackets, eg opening a bracket, but not closing it
A program cannot run if it has syntax errors. Any such errors must be fixed first.
Example:
#include <stdio.h>
int main()
{
a = 10; //
printf("The value of a is : %d", a);
return 0;
}

Syntax errors are due to the violation of the rules of a specific programming language. Syntax errors are thrown by
the compilers.
Logical errors:
Due to mistakes in the algorithm or program design or wrong formula or wrong logic which are not easily
detected.
Logical errors are also called Semantic errors. The statement has no syntax errors, so it will compile and run
correctly. However, it will not give the desired output as the logic is not correct.
Let us take an example.(with C++ programming Language)

#include<iostream>
using namespace std;
int main()
{
int n = 5; // To compute factorial of n
int factorial;
int i = 1;
while (i <= n)
{
factorial = factorial * i;
i++;
}
cout << "The Factorial of " << n << " is " << factorial << endl;
return 0;
}
Output:

#include<iostream>
using namespace std;
int main()
{
int n = 5; // To compute factorial of n
int factorial=1; // Initialize the product to 1
int i = 1;
while (i <= n)
{
factorial = factorial * i;
i++;
}
cout << "The Factorial of " << n << " is " << factorial << endl;
return 0;
}
Output:

Logic errors can be caused by the programmer due to :


 incorrectly using logical operators, eg expecting a program to stop when the value of a variable reaches 5,
but using <5 instead of <=5
 incorrectly using Boolean operators

 unintentionally creating a situation where an infinite loop may occur


 incorrectly using brackets in calculations
 unintentionally using the same variable name at different points in the program for different purposes
 using incorrect program design
Unlike a syntax error, a logic error does not usually stop a program from running. The program with a logic error
will run, but not function as expected.
One more Example():
#include <stdio.h>
int main()
{
int i,sum=0;
int k=1;
for(i=1;i<=10;i++);
{
sum=sum+k;
k++;
}
printf("The value of sum is %d", sum);
return 0;
}
Output:(Which is unexpected)

#include <stdio.h>
int main()
{
int i,sum=0;
int k=1;
for(i=1;i<=10;i++)
{
sum=sum+k;
k++;
}
printf("The value of sum is %d", sum);
return 0;
}
Output:

This error generated if and only if written code is not understandable format to the compiler.
Ex:
main()
{
int x, y, z;
x + y = z; //semantic error
}
Runtime errors
Runtime errors are errors that occur while executing the program.
This implies that the program has no syntax errors.
Some of the most common run time errors our program may encounter are −
 Infinite loop
 Division by '0'
 Wrong value entered by user (say, string instead of integer) etc.
An example is writing a program that tries to access the sixth item in an array that only contains five items using C
programming Language.

#include <stdio.h>
int main()
{
int i;
int ary[]={37,42,80,55,40};
printf("Elements of the array are:\n");
for(i=1;i<=4;i++)
{
printf("%d\n",ary[i]);
}
printf(" the 6th Elements of the array is:\n");
printf("\n%d",ary[6]);
return 0;
}
Output

Arithmetic Error is also a runtime error


Example 2:

#include <stdio.h>
int main()
{
int a=2;
int b=2/0;
printf("The value of b is : %d", b);
return 0;
}
Linker error
Linker is a program that takes the object files generated by the compiler and combines them into a single
executable file. Linker errors are the errors encountered when the executable file of the code cannot be generated
even though the code gets compiled successfully.
This error is generated when a different object file is unable to link with the main object file.
This may be due to wrong function prototyping, incorrect header files.
Most frequent linkererror is writing Main() instead of a main() method.
Example
#include <stdio.h>
int Main()
{
int a=78;
printf("The value of a is : %d", a);
return 0;
}
These errors are generated after compilation we link the different object files with the main’s object .

Compilation Errors:
Compilation is the process of converting a high-level coding language into a lower-level language that can be
better understood by the computer. Compilation errors occur when the compiler isn’t able to properly transform
the code into the lower-level code. This prevents the software from being launched or tested.
Examples: syntax errors such as omitting a required semicolon, using an undeclared variable, using a keyword for
the name of a variable."
In our syntax error example, if we were compiling print('hello', the compiler would stop and tell us it doesn’t know
how to convert this into a lower-level language because it expected a ) after the '.
Compilation happens across all files of the project at the same time. If we’ve made lots of changes and see lots of
compiler warnings or errors, it can be very daunting. By running the compiler often, we will get the feedback we
need sooner, and we will more easily know where to address the issues.
6. Resource errors
Sometimes, a program can force the computer it’s running on to attempt to allocate more resources (processor
power, random access memory, disk space, etc.) than it has. This result in the program becoming bugged or even
causes the entire system to crash.
7. Interface Errors
Interface errors occur when there is a disconnection between how we meant our program to be used and how it is
actually used.
Most things in software follow standards. If input our program receives doesn’t conform to the standards, we
might get an interface error.
In python when database connection fails for some reason, MySQLdb will raise an InterfaceError. It is noted
that interface Error only get raise when there is internal problem in connection to the database, MySQLdb will
not raise Interface Error because of wrong database name or password.
For example, an interface error might happen if we have an API that requires specific parameters to be set but
those parameters are not set.
DOCUMENTATION:
 It is the detailed description of a program’s algorithm, design, coding method, testing and proper usage.
 Documentation usually includes the necessary information about the requirements of the program – the
operating system, and hardware requirements needed for the program to run.
 Documentation also contains technical information such as where and who created the program, who contact
when there’s a problem with the program and instructions on the use and maintenance of the program.
Any written text, illustrations or video that describe a software or program to its users is called program or
software document.
User can be anyone from a programmer, system analyst and administrator to end user. At various stages of
development multiple documents may be created for different users. In fact, software documentation is a critical
process in the overall software development process.
In modular programming documentation becomes even more important because different modules of the software
are developed by different teams. If anyone other than the development team wants to or needs to understand a
module, good and detailed documentation will make the task easier.
These are some guidelines for creating the documents −
 Documentation should be from the point of view of the reader
 Document should be unambiguous
 There should be no repetition
 Industry standards should be used
 Documents should always be updated
 Any outdated document should be phased out after due recording of the phase out
Advantages of Documentation
These are some of the advantages of providing program documentation −
 Keeps track of all parts of a program or software
 Maintenance is easier
 Programmers other than the developer can understand all aspects of program
 Improves overall quality of the program
 Assists in user training
 Ensures knowledge de-centralization, cutting costs and effort if people leave the system unexpectedly
Types of Documents
Program or software can have many types of documents associated with it. Some of the important ones include −
 User manual − It describes instructions and procedures for end users to use the different features of the
program.
 Operational manual − It lists and describes all the operations being carried out and their inter-dependencies.
 Design Document − It gives an overview of the software and describes design elements in detail. It
documents details like data flow diagrams, entity relationship diagrams, etc.
 Requirements Document − It has a list of all the requirements of the system as well as an analysis of
viability of the requirements. It can have user cases, real life scenarios, etc.
 Technical Documentation − It is a documentation of actual programming components like algorithms,
flowcharts, program codes, functional modules, etc.
 Testing Document − It records test plan, test cases, validation plan, verification plan, test results, etc. Testing
is one phase of software development that needs intensive documentation.
 List of Known Bugs − Every software has bugs or errors that cannot be removed because either they were
discovered very late or are harmless or will take more effort and time than necessary to rectify. These bugs
are listed with program documentation so that they may be removed at a later date. Also they help the users,
implementers and maintenance people if the bug is activated.
MAINTENANCE
The final stage in programming is maintaining or updating the program. This is the stage where the programmer is
tasked to keep the program running smoothly and updated with the developments and changes in the field where it
is used.
Program maintenance is the process of modifying a software or program after delivery to achieve any of these
outcomes −
 Correct errors
 Improve performance
 Add functionalities
 Remove obsolete portions
Despite the common perception that maintenance is required to fix errors that come up after the software goes live,
in reality most of the maintenance work involves adding minor or major capabilities to existing modules.
For example, some new data is added to a report, a new field added to entry forms, code to be modified to
incorporate changed government laws, etc.
Types of Maintenance
Maintenance activities can be categorized under four headings −
 Corrective maintenance − Here errors that come up after on-site implementation are fixed. The errors may
be pointed out by the users themselves.
 Preventive maintenance − Modifications done to avoid errors in future are called preventive maintenance.
 Adaptive maintenance − Changes in the working environment sometimes require modifications in the
software. This is called adaptive maintenance. For example, if government education policy changes,
corresponding changes have to be made in student result processing module of school management software.
 Perfective maintenance − Changes done in the existing software to incorporate new requirements from the
client is called perfective maintenance. Aim here is to be always be up-to-date with the latest technology.
Maintenance Tools
Software developers and programmers use many tools to assist them in software maintenance. Here are some of
the most widely used −
 Program slicer − selects a part of the program that would be affected by the change
 Data flow analyzer − tracks all possible flows of data in the software
 Dynamic analyzer − traces program execution path
 Static analyzer − allows general viewing and summarizing of the program
 Dependency analyzer − assists in understanding and analyzing interdependence of different parts of the
program

You might also like