






















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
Assignment 1 Prog102 @@@@@@@@@
Typology: Summaries
Uploaded on 09/29/2021
5
(2)1 document
1 / 30
This page cannot be seen from the preview
Don't miss anything!























Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog 102 : Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Student ID Class Assessor name Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Grading grid P1 P2 P3 M1 M2 D
Grade: Assessor Signature: Date: Lecturer Signature: Unit Number and Title Unit 0: IT Fundamental & Procedural Programming Academic Year Unit Tutor Assignment Title Analysis and Design a solution for procedural programming problem Issue Date Submission Date IV Name & Date Learning Outcomes and Assessment Criteria Pass Merit Distinction LO1 Understand the principles of procedural programming LO2 Be able to design procedural programming solutions
TASK 1 (P1, M1) (P1. Provide Information About Procedural Programming)
Programming language is a formal language comprising a set of strings that produce various kinds of machine code output. Programming languages are one kind of computer language, and are used in computer programming to implement algorithms. Computer programming language, any of various languages for expressing a set of detailed instructions for a digital computer. Such instructions can be executed directly when they are in the computer manufacturer-specific numerical form known as machine language, after a simple substitution process when expressed in a corresponding assembly language, or after translation from some “higher-level” language. Although there are many computer languages, relatively few are widely used. Machine and assembly languages are “low-level,” requiring a programmer to manage explicitly all of a computer’s idiosyncratic features of data storage and operation. In contrast, high-level languages shield a programmer from worrying about such considerations and provide a notation that is more easily written and read by programmers.
A low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture—commands or functions in the language map that are structurally similar to processor's instructions. Generally, this refers to either machine code or assembly language. Because of the low (hence the word) abstraction between the language and machine language, low-level languages are sometimes described as being "close to the hardware". Programs written in low- level languages tend to be relatively non-portable, due to being optimized for a certain type of system architecture. Low-level languages can convert to machine code without a compiler or interpreter – second-generation programming languages use a simpler processor called an assembler – and the resulting code runs directly on the processor. A program written in a low-level language can be made to run very quickly, with a small memory footprint. An equivalent program in a high-level language can be less efficient and use more memory. Low-level languages are simple, but considered difficult to use, due to numerous technical details that the programmer must remember. By comparison, a high-level programming language isolates execution semantics of a computer architecture from the specification of the program, which simplifies development.
In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use
natural language elements , be easier to use, or may automate (or even hide entirely) significant areas of computing systems (e.g., memory management), making the process of developing a program simpler and more understandable than when using a lower-level language. The amount of abstraction provided defines how "high-level" a programming language is. In the 1960s, high-level programming languages using a compiler were commonly called auto codes Examples of auto codes are COBOL and Fortran. The first high-level programming language designed for computers was Plankalkül, created by Konrad Zuse However, it was not implemented in his time, and his original contributions were largely isolated from other developments due to World War II, aside from the language's influence on the "Super plan" language by Heinz Rutishauser and also to some degree Algol. The first significantly widespread high-level language was Fortran, a machine-independent development of IBM's earlier Auto code systems. Algol, defined in 1958 and 1960 by committees of European and American computer scientists, introduced recursion as well as nested functions under lexical scope. It was also the first language with a clear distinction between value and name-parameters and their corresponding semantics Algol also introduced several structured programming concepts, such as the while-do and if-then-else constructs and its syntax was the first to be described in formal notation – "Backus–Naur form" (BNF). During roughly the same period, Cobol introduced records (Also called structs) and Lisp introduced a fully general lambda abstraction in a programming language for the first time.
Procedural Programming may be the first programming paradigm that a new developer will learn. Fundamentally, the procedural code is the one that directly instructs a device on how to finish a task in logical steps. This paradigm uses a linear top-down approach and treats data and procedures as two different entities. Based on the concept of a procedure call, Procedural Programming divides the program into procedures, which are also known as routines or functions, simply containing a series of steps to be carried out.Simply put, Procedural Programming involves writing down a list of instructions to tell the computer what it should do step-by-step to finish the task at hand
There are many factors that influence the choice of programming languages, the main factors are cost, organization policy, availability, reliability, suitability and expandability. All these factors should be considered when choosing a programming language.One of the most important factors is cost as it can influence the developing and maintenance to that software. To develop a software project, the size of the project needs to be taken into account. Depending on the size of the project it can change how many programmers you employ. For example a big project will require lots of programmers which can be very costly to contract. To even maintain the project and keep it up to date, free from errors, will cost to keep the programmers to do this over the years. However, some languages can be easier to cut development
In computer programming, a variable or scalar is a storage location (identified by a memory address) paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value ; or in easy terms, a variable is a container for a particular type of data (like integer, float, String and etc...). The variable name is the usual way to reference the stored value, in addition to referring to the variable itself, depending on the context. This separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution. Variables in programming may not directly correspond to the concept of variables in mathematics. The latter is abstract, having no reference to a physical object such as storage location. The value of a computing variable is not necessarily part of an equation or formula as in mathematics. Variables in computer programming are frequently given long names to make them relatively descriptive of their use, whereas variables in mathematics often have terse, one- or two- character names for brevity in transcription and manipulation. A variable's storage location may be referenced by several different identifiers, a situation known as aliasing. Assigning a value to the variable using one of the identifiers will change the value that can be accessed through the other identifiers. Following are the rules that must be followed while creating a variable:
The data type defines which operations can safely be performed to create, transform and use the variable in another computation. When a program language requires a variable to only be used in ways that respect its data type, that language is said to be strongly typed. This prevents errors, because while it is logical to ask the computer to multiply a float by an integer (1.5 x 5), it is illogical to ask the computer to multiply a
float by a string (1.5 x Alice). When a programming language allows a variable of one data type to be used as if it were a value of another data type, the language is said to be weakly typed.
They are arithmetic types and are further classified into: (a) integer types and (b) floating-point types.
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain
The void type, in several programming languages derived from C and Algol68, is the type for the result of a function that returns normally, but does not provide a result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their output parameters.
They include Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
The CHAR data type stores character data in a fixed-length field. Data can be a string of single-byte or multibyte letters, numbers, and other characters that are supported by the code set of your database locale. Example: Styntax: #include
The void data type, similar to the Nothing data type described earlier, is the data type for the result of a function that returns normally, but does not provide a result value to its caller. The void data type has no values and no operations. It’s a data type that represents the lack of a data type. Example: void sum (int a, int b); – This function won’t return any value to the calling function. int sum (int a, int b); – This function will return value to the calling function.
3. Slection Structures
The if statement is used to check some given condition and perform some operations depending upon the correctness of that condition. It is mostly used in the scenario where we need to perform the different operations for the different conditions. The structure of an if statement is as follows: 1 2 if (statement is TRUE) Execute this line of code Here is a simple example that shows the syntax: 1 2 if (5 < 10) printf ( "Five is now less than ten, that's a big surprise") Flowchart of if statement in C
Figure 1 The Flowchart show how if statement works [1] javaTpoint.com A simple example of C language if statement. #include<stdio.h> int main(){ int number=0; printf("Enter a number:"); scanf("%d",&number); if (number%2==0){ printf("%d is even number",number); } return 0; }
witch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. The switch statement works with byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long. Since Java 7, you can use strings in the switch statement. In other words, the switch statement tests the equality of a variable against multiple values. Syntax: switch (expression){
public class SwitchExample { public static void main (String [] args) { //Declaring a variable for switch expression int number= 20 ; //Switch expression switch (number) { //Case statements case 10 : System.out.println("10"); break ; case 20 : System.out.println("20"); break ; case 30 : System.out.println("30"); break ; //Default case statement default :System.out.println("Not in 10, 20 or 30"); } } }
The Java while loop is used to iterate a part of the program repeatedly until the specified Boolean condition is true. As soon as the Boolean condition becomes false, the loop automatically stops. The while loop is considered as a repeating if statement. If the number of iterations is not fixed, it is recommended to use the while loop. Syntax: for (initialization; condition; increment/decrement) { //statement or code to be executed }
Figure 3 The Flowchart show how for loop works [3] javaTpoint.com Example: public class WhileExample { public static void main (String [] args) { int i= 1 ; while (i<=10) { System.out.println(i); i++; } } }
The Java while loop is used to iterate a part of the program repeatedly until the specified Boolean condition is true. As soon as the Boolean condition becomes false, the loop automatically stops.
The Java do-while loop is used to iterate a part of the program repeatedly, until the specified condition is true. If the number of iterations is not fixed and you must have to execute the loop at least once, it is recommended to use a do-while loop. Java do-while loop is called an exit control loop. Therefore, unlike while loop and for loop, the do-while check the condition at the end of loop body. The Java do-while loop is executed at least once because condition is checked after loop body. The syntax of the C language do-while loop is given below: do { //code to be executed / loop body //update statement } while (condition); Figure 5 The Flowchart show how Do While Lopp works [5] javaTpoint.com Example
#include<stdio.h> #include<stdlib.h> void main () { char c; int choice, dummy; do { printf("\n1. Print Hello\n2. Print Javatpoint\n3. Exit\n"); scanf("%d",&choice); switch (choice) { case 1: printf("Hello"); break ; case 2: printf("Javatpoint"); break ; case 3: exit (0); break ; default : printf("please enter valid choice"); } printf("do you want to enter more?"); scanf("%d",&dummy); scanf("%c",&c); } while(c=='y'); }
The header file stdio.h stands for Standard Input Output. It has the information related to input/output functions.