Programming

4
1219

Programming

 

 

Introduction

 

A computer simply performs three functions of receiving data, processing it using various computations and generating results. These functions are accomplished by giving the computer a program consisting of a sequence of statements called program segment.

 

Programming the computer the way you want it is fun and professional. The user has to identify and define the problem to be solved and the solution path. In essence, if you cannot in principle solve the problem, the computer certainly cannot; it can only follow precise instructions given by the user in the form of a program.

A systematic approach of problem solving using a computer is generally as follows:

  • Statement of the problem Development of the mathematics of the solution.
  • Drawing of flowcharts indicating the sequence of operations to be performed
  • Writing the program.

What is Programming?

 

Programming is the process of writing a program.

 

Computer program

A computer program is a series of instructions given to the computer at a particular time to solve a problem. It is usually written in a particular programming language, and named according to the language used in writing it.

Who can be a programmer?

You might be wondering just who can become a programmer (probably because you’ve read the title of this section, and it got you thinking). The clichéd thing to do would be to say “anyone!”, but I won’t do that, because it’s just not true. There are a few traits which might indicate that the person would be

The following are qualities of a good programmer:

  • Logical
  • Patient
  • Analytical
  • Problem solver
  • Must be able to work in teams.

 

* Actually, males and females make equally good programmers. I just said that to address the gender disparity which exists in the programming world; it’s true that there are currently more male programmers than female, which is strange given that one of the first ever programmers (Ada Lovelace) was female. Besides, male programmers are especially eager to encourage more females to take up the profession, since they (the male programmers) traditionally have no social lives whatsoever. Or perhaps that’s an unfair generalization, and it’s just me who has no social life.

As you can see, it does take a certain type of person to be a successful programmer (in my humble opinion). If you’re not logical, you’ll have trouble organizing and constructing complex programs. If you’re not fairly intelligent, you won’t be able to break a task down into the necessary individual steps. If you’re not patient, you’ll deliberately destroy your computer long before you manage to finish all but the simplest programs. If you don’t enjoy intellectual challenges, you’ll hate every minute of programming. If you’re not a Star Trek fan, you’ll miss out on a large percentage of the conversation your fellow programmers will have (I’m not saying that’s a bad thing). Finally, if you’re not perceptive, you won’t notice that the twenty consecutive hours you’ve spent in front of your computer have depleted your body’s energy resources to a near-fatal level, and you’ll die whilst designing an icon for your new application program (tip: experienced programmers avoid this problem by designing the icon before writing the program).

 

Properties of a Good Program

A good programming practice is needed to write a good program. Program development has to follow problem definition, analysis, modeling, algorithm/flowchart design, coding and documentation. The following properties are required for developing a good program is given below:

 

  • Program Correctness: a good program must be able to solve the intended problem with relevant results. The output (result) must be readily available for testing with assumed or calculated results using real or dummy data.

 

  • Documentation: every module or procedure must be preceded with comments on brief explanation of the module in the program. These make programs easy to read and understand by other users that may want to modify or improve on the program.

Complete documentation of the whole program is also necessary to give details of the input, output, processing tasks and manual guide.

 

  • Robustness and Scalability: programs that can survive various unexpected events are said to be robust and those that can easily be upgraded are scalable. They are sometimes called safe or defensive programs because of the way they are written, the choice of variable names, surviving incorrect data etc.

 

  • User Interface: a good look or design of the medium of interaction of the user and the program must be well taken care so as to have a good user interface. This is the part of the program that performs the dialog aspect of the program with the user and must be easy and friendly to use.

 

  • Program Style: the programming language rules are to be adapted in writing programs. You should not do what is not to be done with the programming language in question.

 

  • Use of Tools and Library Functions: programming languages have special tools and libraries that can assist in developing computer programs. Some editors are also used to enhance the development of programs.
  • OPPORTUNITY FOR UPGRADE
  • EFFICIENT
  • A GOOD PROGRAM MUST BE DIRECTED AT SOLVING PROBLEMS.
  • PROVIDE HIGH BENEFIT(both tangible and intangible)

 

TEAM ROLES RESPONSIBLE FOR BUILDING AN ENTERPRISE APPLICATION

By enterprise application, we mean a large software project. The following are team members responsible in designing an enterprise application:

  1. System analyst: this is software professional that is skilled at analyzing a system. They carry out the following:
  • Identifies how technology can improve business processes.
  • Designs the new business process model (a model is a diagrammatical representation of a program.
  • Designs the information system
  • Ensures that the system conforms to the organizations standard.
  1. Business analyst: this is a professional that:
  • analyses the key business aspects of the system.
  • Identifies how the system will provide business value
  • Design new business process and policies
  1. Infrastructural analyst: this is a professional that has a good understanding of hardwares and how they function together with the software. They have networking and database administration skills.
  • Ensures that the system conforms to infrastructural standard
  • Indentifies the infrastructural changes needed to support the system
  1. Project manager: this is a professional skilled at managing the team of analyst, programmers, technical writers and other specialists. They develop and monitor the project plan, assign resources and makes sure that the project is completed with the right quality and the right specification within the budget.
  2. Change management analyst: they are skilled at developing and executing a change management plan. They also develop and execute a user training plan.

 

 

 

PROGRAM DEVELOPMENT LIFE CYCLE (PDLC)

 

This shows the stages involved in designing a standard enterprise application. It involves the following:

  • Planning
  • Analysis
  • Designing
  • Implementation
  • Training
  1. PLANNING: About 70% of programs fail due to lack of planning. This is because most programs developed do not carry out their function hence they are not used even after spending millions in designing them.

Before even planning, there exists a problem. This problem may exist in any of the sectors e.g banking, aviation, agricultural, academics, e.t.c take for instance in a school library, where there are categories of books based on the authors and book titles. A librarian wishing to locate a book may be delayed due to inability to quickly search for the book and the location. Identifying the students that borrows a book may be difficult.

Therefore there is need to design a library information system to solve the above problem. It starts with

  • project initiation: begins when someone in the organization(project sponsor) identifies the business value that can be gained from using the information system.
  • The system request is produced and submitted to approval committee (the approval committee can be an information system steering committee or decision making body).

The approval committee reviews it and determines whether to investigate the proposal. If true, they can now demand for a feasibility analysis.

  • The feasibility analysis plays an important role in deciding whether to proceed with the information system development project. It contains :
  • Technical, economical and organizational pros and cons of developing the systems. It also provides the advantages of investing in the system.

 

SYSTEM REQUEST: This includes four elements: project sponsor, business needs, functionality and expected value.

Note: the business need tells why the information system should be built and why fund the project.

Functionality tells of what features the new system will include e.g  the ability to collect customers orders over the web.

The expected value shows the tangible and intangible reasons for building the system.

 

SAMPLE OF A SYSTEM REQUEST

Project name: internet sales

Project sponsor: your name and position

Department: marketing

Phone:

Email:

Business need: to increase cd sales by reaching a new market i.e internet customers

Functionality: using the web, customers should be able to complete a purchase of our products that we sell (e.g tapes, poster, books) customers should be able to :

  • Search through a list of products we sell.
  • Place an order for one or more product
  • Receive immediate credit approval
  • Receive confirmation that their order have been placed and an expected delivery date
  • Receive the order in a timely manner.

EXPECTED VALUE:

TANGIBLE BENEFIT

  • A N3 million to N5million increase in annual sales after the business has been operating for 2 to 3 years

INTANGIBLE:

  • Improved customer satisfaction
  • Improved recognition of the cd selection brand name that may have increase traffic in our traditional stores.

SPECIAL ISSUES OR CONSTRAINTS

  • System should be in place for holiday shopping season next year.

ASSIGNMENT: Think about your system college and choose an idea that could improve  student satisfaction with the course enrolment process . currently, can student enroll for classes from any where? How long does it takes? Are directions simple to follow? Is online help available?

Next think about how technology can help support your idea. Would you need completely new tech? can the current system  be used.

Create a system request that you could give to the admin that explains the sponsor, business need, functionality and potential value of the value of the project . include any constraints or issues that should be considered.

 

  1. Feasibility analysis: A more detailed business case a more detailed business case to better understand the opportunities and limitations with the proposed project.

3 techniques:

Technical feasibility; can we build it?

  • Familiarity with application
  • Familiarity with technology
  • Project size

Note: less familiarity generates more risk and the size as well also generates risks.

  1. Economic feasibility, should we build it?(cost- benefit analysis)
  • Development cost
  • Annual opportunity cost
  • Annual benefit(cost savings and revenues)
  • Intangible cost and benefits.

iii.        ORGANIZATIONAL FEASIBLITY: if we build it, will they use it?

Project champion; senior management; users, other stakeholders.

  1. iv. ECONOMIC FEASIBIITY: includes assessment of financial impacts in four categories:

Development cost: tangible expenses that are incurred during the construction of the system. e.g Dev team salary, consultant fee, dev training, hardware and software, vendor installation, office space and equipment, data conversion cost.

Operational cost: variable cost e.g software upgrades, software licensing fees , hardware repairs, hardware upgrade, operational team salaries, communication charges, user training.

NOTE: ASSIGNING VALUES TO COSTS AND BENEFITS:

You can assign values to cost by checking past projects, industry reports, meeting consultants with experience.

INTANGIBLE BENEFIT: Sometime it is difficult to quantify customer satisfaction but you can imagine the cost of the phone calls and complaints if the system fails, such can be measured.

BENEFITS:                                        year 1

-increased sales                                                500,000

-improved customer service (b)                         70,000

-Reduced inventory costs                    68,000

TOTAL BENEFITS:                                                  638,000

DEV COST:

2 servers@125,000                              250,000

PRINTER                                             100,000

SOFTWARE LICENSES                      34,825

Server software                                                10,945

Dev labour                                           1236,525

Total dev cost                                      1632,295

OPERATIONAL COST

Hardware                                             54000

Software                                              20,000

OPERATIONAL LABOUR                 111,788

185,788

TOTAL COSTS                                                           1,818,083

TOTAL                                                                        (1180083)

FROM THE ABOVE,IT CAN BE SEEN THAT THE PROJECT FOR THE FIRST YEAR IS NOT FEASIBLE BECAUSE THE  TOTAL COST OF BUILDING THE PROJECT OUTWEIGHS THE TOTAL BENEFIT BY N1,180,083

(B)       CUSTOMER SERVICE NUMBERS HAVE BEEN BASED ON REDUCED COSTS FOR CUSTOMER COMPLAINTS PHONE CALLS

METHOD 2 (DATA CASHFLOW)

2000(N)                     2001(N)                                   TOTAL

BENEFIT

Increased sales                                      12000                          12,555                                    24555

Improved customer service                    7,500                             1000                                    8500

Reduced inventory cost                                     6,000                             2000                                    8000

TOTAL BENEFITS:                             25500                          15,555                         41055

DEV COSTS:

2 SERVERS @ 125,000                                  250,000                                          –                            250000

PRINTER                                             100,000                                          –                            100000

SOFTWARE LICENSES                      34,825                                            –                           34825

SERVER SOFTWARE                            10,945                               –                          10945

DEVELOPMENT  LABOUR                   10000                           5000                                   15000

TOTAL OPERATIONAL COST          405770                                        5000                                    410770

TOTAL COST                                                816540                                        5000                                    821540

TOTAL                                               (796040)                      10,555                         (780485)         

 

N.B: RETURN ON INVESTMENT: a calculation listed somewhere on the spreadsheet that measures the amount of money an organization receives in return for the money it spends. A high return on investment (ROI) results when benefit far outweighs the cost.

MATHEMATICALLY:

ROI=                            TOTAL                *   100

TOTAL COST

Note: ROI is always represented in %

FROM THE ABOVE, ROI=

-780485   X    100

821540

ROI= -95%

NOTE:TO TAKE INTO CONSIDERATION THE FUTURE VALUE OF MONEY,THE NPV(NET PRESENT VALUE IS CALCULATED:

NPV=                       TOTAL

(1+R)n  

Where r=interest rate,               n= nos of years

  1. Analysis: This deals with analyzing the program. If the system is already in existence and needs modification, the analyst can identify any needed improvement that needs to be reflected in the new system e.g if the program earlier designed lacked printing features, in the TO-BE (new system) it must reflect this. As compared to the AS-IS (old system).The system analyst would also gather information using techniques like:

Step 1: information gathering process

  • Interview: Here, the system analyst can book an appointment with the organisation to which he is to gather the information and gets there to ask series of questions. It can be one on one or panel interview. The system analyst must know the difference between open and closed ended questioning method. An open ended question is a question that allows the user to express his mind further while a closed ended question is a question that requires either yes or no from the interviewee and no further responses.

 

  • JAD (JOINT APPLICATION DEVELOPMENT): This is a system where the facilitator gathers all respondents in a room and they are all subjected to a networked computer. Each respondent can type in his opinion. At the end of the session the facilitator gathers all the responses and compiles them. This method is normally used when urgent information is needed. But it is costly to setup.
  • Questionnaire: The system analyst designs sets of question about the system in a paper form and gives it to the respondents to be filled. Here the analyst must be skilled in applying open or closed ended questionning method.
  • Direct observation: here the analyst directly goes to the site and sees things for himself.

 

After gathering the required information, the system analyst can now design the structure or model of the TO-BE system. He designs the flow chat, Data flow diagram, Entity relationship diagram e.t.c just like an architect designs the structure of a building and this structure guides him in the building process. So also is the program structure for a system analyst.

  1. Design: Here, the programmer can start designing the program by using programming languages that is appropriate. After writing the code, he has to test and compile this code, check for any error, debug for error until the program runs.

4.Implementation: This program after being error free can now be implemented, packaged and ready for use.

5.Documentation: help on how to use the program and the minimum required hardware and software needed to run the program is provided in a written form.

Note: EULA (End user license agreement) which is a legal agreement between the software designer and the end user on the use of the software is also established. Any breach of contract will result into court case.

  1. Training: The team can now train who is to use the software and training can be done using different method. The method to be used depends on the number of users and the nature of the program.

 

PROGRAM STRUCTURES

As programs become more complex, a flowchart is most helpful in planning, designing, and structuring a program. A flowchart is a graphical representation of an algorithm.

An algorithm is a step-by-step method for solving a problem.

 

Flowcharts can be divided into two: System flowchart and Program flow chart.

 

Describing a Program, Using Algorithms and Flowcharts

 

When you write a program, that program must perform some task. It might be a real-world business task, such as managing payroll or processing orders. Or it might be a program that provides entertainment, such as a game. In either case, the program will perform a large number of tasks, and for each of them, you must provide a very specific set of instructions.

Before you begin to write code, you need a clear understanding of the tasks the program must perform: the requirements and the steps it should take to perform them. The step a program must take to perform a task is known as the program’s flow. You can design a program’s flow by using algorithms and flowcharts.

 

What is algorithm?

 

An algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function.  A set of instructions or procedures for solving a problem.

 

 Writing Algorithms Using Pseudo code

An algorithm is a step-by-step description of a procedure. Writing an algorithm allows you to think about the logic of a program without worrying about the syntax of the programming language.

 

You can think of an algorithm as being like a recipe:

  1. Put 1 tablespoon of oil in a frying pan.
  2. Heat the oil on the stove at low temperature.
  3. Break three eggs into a bowl.
  4. Beat the eggs with a whisk.
  5. Add cheese.
  6. Add seasonings.
  7. Add the egg mixture to the frying pan.
  8. Cook on both sides.

You write an algorithm by using pseudo code. As the word suggests, pseudo code is like code but different. In fact, pseudo code is a description of the program flow, written in the language you speak. When you write pseudo code, you usually keep the sentences short and to the point.

You clearly define each step that must be taken to perform the task. For example, suppose you need to write a program that accepts a person’s hourly wage and calculates the person’s pay. For the sake of this example, let’s assume a withholding rate of 20%. The algorithm for this procedure is as follows:

  1. Declare variables for Wage, HoursWorked, GrossPay, WithholdingAmount, and NetPay.
  2. Declare a constant for WithholdingPercent and set it equal to 20%.
  3. Input Wage.
  4. Input HoursWorked.
  5. Set GrossPay Wage * HoursWorked.
  6. Set WithholdingAmount GrossPay * WithholdingPercent.
  7. Set NetPay GrossPay WithholdingAmount.
  8. Output NetPay.

There are different ways you could write this pseudo code. For example, you could write step 5 as “Multiply Wage by HoursWorked and store the result in GrossPay.” However, the point of writing an algorithm is to describe the program’s logic, not to worry about language.

 

 

Example 1

Let’s write an algorithm to calculate the sum of two numbers

Step 1 : Start

Step 2 :enter X value

Step 3 :enter Y value

Step 4 :Z = X+Y

Step 5 :print Z value

Step 6 :End

 

Example 2

 

Write an algorithm to calculate the mean of two numbers given.

 

Step 1: start

Step 2 :enter X value

Step 3 :enter Y value

Step 4 :Z = X+Y

Step 5 :mean= Z/2

Step 6 :print mean

Step 7 :end

 

Example 3

An algorithm to calculate the area of a rectangle with given length.

If the length of edge is defined as negative, it will be redefined.

 

 

Let’s define Variables:

First edge length of rectangle: a,

Second edge length of rectangle : b,

Area of rectangle: area

 

Algorithm:

S1 : start

S2 : enter a value

S3 : if a<0 repeat the second step

S4 : enter b value

S5 : if b<0, repeat the fourth step

S6 : area = a*b

S7 : print area value

S8 : end

Using Flowcharts

A flowchart is a graphical representation of an algorithm. These flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language. Often we see how flowcharts are helpful in explaining the program to others. Hence, it is correct to say that a flowchart is a must for the better documentation of a complex program.

A flowchart is a graphical representation of a program’s logic. You can draw a flowchart on paper or using a flowcharting tool such as Microsoft Visio. There are even flowcharting objects available in Microsoft Office.

 

The following are some guidelines in flowcharting:

  1. In drawing a proper flowchart, all necessary requirements should be listed out in logical order.
  2. The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart.
  3. The usual direction of the flow of a procedure or system is from left to right or top to bottom.
  4. Only one flow line should come out from a process symbol.

or

  1. Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

 

  1. Only one flow line is used in conjunction with terminal symbol.

 

  1. If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication.
  2. Ensure that the flowchart has a logical start and finish.
  3. It is useful to test the validity of the flowchart by passing through it with a simple test data.

 

PART II: Example of a flowchart:

Problem 1: Write an algorithm and draw the flowchart for finding the average of two numbers

Algorithm: 

Input: two numbers x and y

Output: the average of x and y

Steps:

  1. input x
  2. input y
  3. sum = x + y
  4. average = sum /2
  5. output average

PART III: An exercise

Problem 2: Write an algorithm for finding the area of a rectangle

Hints:

  • define the inputs and the outputs
  • define the steps
  • draw the flowchart

 

Flow chart gives the logical flow of the solution in a diagramatic form.

 

 

 

 

Arrows connect the shapes to define the flow. The oval is a terminator and marks the beginning and end of the flow. The parallelograms are used to represent input and output. The rectangles are used to represent a process.

 

 

For example

Example 1: Finding the sum of two numbers.

Variables:

A: First Number

B: Second Number

C: Sum (A+B)

Algorithm:

Step 1 – Start

Step 2 – Input A

Step 3 – Input B

Step 4 –Calculate C = A + B

Step 5 – Output C

Step 6 – Stop

 

 

Example 2: Find the difference and the division of two numbers and display theresults.

 Variables:

N1: First number

N2: Second number

D : Difference *

V : Division

 

Algorithm:

 

Step 1: Start

Step 2: Input N1

Step 3: Input N2

Step 4: D = N1 –N2

Step 5: V = N1 / N2

Step 6: Output D

Step 7: Output V

Step 8: Stop

When you draw a flowchart, you should use industry-standard shapes to represent each step in the process. You usually draw the flow from top to bottom or from left to right.

 

Draw a flowchart to find the largest of three numbers of A, B, and C.

 

 

Draw a flowchart to find the sum of numbers from 1 to 100

The algorithm is given below:

 

Algorithm:

S1 : Start

S2 : enter sum as zero

S3 : enter counter as zero

S4 : add counter to sum

S5 : add 1 to counter

S6 : if counter <100 then go to S4

S7 : print sum

S8 : End

 

 

 

 

 

 

 

Self Assessment Exercise

  1. Which of the following is a step-by-step description of a process written in pseudo code?

(a) algorithm

(b) flowchart

(c) control of flow

 

  1. Which of the following is a graphical depiction of a program’s flow?

(a) algorithm

(b) Control of flow

(c) Flowchart

 

Definition (PSEUDO CODE)

A Pseudo code is logical representations of an algorithm using third generation language (3 GL) style such as DO, WHILE, IF-THENELSE, etc. Pseudo code is also called structured English since it is English- like in structure. It is essential to know that a Pseudo code is not directly executable on a computer except it is transformed into a high- level language code.

 

Machine Language

 

Every computer has its own machine language. Instructions to the computer are given in machine language since this is the only language computer actually understands. The machine language varies from machine to machine which is a function of the hardware of the computer. Programs written in machine language are only good for that particular machine.

 

The machine language is a low level interface, natural to the hardware of the computer. The instructions are usually represented by binary numbers, that is, the communication symbols or sequence of instructions consist of 0’s and 1’s otherwise known as the binary digit (BIT).

Since the machine language depends on the particular computer model, it is said to be machine dependent. The early days of computer programming was almost exclusively machine language programming. The difficult nature of writing in machine language and the machine dependent nature which is very involved and detailed led to the development of symbolic languages and later higher level languages.

 

Symbolic Languages

Arising from the machine language difficulties, is the development of a higher level up the ladder (hierarchy) of programming languages called assembly languages. Here the sequence of 0’s and 1’s are replaced with symbols, so that instructions can be given in symbolic codes called mnemonics.

 

The symbolic language is a middle level language between the machine language and high level languages. The language adopts mnemonic codes to represent machine instructions. The uses of mnemonic codes imply that mnemonic names are used for operators, addresses and instructions. Ordinarily, the computer does not understand these codes until they are translated to machine language using the appropriate translator.

 

Symbolic language is largely machine dependent just like machine language. An example of symbolic language is the Assembly language. We use Assembler to translate Assembly language to machine language for the understanding of the computer.

 

We can define Assembler as a machine language instruction or program that translates symbolic instructions such as Assembly language instructions into machine language instruction. The difficulty in understanding, the dependence of the language on the machine model and peculiarity of the mnemonics codes posed a serious disadvantage to the programmer. This necessitated the introduction of high-level languages because the programmer must be concerned with various details and complex sequence of instructions to be able to write symbolic language.

 

 

High Level Languages

 

High level language introduces the use of “almost English” language in writing computer programs which are also known as problem oriented languages.

 

Examples are FORTRAN, COBOL, PASCAL, C, Java,VB.NET,C-SHARP, C++, python, etc.

 

BASIC : (Beginners All Purpose Symbolic Instruction Code) A programming language, or more accurately a family of programming languages since there are many versions of BASIC. The term stands for Beginner’s All-purpose Symbolic Instruction Code, which sounds technical but really isn’t: it’s for beginners, it’s all-purpose rather than being designed for a specific type of programming (quite a few languages are designed for just one type of programming, like business programming or scientific programming), and it’s a “symbolic instruction code” which just essentially means that it’s a programming language.

As its name implies, any version of BASIC tends to be good for those who are just starting to program. For that same reason, BASIC tends to have a bad reputation amongst “serious” programmers, for being “too simple” or inflexible. Of course, the real reason they’re annoyed is that BASIC makes it even easier for people to take up programming, so there’s more competition for all the fabulous software products programmers create.

Ada: A programming language, sometimes with a number after the name (e.g. Ada95). Used commonly for defense applications (particularly in the UK). A fairly common choice as a first language in university computer science courses (again, particularly in the UK). Named after Ada Lovelace, a very clever lady who was one of the first ever programmers (I told you that gender had nothing to do

C: A very popular programming language, created by Dennis M. Ritchie. C is a very compact and quite easy to learn language, and is an excellent choice for those intending to make a career out of programming. It is an especially good first language, since you can then move on to any of various object oriented versions of C, or other fairly C-like languages such as Java.

C++ : A programming langauge which is an object oriented version of C, and which was created by Bjarne Stroustrup. The modern language of choice for Windows and Mac OS application development.

 

COBOL – (Common Business Oriented Language)as its name implies, COBOL was designed to be used for writing business programs. It was very popular during the 1960s and 70s, but is now seen as an essentially dead language.

 

FORTRAN – Formula Translation

Also “Fortran” (not all in capital letters). FORmula TRANslation; a programming language. FORTRAN is a programming language designed to be used for writing scientific and numerical programs. Still in use, although not really a mainstream language.

Java A programming language which is object oriented and can run on many different computers without needing to be re-compiled for each one. Very popular at the moment, but can be slow in comparison to other languages.

  • JavaScript A scripting language used within web pages to add basic interactivity and so on. A completely different language from Java, despite the similar name. Often confused with Java by those who don’t know the difference.

Perl A programming language originally created for Unix computers. Very powerful for manipulating text, and very popular for writing programs to help run web sites.

PROLOG PROgramming in LOGic; a programming language. PROLOG was the first of many languages designed to use so-called “logical programming” techniques. The basic idea is that you define a set of facts, then define a goal, and the computer tries to get to the goal using the facts you’ve defined.

PASCAL – Named after French mathematician Blaise Pascal

The language use English like phrases to represent computer instructions (codes) in a way that resemble programmers thinking process using English like expressions. The language is procedure oriented rather than machine oriented. Programs written in this type of language can, with possible minor modifications, run on different machines as long as there is appropriate translator/compiler.

 

TRANSLATORS AND COMPILERS

A translator is a machine language program that translates source codes written in either symbolic or high level language to machine language program known as the object language. They can also be referred to as compiler languages and are almost machine independent and very easy to use. If the source program (source code) is a high level language program such as FORTRAN, PASCAL, etc., the translator that produces the object code in machine understandable form is called a Compiler.

 

A compiler is a special program which translates programs written in high-level language into machine language.

 

In more detail, the compiler (e.g. BASIC, FORTRAN compiler, PASCAL compiler, etc.) reads the source code and generates the machine code (object code), and saves it unto disk file. When the program is to be executed, the computer simply loads the object code into the memory and executes it.

 

 

 

An interpreter, a kind of translator such as BASIC, is required to translate the source program to machine understandable form.

 

 Interpreter reads the source program directly, line by line, starting from the beginning of the source program each time it is to be executed and generates machine codes necessary to carry out the instructions as they proceed through the program, without saving it onto disk.

 

If the source program is a low level language (Assembly language), the translator that produces the object code in machine understandable form is the Assembler. It must be noted that original program is called the source program, and its translation is called the object program. It is also important to remember that a high/low level language program is first translated into machine language instructions before the computer can actually executes them.

Tutor Marked Assignment

  1. Explain the following terms

(a) Programming Language        (b) Machine Dependence       (c) Object Code (d) Source Code

  1. State five properties of a good program. Which of these properties is most important and why?
  2. State possible errors encountered during program compilation
  3. Distinguish between Machine Language and Symbolic Language

 

BUGGS AND DEBUGGING

Program Process and Errors

There are general violations of the rule of programming or pitfalls of computer arithmetic that are referred to as Errors or Program Errors or Bugs.

 

A bug is simply referred to as an error that occurs during programming while debugging on the other hand is the process of correcting an error in a program.

 

Debugging is an essential part of any development project because it helps you find errors in code and in logic. Some Compilers have some sophisticated debugger built right into the development environment.

In designing a computer program, there is need to properly analyze the program in other to design a program that will perform desired expectation.

 

 Understanding Types of Errors

The errors caused by a computer program (regardless of the language in which the program is written) can be categorized into three major groups: design-time errors, runtime errors, and logic errors.

 

  • Correcting Design-Time Errors

Design-time errors, which are the easiest type of error to find and fix, occur when you write a piece of code that does not conform to the rules of the language in which you’re writing. They are easy to find because some compilers tells you not only where they are but also what part of the line it doesn’t understand. Design-time errors, also called syntax errors, occur when the compiler cannot recognize one or more statements that you have written. Some design-time errors are simply typographical errors (e.g., a mistyped keyword). Others are the result of missing items (e.g., undeclared or untyped variables).

 

A program with as few as one design-time error cannot be compiled and run; you must locate

and correct the error before you can continue.

  • Understanding Runtime Errors

Runtime errors are harder to locate than design-time errors because compiler does not give you any help in finding an error until it occurs in a program. Runtime errors occur when a program attempts something illegal, such as accessing data that does not exist or a resource to which it does not have the proper permissions. These types of errors can cause a program to crash, or hang, unless they are handled properly.

Runtime errors are much more difficult to find and fix than design-time errors. Runtime errors can take on dozens of different shapes and forms. Here are some examples:

 

  • Attempting to open a file that doesn’t exist
  • Trying to log in to a server with an incorrect username or password.
  • Trying to access a folder for which you have insufficient rights
  • Accessing an Internet URL that no longer exists
  • Dividing a number by zero
  • Entering character data where a number is expected (and vice versa)

 

As you can see, runtime errors can occur because of an unexpected state of the computer or network on which the program is running, or they can occur simply because the user has supplied the wrong information (e.g., an invalid password, a bad filename). You can therefore write a program that runs fine on your own computer and all the computers in your test environment but fails on a customer site because of the state of that customer’s computing resources.

 

  • Understanding Logic Errors

 

The third type of error, the logic error, is often the most difficult type to locate because it might not appear as a problem in the program at all. If a program has a logic error, the output or operation of the program is simply not exactly as you intended it. The problem could be as simple as an incorrect calculation or having a menu option enabled when you wanted it disabled. Quite often, logic errors are discovered by users after the application has been deployed.

 

Logic errors also occur at runtime, so they are often difficult to track down. A logic error occurs when a program does not do what the developer intended it to do. For example, you might provide the code to add a customer to a customer list, but when the end user runs the program and adds a new customer, the customer is not there. The error might lie in the code that adds the customer to the database; or perhaps the customer is indeed being added, but the grid that lists all the customers is not being refreshed after the add-customer code, so it merely appears that the customer was not added.

 

Debugging Code

This unit looks at some of the debugging features available in some compilers. You’ll learn how to set breakpoints in your code to stop execution at any given point, how to watch the value of a variable change, and how to control the number of times a loop can execute before stopping. All these can help you determine just what is going on inside code.

 

 

  • Desk Checking Logic

Debugging an application should actually start when you are designing the program flow. After you write the algorithm for a procedure, you should walk through it using a pencil and paper to make sure it works as you intended. This process is called desk checking. To desk check an algorithm, you supply sample values and walk through the algorithm, performing the calculations.

 

To see how this works, let us use the algorithm example:

  1. Declare variables for Wage, HoursWorked, GrossPay, WithholdingAmount, and NetPay.
  2. Declare a constant for WithholdingPercent and set it equal to 20%.
  3. Input Wage.
  4. Input HoursWorked.
  5. Set GrossPay Wage * HoursWorked.
  6. Set WithholdingAmount GrossPay * WithholdingPercent.
  7. Set NetPay GrossPay WithholdingAmount.
  8. Output NetPay.

 

To desk check this algorithm; you perform each step, using sample values for the variables. You document the expected value for each variable after the step completes. You test expected input values and unexpected input values to try to find potential problems in the algorithm. For example, what if the user entered a negative number for hours worked?

  • Setting Breakpoints

When trying to debug a large program, you might find that you want to debug only a section of code; that is, you might want your code to run up to a certain point and then stop. This is where breakpoints come in handy: They cause execution of code to stop anywhere a breakpoint is set. You can set breakpoints anywhere in code, and the code will run up to that point and stop. Note that execution of the code stops before the line on which a breakpoint is set.

 

You can set breakpoints when you write code, and you can also set them at runtime by switching to the code and setting a breakpoint at the desired location. You cannot set a breakpoint while a program is actually executing a section of code, such as the code in a loop, but you can when the program is idle and waiting for user input.

When the development environment encounters a breakpoint, execution of the code halts, and the program is considered to be in break mode. While the program is in break mode, a lot of debugging features are available. In fact, a lot of debugging features are available to you only while a program is in break mode.

 

 

 

  • Stepping Through Code

When debugging an application, it is helpful to be able to step through the code line by line. You can use the followings:

 

Step Into: This includes stepping into any function or procedure that the code calls and working through it line by line.

Step Over: This works in a similar way to Step Into, but it enables you to pass straight over the procedures and functions; they still execute, but all in one go. You then move straight on to the next line in the block of code that called the procedure.

Step Out: This allows you to jump to the end of the procedure or function that you are currently in and to move to the line of code after the line that called the procedure or function. This is handy when you step into a long procedure and want to get out of it.

The rest of the code in the procedure is still executed, but you do not step through it.

 

Self Assessment Exercise

  1. Compare design-time error, runtime error, and logic error. Give an example of each.
  2. A logic error is also called a syntax error. True or False?
  3. Which type of error results in a hang or an exception during execution?

(a) design-time error

(b) Logic error

(c) Runtime error

(d) Syntax error

  1. Logic errors are often discovered by end users. True or False?
  2. Desk checking is performed after you write code. True or False?
  3. You can set a hit counter on a breakpoint to cause a program to pause after a loop executes a specific number of times. True or False?

 

Self Assessment Exercise

  1. What is a computer program?
  2. Differentiate between an interpreter and compiler
  3. What type of programming error that is not easily noticed during compilation and why?
  4. State why High level language is very easy to use compared with the earlier ones

 

CLASSIFICATION OF COMPUTER LANGUAGES

 

Before you see the general classification of programming languages, you will recall the origin of programming languages mentioned under the Introduction. You have been introduced to what is known as the Machine Language which is generally known as the language that the computer understands. With the birth of the Machine Language, two broad categories of languages are as follows:

Low-Level Language

High-Level Language

 

Low-Level Language

 

Machine Language is generally called the lowest- level language and it was the first language available to computer programmers. It is very fast since the language needs no translation because its instructions are made up of zeros and ones (O’s and I ‘s). Thus Machine Language is merely data to the computer and the program can modify itself during execution.

The advantages of Machine Language (ML) can be summarized as follows:

Fast execution speed

Programmer’s full control of the Computer and its capabilities

However, ML has some disadvantages as follows:

Difficult to learn

Highly prone to errors

Totally machine-dependent — this means that programs written in ML will only execute on the specific machine they were written.

You have been informed that ML is the lowest-level language. Hence it is the most efficient language and it is good for you to know that every computer responds only to its machine language.

The next in the hierarchy of languages that is closer to the Machine Language is the Assembly Language (AL). Assembly Language was developed in the early 1950s to alleviate some of the difficulties associated with the Machine Language. Symbolic names or mnemonics were used to replace the binary code of the Machine Language. Remember that a mnemonic means a memory aid. Hence AL instructions are easier to remember than the O’s and I ‘s of the ML instructions.

 

Below are the advantages of the AL:

It is efficient in processing time and in the use of memory space.

It encourages Modular Programming, where programs are broken into modules.

It provides an error listing which is useful in debugging.

Since it is very close to machine language, it is also fast.

Just as you have seen the disadvantages of Machine Language, the Assembly Language also has its disadvantages. Some of these are stated below:

It is cumbersome in usage.

Assembly Language has one-to-one-relationship with machine language, meaning that one Assembly Language instruction is translated into one Machine Language instruction. This process leads to long program preparation time.

Assembly Language is machine-dependent like the Machine Language.

 

Translation Method Classification

Among all the Computer programming languages, only the machine language is in machine-executable form. All other languages must be translated into O’s and l ‘s, the only things understood by the computer.

Now, translators take the forms of the following:

Interpreter

Compiler

Assembler

Interpreter

Some languages are interpreted by converting the “source program” into machine language as the program is being executed. Interpreters translate code line-by- line which therefore makes them run slowly than other translators. For example, sonic BASIC language versions only interpret programs instead of compiling them. However in Turbo Basic, KBASIC or BASIC 4GL you can compile the BASIC source code into an executable code.

 

Compiler

Unlike an Interpreter, a Compiler translates an entire program into machine language before the execution of the program. A Compiler usually translates the SOURCE program into another program called the OBJECT program which is the machine language version of the source code. With the object program created by your compiler, you will never use the source program again except when you want to modify it. Generally, a compiled program runs faster than an interpreted program.

Assembler

You have already been introduced to the Assembly Language which is neither compiled nor interpreted. For the language, it is simply assembled. Since the assembly language is already close to the machine language, assembling a program is therefore less time-consuming than compilation.

Before you proceed to the next section on High-Level Lang .ages, it is worth noting that advancement in computer programming languages has added a new classification of languages, called Very High Level

Languages (VHLL’s) or what are usually referred to as the 4th Generation Languages (4GL’s).

Below are the basic characteristic layers of a simple 4GL:

Database

Data Communication

Data Processing

End User Facilities (EUF)

From the above, database languages such as FoxPro, Dbase and Foxbase are 4GL’s. A language such as Visual Basic which equally has database capabilities can also be classified as a 4GL from the above characteristics. Now, you will be introduced to the High- Level Languages in the following section.

 

ARITHMETIC OPERATORS

 

Almost all computer programs do arithmetic operations like addition, subtraction. multiplication. division and so on for making calculations on various numeric values. In all there are 7 arithmetic operators in Visual Basic as listed below:

Operation Operator symbol
Addition +
Subtraction
Multiplication *
Division /
Exponentiation ^
Integer division \
Modulus Mod

 

The last two operator shown in our table above needs more explanation for clarity. The modulus division gives the quotient as the final result while the modulus division gives the remainder as the final result. See below for example:

Operation Example Result after division Final result
Integer division 5\2 Quotient=2 and remainder=1 2
Integer division 21\10 Quotient=2 and remainder=1 2
Modulus 7mod5 Quotient=1 and remainder=2 2
Modulus 11mod3 Quotient=3 and remainder=2 2

 

 

 

ORDER OF PRECEDENCE

In performing calculation in vb.net, it is important to consider the order of precedence i.e the rules in which arithmetical operations is being performed

Operators can either be arithmetical or logical operator.

 

The arithmetical operator has been listed in the above table. The logical operators are used to make comparism upon a given condition. The logical operators include:

 

 

Logical operators Symbols
Greater than >
Less than <
Greater than or equal to >=
Less than or equal to <=
Not equal to !=
   

.

 

Consider an example where a mathematical statement contains more than one arithmetic operator:

5+3*2

What can the answer be? Well, that depends from where we have started solving the problem. If we start from left to right and add 5 and 3 first, and then multiply the result by 2, the answer will be 16, but if we start from right to left and multiply 3 and 2 first, and then add 5 to it, the answer will be 11. Confused? This might seem quite confusing, but the possibility of such confusion can be avoided by the following rules of precedence. That means arithmetic operations are performed in a specific order. The order of operator precedence is shown below:

 

  • Exponentiation (^)
  • Multiplication(*) and division(/)
  • Integer division(\)
  • Modulus (Mod)
  • Addition(+) and subtraction(-)

Thus according to the order of precedence, exponentiation operation will be done first, second comes multiplication and division, then integer divisions, then modulus operations and lastly addition and subtractions. So the answer in our example would be 11 instead of 16 since multiplication is done before addition.

In case if the precedence level of two operators are same, the operations are done from LEFT TO RIGHT. E.g in the following example, both the operators- multiplication and division- have the same precedence level:

20/2*5

Here the division will be performed before the multiplication operation, yielding the final result as 50. In case we want to perform multiplication first and then division, we must use parenthesis () to force operations within the parenthesis to be performed first. If we rewrite the above example using parenthesis, it will be like:

20/(2*5)

From the above, the multiplication is done first  because of the parenthesis, yielding the final result as 2.

Exercise: solve: ((2+3)*5)+7

 

 

INTRODUCTION TO VB.NET AS A PROGRAMMING LANGUAGE

 

VB.Net is a simple, modern, object-oriented computer programming language developed by Microsoft to combine the power of .NET Framework and the common language runtime with the productivity benefits that are the hallmark of Visual Basic.

VB.NET is a member of the Visual studio family developed by Microsoft corporation.

Before discussing the available tools for running a VB.Net program, let us understand how VB.Net relates to the .Net framework.

The .Net Framework

The .Net framework is a revolutionary platform that helps you to write the following types of applications:

  • Windows applications
  • Web applications
  • Web services

The .Net framework applications are multi-platform applications. The framework has been designed in such a way that it can be used from any of the following languages: Visual Basic, C#, C++, Jscript, and COBOL, etc.

All these languages can access the framework as well as communicate with each other.

The .Net framework consists of an enormous library of codes used by the client languages like VB.Net. These languages use object-oriented methodology.

Following are some of the components of the .Net framework:

  • Common Language Runtime (CLR)
  • The .Net Framework Class Library
  • Common Language Specification
  • Common Type System
  • Metadata and Assemblies
  • Windows Forms
  • ASP.Net and ASP.Net AJAX
  • ADO.Net
  • Windows Workflow Foundation (WF)
  • Windows Presentation Foundation
  • Windows Communication Foundation (WCF)
  • LINQ

Integrated Development Environment (IDE) For VB.Net

Microsoft provides the following development tools for VB.Net programming:

  • Visual Studio 2010 (VS)
  • Visual Basic 2010 Express (VBE)
  • Visual Web Developer

The last two are free. Using these tools, you can write all kinds of VB.Net programs from simple command-line applications to more complex applications. Visual Basic Express and Visual Web Developer Express edition are trimmed down versions of Visual Studio and has the same look and feel. They retain most features of Visual Studio.

 

VB.NET SYNTAX

VB.Net is an object-oriented programming language. In Object-Oriented Programming methodology, a program consists of various objects that interact with each other by means of actions. The actions that an object may take are called methods. Objects of the same kind are said to have the same type or, more often, are said to be in the same class.

When we consider a VB.Net program, it can be defined as a collection of objects that communicate via invoking each other’s methods. Let us now briefly look into what do class, object, methods and instant variables mean.

  • Object – Objects have states and behaviors. Example: A dog has states – color, name, breed as well as behaviors – wagging, barking, eating, etc. An object is an instance of a class.
  • Class – A class can be defined as a template/blueprint that describes the behaviors/states that object of its type support.
  • Methods – A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instant Variables – Each object has its unique set of instant variables. An object’s state is created by the values assigned to these instant variables.

 

HOW TO OPEN VB.NET

1.CLICK ON START

2.CLICK ON PROGRAMS

3.CLICK ON VISUAL STUDIO

4.When the environment opens, select file menu

  1. select new

6.select visual basic

7.select windows application and give your project a file name

8.click on ok.

 

VISUAL STUDIO IDE

Visual Studio is a powerful and customizable programming environment that contains all the tools you need to build programs quickly and efficiently. It offers a set of tools that help you write and modify the code for your programs, and also detect and correct errors in your programs.

 

Before you start learning more about VB.NET programming, it is important to understand the development environment and identify some of the frequently using programming tools in Visual Studio IDE

   1. Menu Bar  2. Standard Toolbar  3. ToolBox  4. Forms Designer  5. Output Window  6. Solution Explorer

  1. Properties Window

 

Visual Basic.NET IDE is built out of a collection of different windows. Some windows are used for writing code, some for designing interfaces, and others for getting a general overview of files or classes in your application.

 

Visual Studio organizes your work in projects and solutions. A solution can contain more than one project, such as a DLL and an executable that references that DLL. From the following chapters you will learn how to use these Visual Studio features for your programming needs.

 

 

 

 

 

 

VB.NET DATATYPES

Data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

Data Types Available in VB.Net

VB.Net provides a wide range of data types. The following table shows all the data types available:

Data Type Storage Allocation Value Range
Boolean Depends on implementing platform True or False
Byte 1 byte 0 through 255 (unsigned)
Char 2 bytes 0 through 65535 (unsigned)
Date 8 bytes 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999
Decimal 16 bytes 0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9…E+28) with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal
Double 8 bytes -1.79769313486231570E+308 through -4.94065645841246544E-324, for negative values

4.94065645841246544E-324 through 1.79769313486231570E+308, for positive values

Integer 4 bytes -2,147,483,648 through 2,147,483,647 (signed)
Long 8 bytes -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807(signed)
Object 4 bytes on 32-bit platform

8 bytes on 64-bit platform

Any type can be stored in a variable of type Object
SByte 1 byte -128 through 127 (signed)
Short 2 bytes -32,768 through 32,767 (signed)
Single 4 bytes -3.4028235E+38 through -1.401298E-45 for negative values;

1.401298E-45 through 3.4028235E+38 for positive values

String Depends on implementing platform 0 to approximately 2 billion Unicode characters
UInteger 4 bytes 0 through 4,294,967,295 (unsigned)
ULong 8 bytes 0 through 18,446,744,073,709,551,615 (unsigned)
User-Defined Depends on implementing platform Each member of the structure has a range determined by its data type and independent of the ranges of the other members
UShort 2 bytes 0 through 65,535 (unsigned)

 

VB.NET VARIABLE

A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in VB.Net has a specific type, which determines the size and layout of the variable’s memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

We have already discussed various data types. The basic value types provided in VB.Net can be categorized as:

Type Example
Integral types SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and Char
Floating point types Single and Double
Decimal types Decimal
Boolean types True or False values, as assigned
Date types Date

VB.Net also allows defining other value types of variable like Enum and reference types of variables like Class. We will discuss date types and Classes in subsequent chapters.

Variable Declaration in VB.Net

The Dim statement is used for variable declaration and storage allocation for one or more variables. The Dim statement is used at module, class, structure, procedure or block level.

Syntax for variable declaration in VB.Net is:

[ < attributelist> ] [ accessmodifier ] [[ Shared ] [ Shadows ] | [ Static ]]

[ ReadOnly ] Dim [ WithEvents ] variablelist

Where,

  • attributelist is a list of attributes that apply to the variable. Optional.
  • accessmodifier defines the access levels of the variables, it has values as – Public, Protected, Friend, Protected Friend and Private. Optional.
  • Shared declares a shared variable, which is not associated with any specific instance of a class or structure, rather available to all the instances of the class or structure. Optional.
  • Shadows indicate that the variable re-declares and hides an identically named element, or set of overloaded elements, in a base class. Optional.
  • Static indicates that the variable will retain its value, even when the after termination of the procedure in which it is declared. Optional.
  • ReadOnly means the variable can be read, but not written. Optional.
  • WithEvents specifies that the variable is used to respond to events raised by the instance assigned to the variable. Optional.
  • Variablelist provides the list of variables declared.

Each variable in the variable list has the following syntax and parts:

variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ]

Where,

  • variablename: is the name of the variable
  • boundslist: optional. It provides list of bounds of each dimension of an array variable.
  • New: optional. It creates a new instance of the class when the Dim statement runs.
  • datatype: Required if Option Strict is On. It specifies the data type of the variable.
  • initializer: Optional if New is not specified. Expression that is evaluated and assigned to the variable when it is created.

Some valid variable declarations along with their definition are shown here:

Dim StudentID As Integer

Dim StudentName As String

Dim Salary As Double

Dim count1, count2 As Integer

Dim status As Boolean

Dim exitButton As New System.Windows.Forms.Button

Dim lastTime, nextTime As Date

 

VB.NET CONSTANTS

The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals.

Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.

The constants are treated just like regular variables except that their values cannot be modified after their definition.

An enumeration is a set of named integer constants.

Declaring Constants

In VB.Net, constants are declared using the Const statement. The Const statement is used at module, class, structure, procedure, or block level for use in place of literal values.

 

4 COMMENTS

  1. I’ve been absent for a while, but now I remember why I used to love this web site. Thanks, I will try and check back more often. How frequently you update your website?

  2. We absolutely love your blog and find almost all of your post’s to be what precisely I’m looking for. Does one offer guest writers to write content for yourself? I wouldn’t mind composing a post or elaborating on many of the subjects you write in relation to here. Again, awesome site!

    • Thank you very much for your comment, we welcome people to post their article,project,books, journal and etc on our website. Thanks (+2347039885501)

Leave a Reply