




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Btec Programming Assignment based on Pearson syllabus format
Typology: Study Guides, Projects, Research
1 / 28
This page cannot be seen from the preview
Don't miss anything!
GU-2020-
Mr. Anil Pandit Course Instructor Faculty of Computational Science
Simranjit Kaur
Page 1
GU-2020-
I want to thank many people who have helped me in completing this assignment. Without their proper guidance and encouragement, I would not have made headway in this assignment. First and foremost, I would like to thanks to Mr. Anil Pandit, Course Instructor of our university, to share his knowledge with me on this assignment. He helped me to understand about all the concepts and his instructions have served as the major contribution towards the completion of the assignment. Secondly, a big thanks to Mrs. Gurgeet Kaur who have helped me to improve the quality of my assignment. Thirdly, a big thank you to my parents for all what they did and still doing to help me be at this position. Besides, big thanks to all my friends and classmates who have shared their support and help me in making my assignment valuable, Page 2
GU-2020- 3.5.1: Algorithm 23 3.5.2: Program written in C language (Procedural Programming language) 23- 3.5.3: Program written in C++ language (Object Oriented Programming language)
3.5.4: Program written in Java (Event Driven Programming) 26- Page 4
GU-2020-
An Algorithm may be defined as the finite sequence of instructions that can be used for solving different kinds of programming problems. The sequence of instructions designed in such a manner that when we perform a task to solve any programming problem then the corresponding result will be obtained and terminate in a fixed amount of time. An algorithm is used to refer the logic of a program and tells computer how to solve a problem in order to get desired result. An algorithm is independent of any programming language. If we have to perform a program which is very complex, so we maybe find some difficulty in writing a program but with the help of algorithm we are able to perform it in its easiest way.
INPUT: An algorithm must consist of zero or more well defined but must be finite number of inputs supplied externally. OUTPUT: An algorithm must have one or more well defined outputs as a result and those outputs should match the desired output. FINITENESS: An algorithm should have finite number of steps i.e. steps must be countable and each step must take finite time for execution. DEFINITENESS: In algorithm each step should have a clear and only one meaning and leads to a unique solution of the problem. EFFECTIVENESS: An algorithm doesn’t contain any unnecessary step. Each step should provide a result in finite amount of time. Algorithm should be simple and it should be easily understandable by the user. Page 5
GU-2020- 2 0
Now, compare the element 20 with the next adjacent element 70. So, 20 is smaller than 70 so there is no need to swap it. Now, compare the 70 with 40. Hence, the element 70 is greater than 40 so it swaps with it. 10 20 70 40 50 0 1 2 3 4 Now, compare the element 70 with 50. So, the element 70 is greater than 50. So, it swaps with it. 10 20 40 70 50 0 1 2 3 4 Hence all the elements are arranged in an ascending order. 10 20 40 50 70 0 1 2 3 4
Step1: Start Step2: Declare integer type variables. Step2: Enter total number of elements in array. Step3: Initialize i= Step4: Enter the elements in the array. Step5: If (i<=n) then repeat step 6 to 8. Step6: Set j=0. Step7: Repeat step 8 until j<n-1. Step8: If A[j] > A[j+1] Set temp=A[j] A[j]=A[j+1] Page 7
GU-2020- A[j+1]=temp end if end for Step9: Print the sorted array. Step10: Exit.
#include<stdio.h> #include<conio.h> void main() { int arr[100], i, j, n, temp; clrscr(); printf(“Enter total number of elements:”); scanf(“%d”,&n); printf(“Enter elements:”); for(i=0;i<n;i++) { scanf(“%d”,&arr[i]); } printf(“Elements you have entered are \n”); for(i=0;i<n;i++) { printf(“%d”,arr[i]); Page 8
GU-2020- When we write a program, we have to write instructions which are readable by a human for performing any operation and those instructions are called as source code. A computer understands only binary or machine language, so we have to convert a source code into machine code for the execution of a program and this we can done by compiler. Compiler takes the source code and converts that source code into object code which is understandable by the computer and we can save the object code as an object file. If we have many files suppose we have five object files so we can divide these files and perform compiling process on each file and generate object code for each file. Then we have to link all these files together and generate an executable file. This process is done by the linker. The linker takes all the object files and it generates an executable file.
Preprocessor is a program which transfers the code before compilation. In a program, the line starting with the symbol # are called as preprocessor directive and that line is called as preprocessor command.
Page 10
GU-2020- Function: We write the instructions in human readable form to perform any task in programming are called as source code. Pre Processor takes that source code and modifies the source code before it passes through the compiler. After the completion of all the operations of preprocessor, the expanded code is passed to the compiler. When we write any computer program, we store it in the computer memory as a computer file and the file which is containing this source code is called as the source file. A file containing C source code is called as C source file and when we have to save this C source file, it contains ‘.c’ extension. The main tasks which are performed by the pre processor are as following: Macro substitution: Macro replaces the instance of one value by a predefined value. We use the directive #define to predefined any text. Some types of macro substitution are:
GU-2020-
A programmer write a code in human readable form but computer understand only binary language i.e. 0 and 1, so the complier works as a translator for the computer which converts the source code into binary form. Function: The compiler converts the complete source code into machine language code which is understands by the computer and makes object code and the file containing object code is called as object file. This object file has different extensions in different environments like in DOS, it has ‘.obj’ extension and in UNIX, it has ‘.o’ extension. If we have many files it is the work of a compiler to divide these files and generates a separate object file for each one. It executes the whole program so there is need to join these separate object codes which are saved as object files, so compiler generates an intermediate object code which requires linking.
Source code in high level language Compiler Object code in machine language Page 13
GU-2020-
As we written above in the compiler section, when there is large object code it requires linking. So, linker is a program which combines one or more object code into an executable code. Function: All programs and operations use library functions. Linker combines the large object code made by the compiler of the library functions with the object code of our program. Our written program may also contain the references to functions which are defined in other files. The linker links the object code of these files also to our programs. When there is completion of combining this object code is complete, we get the executable code and we can save it as an executable file. In different environments, executable file has different extension like in DOS has ‘.exe’ extension.
Interpreter converts the source code line by line or into an intermediate language code that can be easily executed by the computer. Function: Interpreter translates the code line by line and each time the code is executed, every line of the code is checked for syntax error and then converted into machine code. Therefore, interpreter is good for fast debugging. For the execution of a code, it has to go through the following steps shown in the diagram. Page 14
GU-2020- In procedural programming language, a problem is to be solved in a set of instructions such as reading the input, calculating the given problem, printing the output. The primary focus of procedural programming is towards the functions means how to work in a systematic way. Examples of procedural programming languages are C, BASIC, FORTAN, COBOL etc. 3.1.1: CHARACTERISTICS OF PROCEDURAL PROGRAMMING LANGUAGE Simplicity: The syntax style of Procedural Programming Language is easy to understand as it is written in procedures and easy to perform operations in a program because of the structured programming. Approach: It follows the top-down approach. Focus: The main focus of Procedural Programming Language is on processing not on the data. Efficient: We can easily use the applications of Procedural Programming Language and perform different operations on it. It allows the user to concentrate on the code and not worry about the machine code on which the program has to be run. Powerful: Procedural Programming Language is a very powerful programming. It has a great variety of functions, decision making statements, data types etc. Case sensitive: Procedural Programming Language is case sensitive. Suppose if we are writing any program and in it we write a character like ‘case’ so we have to write as it is. We can’t write ‘CASE’ because C library treats lowercase and uppercase letters differently. Speed: Procedural Programming Language is a compiler based language. Compiler process the whole code in faster speed. So, it has comparatively faster speed than object oriented programming language. Popular: Procedural Programming Language is the most popular language in the development of operating systems. It is a fundamental language and allows the programmers to write the programs in more easiest and efficient way. Syntax based language: In Procedural Programming, code is written in procedures so it follows the rules and regulations while writing a code. So it is a strongly syntax based language. We have to write a code perfectly for successful execution. Existence of libraries: Procedural programming language provides a lot of built in features i.e. keywords, operators, datatypes etc which allows a user to perform Page 16
GU-2020- different kinds of operations. Also, the user defined functions are present in its library. These features help in developing any task in programming very fast. Middle level language: Procedural programming language is a middle level language i.e. it has combined features of assembly language and high level language. Clarity: Features of Procedural Programming like keywords, structures, inbuilt functions help to improve the understanding and clarity of the program. Structured language: Procedural programming language is a structured language i.e. when we write a program in this language we can divide it into smaller parts with the help of functions which help a user to understand and run the program properly. Flexibility: Procedural Programming Language is very flexible because it is a fundamental language so it can interface with other languages without any kind of difficulty. Extensible language: Procedural programming language is an extensible language that means when we write any program we can also add some functions in it. It can easily adopt new features. Portability: It is a portable language i.e. when we write any program in procedural programming language we can run this program in different environments with little or without any modification. Therefore, Procedural Programming Language is a Machine Independent Language. Core language: Procedural Programming Language is a core language because the other languages like java, C++ are based on Procedural Programming Language. If you have a complete knowledge of procedural programming language then it is very easy to learn other languages. Memory management: Memory can be allocated and deallocated in procedural programming language. Error detection: In this language, different types of errors can be easily detected in its compiler. These errors displayed on the screen with line number of the code and the error message while execution of the program. There are different types of errors occur during the execution of the program like syntax errors, runtime errors, logical errors etc. Page 17
GU-2020- programs in it and understand those programs. Object oriented programming implement the real world entities. Examples of object oriented programming languages are C++, C#. 3.2.1: CHARACTERISTICS OF OBJECT ORIENTED PROGRAMMING LANGUAGE Approach: It works with bottom-up approach. Object: In Object Oriented Programming, objects are run-time entities. It consists of data and functions that operate on data. An object has characteristics and behavior and is an instance of a class. Classes: It is a collection of homogeneous objects. Class is a user defined data type which holds its data variables and functions. It is like a blueprint for an object. Let us take an example that we have a car and there are many models of a car like Hyundai, Audi, and Swift. So, a car is come under in a category of a class and its models come under objects. Method: An operation is required for an object when it is coded in a class so that operation is called as a method. Encapsulation: Encapsulation means binding the data together and functions into a single component. With the help of encapsulation we can also accomplish data hiding. Data abstraction: It is the most important feature of object oriented programming. It displays only the necessary information and hides the implementation work which is done on the background. Polymorphism: Polymorphism means many forms. It makes the same function to act differently on different classes like in real world a woman have different characteristics like she may be a daughter, mother or an employee. Inheritance: When objects of one class get the properties of another class is called inheritance. There are five types of inheritance i.e. single inheritance, multilevel inheritance, hybrid inheritance, multiple inheritances, hierarchical inheritance. Dynamic binding: In dynamic binding, the written code to be executed in response to function call is decided at runtime. Message passing: In Object Oriented Programming, objects can communicate with one another by sending and receiving the information. Page 19
GU-2020- Clarity: Object Oriented Programming allows a user complete clarity about any complex program. We can perform complex operations in a very simple way using Object Oriented Programming. Reusable code: A programmer can reuse their code through inheritance. Flexible: The concept of polymorphism gives flexibility to the programmer by allowing the entities to have multiple forms.
In event driven programming, flow of the program is determined by events. Example: user actions, messages from other programs, sensor outputs etc. Event driven programming is also known as event based programming. With the use of it, it is easy to design a program as it is very visual. Examples of event driven programming languages are Visual Basic, JAVA, and Python etc. 3.3.1: CHARACTERISTICS OF EVENT DRIVEN PROGRAMMING LANGUAGE Flexibility: Programs written in Event Driven Programming are more flexible than programs written in other languages. It is easy for the user to change anything in the program because the user has to change only some event handlers or screen adding. Simplicity: It is easier and simple to use as it is very visual so it simplify even the complex program. Event driven programs are easy to develop and maintain. Approach: It works with bottom-up approach. Service oriented: Everything which is visible on the screen provides service to the user. Everything appears on the screen have a control and each control have blocks of code attached with it. These blocks are referred to events. Time driven: In Event Driven Programming, time driven is a code which runs only on a specific time. Event handlers: It is a type of a function which programmers made for the user to perform a specific action. Example: This can be done by clicking a button by the user. All event handlers work independently in a program so it is easier for the programmer Page 20