Sunday, November 4, 2012

CBSE Class 11/10 - Computers/FIT - Programming Languages

Programming Languages
Programming Languages
(Questions & Answers)

Q1: What is a computer language?

Answer: The instructions are fed into computers in the form of computer programs, follow some semantics (grammar or syntax) collectively is called a programming language. In layman terms, the language, which the user employs to interact with computer, is known as computer or programming language.

Examples are: C/C++, Java, Pascal, COBOL, Python, FORTRAN etc.

Q2: What are different generation of languages?

Answer: A good number of languages have been developed so far, therefore all computer languages are divided among different generations of languages:
  1. The first generation languages (1GL) are low-level languages that are machine language.
  2. The second-generation languages (2GL), ar also low-level languages that consist of assembly language.
  3. The third generation languages(3GL) are high-level languages such as C.
  4. The fourth generation languages (4GL) are languages that consist of statements similar to statements used in a human language.
  5. The fifth generation languages(5GL) are programming language based around solving problems following constraints-driven approach rather using an algorithm-driven approach.A good example of a fifth generation language is PROLOG.
Q4: What were different types of problem-solving approaches which led to the basis of computer-based solving and design of computer languages?

Answer: Various problem solving approaches which were initially used in computer based solving and design of computer languages are:
  1. Look for similar patterns or situations (Table look up)
  2. Divide and Conquer
  3. Heuristics (rule of thumb)
  4. Algorithms

Machine Code
Machine Code
(Hex View of .exe file)
Q5:  What is a machine language?

Answer: Machine Language was the first generation programming language which is hard wired in processors. It is also referred as machine code or object code. Machine language instructions are built into the hardware of a particular computer. It is a collection of binary digits or bits that the computer reads and interprets. Machine language is the finite number of instructions that only a computer can understand.

Q6: What are the advantages of  First Generation Languages?

Answer: Advantages are:
  • Programs written in machine language execute very fast by the computer.
  • The computer directly understands machine instructions, since no translation of the program is required.

Q7: What are the disadvantages of  First Generation Languages?

Answer: Disadvantages are:
  1. Machine dependent: The processor and machine code are directly integrated the machine language differs from computer (processor) to computer (processor). 
  2. Difficult to Code: Although, machine language programs are directly executed by the computer, but it is difficult to write program in machine language.
  3. Error Prone Coding: a programmer has to remember the machine codes, and must keep track of the storage locations of data and instruction. So it becomes very difficult to concentrate on the logic of the problem. This frequently results in programming errors.
  4. Difficult to understand: It is difficult to correct or modify machine language programs.
  5. High Cost of Maintenance: Because of tight integration with processor high chances of error coding, cost of coding and managing programs increase.

Q8: What is an assembly language?

Answer: Assembly language is a second generation programming language. Also referred as low-level programming language, it is designed for specific processors. Assembly language uses structured commands as substitutions called mnemonics. The mnemonics are used for bits used by machine language allowing humans to read the code easier than looking at binary.

A system software called assemblers were designed to convert mnemonic codes into machine language instructions. In general assembly mnemonic instruction consist of Opcode (CPU instruction) and operand (data value).

Here is an example of assembly language code.
 mov  ax,2C00h   - Move number (2C00H) to AX register
 inc  cx                 - Increment value stored in CX register
 int  20h                - Call Interrupt 20H

Since mnemonics are one to one related to machine code instructions, assembly language is machine dependent.

Q9: What is a computer bug?

Answer: A computer bug is a any type of problem, defect or mistake in a program/software or in a hardware.

Q10: What is debugging?

Answer: The process of identifying and removing a defect in hardware or software is called debugging.

Q11: What are the advantages of assembly language over machine language?

Answer: As compared to machine language, assembly language has the following advantages:
  1. Easier to write code.
  2. Easier to debug program.
  3. Easy to modify program, reduce maintenance cost.
  4. Useful for writing small, real time applications for embedded devices.

Q12:  What is an assembler?

Answer: Assembler is a system program which translates an assembly language code or program to machine code format. Generally assemblers are written by the manufacturers of processors because assemblers are machine dependent.

Q13: What are the limitations of coding in assembly language?

Answer: Following are the limitations of coding in assembly language:
  1. Machine Dependent: Since mnemonics are processor specific, one needs to port or translate his/her program while switching to another machine (processor model).
  2. Hardware knowledge is prerequisite. It because necessary to know about CPU and its hardware. 
  3. Increase maintenance cost. Due to above said two factors, it increases the maintenance cost for managing software.
Q14: What are high-level languages?

Answer:  High level languages or 3rd generation languages use English like statements to code computer instructions. These are programmers' friendly since these languages are machine-independent and developers can concentrate on problem solving logic rather than on hardware structure. These languages require system programs called compilers (and interpreters) which translate English-like statements (source code) to machine code.

Examples of high level languages are: C, C++, Java, COBOL, BASIC, FORTRAN, Pascal etc.

Q15: Write full form of following computer language abbreviations
(ii) BASIC
(iv) ALGOL
(v) LISP

(i) COBOL: Common Business Oriented Language (used for developing for business applications)
(ii) BASIC: Beginners All purpose Symbolic Instruction Code
(iii) FORTRAN: Formula Translation (for developing scientific applications)
(iv) ALGOL: Algorithm Language
(v) LISP: List Processor (used for developing artificial language based applications)

Q16: What is a compiler?

Answer: Compilers are system programs, which translate a source code written in high level language to an object code. When a programmer writes a program code, he runs the compiler program, which translates it into an executable program. Then you run or execute the translated program.

In general compiler works in multiple stages. In the first stage it checks if the code follows the high level language grammar and semantics. If there is any error(s) it aborts the compilation process and reports the errors. If there is no error, it generates intermediate object code. In the second stage, linker which is a system program part of compiler, combines various object code files into a single executable binary file (machine code).

Q17: What is an interpreter? What are advantages and/or disadvantages the interpreter has over compiler?

Answer: An interpreter like a compiler is also a system program that translates a high-level language code into a low-level one. But the translation occurs at the moment when the program is run. A developer writes the code using a text editor or something similar, and then calls the interpreter to translate and run the program. Interpreter reads the source code one line at a time and translates each line and then executes it. Then it translates the second line, runs it, and so on.

The main advantage of interpreters over compilers is that a syntax error in the source code is detected and is brought to the attention of the programmer as soon as the program statement is interpreted.

The main disadvantage of interpreter over compiler is that it is slower than compiler when running a finished program. Also the interpreter's run time environment has to be available in the computer’s memory when the program is executed.

GW-BASIC is an interpreter for BASIC language. Visual C++, Turbo Pascal are compilers for C++ and Pascal languages. Now-a-days, modern languages like Java, C# use a mixed model of interpreter and compiler.

Q18: What are the main advantages of High Level Languages?

Answer: High Level language have the following advantages over using assembly and machine language:
  1. Machine Independent: A high level language written code can easily be ported to another hardware platform. Language instructions do not reply on characteristics of a machine hardware.
  2. Easy to Learn: Since the HLL instructions are English like statements, these are easier to learn.
  3. Closer to Design Process: The design process is better suited for HLLs as compared to low level languages. Implementing various programming techniques, algorithms and data structures is much easier in HLLs.
  4. Few Errors and Easy Debugging: Since the programmer need not worry about hardware instructions, he can concentrate more on developing program logic.
  5. Low development Cost: Writing programs in high level languages take less time as compared to coding in low level languages.
  6. Low maintenance cost: Programs are easier to manage. One can find errors easily and rectify them thus reducing the maintenance cost.
  7. Better Documentation: Since HLLs are English language statements and hence easier to understand. The code is self-explanatory and requires less commenting.
Q19: What are the limitations of High level languages?

Answer: Although HLLs have numerous advantages over low level languages but it does have certain limitations:
  1. Large time to execute: A HLL translated machine code is bigger in size than low level programmed code. Thus HLL translated code takes larger time to execute.
  2. Less optimized code: Sometimes it is required to write a small sized efficient programs because of memory and performance constraints (e.g. embedded devices which use CPUs do not have large memory and need faster response). In this case, coding in assembly is better alternative.
  3. Managing Growing complexity is a challenge: As the code size of a software grows, the complexity to manage its code also increases. One needs to apply various disciplinary actions of software engineering and code management to produce a reliable software. This indeed increases the managing cost.

Q20: Who designed 'C' language?

Answer: Dennis Ritchie

Q21: Who designed 'C++' language?

Answer: Bjarne Stroustrup

Q22: Who designed BASIC language?

Answer: John George Kemeny and Thomas Eugene Kurtz at Dartmouth College

Q23: Who developed Visual Basic?

Answer: Microsoft Team

Q24: Who is known as Father of Computers?

Answer: Charles Babbage  

Q25: Name the language which was named after a lady who was the daughter of  poet Lord Byron. She worked with Charles Babbage to develop plans for the Analytical Engine.

Answer: Ada (and the lady was Augusta Ada Byron, countess of Lovelace. Also referred as the first known programmer.) Ada is a object oriented high level language.

Q26: What are fourth generation languages (4GL)? How are 4GLs different from third generation languages?

Answer: Fourth generation languages (4GLs) are English like statements commonly used to access databases. These are called command languages or non-procedure languages because these languages help the user obtain desired results without writing long program or procedures (as it is done in 3rd generation languages). 4GLs are more oriented towards non-technical users and reduce coding errors. Examples of 4GLs are SQL, DBMS, spreadsheets, FOCUS, report generator etc.

Q27: What are different types of programming errors?

Answer: Different types of programming errors are:
  1. Syntax errors: Mistyping a reserved word, e.g. typing peint instead of print
  2. Logic errors: e.g. A jump instruction that tells the computer to jump to the wrong address
  3. Arithmetic error: inappropriate use of arithmetic. e.g. divide by zero
  4. Runtime Errors: e.g. stack overflow, null pointer assignment, exceptions

Q28: Bugs are common in computer programs. Describe any two techniques which can be used to debug a program.

Answer: The two techniques which can help debug the program are:
  1. Trace Table (stack trace listing the functions called in a sequence)
  2. Reference of variables: Check the value of variable at various places of the program.

 (In progress...)

No comments:

Post a Comment