Introduction to Programming Languages: Types, C Language, and Control Statements, Assignments of Computer Science

An introduction to programming languages, their types (low-level, middle-level, and high-level), applications, and specific examples using the C language and its procedural programming paradigm. It covers the basics of structured programming, pre-defined functions, data types, and control statements such as conditionals and loops.

Typology: Assignments

2020/2021

Uploaded on 12/01/2021

nguyen-huu-hieu-fgw-dn
nguyen-huu-hieu-fgw-dn 🇻🇳

4.8

(17)

15 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: 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
Hieu
Grading grid
P1
P2
P3
M1
M2
D1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Introduction to Programming Languages: Types, C Language, and Control Statements and more Assignments Computer Science in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog102: 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 Hieu Grading grid P1 P2 P3 M1 M2 D

r Summative Feedback:Resubmission Feedback: Grade: Assessor Signature: Date: Lecturer Signature:

Contents

  • Section 1 : Introduction to programming languages
    • Section 1.1 : Types of programming languages
      • Section 1.A: Low-level programming language:
      • Section 1.B: Middle-level programming language:
      • Section 1.C: High-level programming language:................................................................................
      • Applications of programming languages in life:
  • Section 1.2: C language :
  • C
  • Section 1.3 : Procedural Programming :...............................................................................
  • Section 1.4 : Characteristics of structured programming:
  • Section 1.5 : Pre-defined functions:
  • Section 1.6 : Variables :
  • Section 1.7 : Data type :
  • Section 1.8: Condition Statements :
  • Section 1.9 :Loop statements and describe iteration construct:
  • Section 1.10 : C – Functions:.................................................................................................
  • Section1.11:Design:...............................................................................................................
  • Section 1.12 :Flowchart :

Figure 1 C programming languages .............................................................................................................. 5 Figure 2 C language ....................................................................................................................................... 7 Figure 3 ......................................................................................................................................................... 8 Figure 4 ......................................................................................................................................................... 8 Figure 5 ....................................................................................................................................................... 11 Figure 6 ....................................................................................................................................................... 12 Figure 7 ....................................................................................................................................................... 13 Figure 8 ....................................................................................................................................................... 13 Figure 9 ....................................................................................................................................................... 18 Figure 10 ..................................................................................................................................................... 18 Figure 11 ..................................................................................................................................................... 19 Figure 12 ..................................................................................................................................................... 20 Figure 13 ..................................................................................................................................................... 20 Figure 14 ..................................................................................................................................................... 21 Figure 15 ..................................................................................................................................................... 22 Figure 16 ..................................................................................................................................................... 22 Figure 17 ..................................................................................................................................................... 23 Figure 18 ..................................................................................................................................................... 25 Figure 19 ..................................................................................................................................................... 26 Figure 20 ..................................................................................................................................................... 28 Figure 21 ..................................................................................................................................................... 29 Figure 22 ..................................................................................................................................................... 31 Section 1 : Introduction to programming languages A programming language is a form of computer language that is used to write software, scripts, or instructions for the computer to follow. There are many programming languages in use today. Although the languages also have similarities, each language has its own syntax to use. The job of the programmer is that they have to learn the rules, syntax and structure of the language, then write the source code in an editor or IDE and compile the code into machine language that the computer can understand.. Scripting

Section 1.B: Middle-level programming language:

This is an intermediate programming language between high-level programming language and low-level programming language, also known as intermediate programming language. The language is both user-friendly and can communicate close to the machine. For example: C, C++ are two typical intermediate languages.

Section 1.C: High-level programming language:

A programming language redesigned to be easy to read, understand, write and maintain for the development of natural language friendly software, application programs or websites. A high-level programming language would require a compiler to translate into machine language for the machine to understand. There are three main types in high-level programming languages: ▪ Procedural Oriented programming language ▪ Object-Oriented Programming language ▪ Natural language Applications of programming languages in life: ▪ Software and application development ▪ Building artificial intelligence ▪ Database Development ▪ Website construction

Section 1.2: C language :

C language is a procedural programming language. It was initially developed programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development.It extremely popular, simple, and flexible to use. It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Git, Python interpreter, and more.

Figure 2 C language

Section 1.3 : Procedural Programming :

Procedural programming is the way to implement the above function- oriented approach. The procedural approach divides a large program (function) into blocks of functions or functions (procedures) that are small enough to be easy to program and test. Each function has a start and an end point and has its own data and logic. In a program system, variables have certain visible scopes. In a program, functions work independently of each other. Data is converted back and forth through function call parameters. Dividing a program into functions allows multiple people to participate in the

B. Advantages and Disadvantages of Procedural Programming a) Advantage ▪ Procedural Programing is a great way to program in general. ▪ The code simplicity,as well as ease with which compilers and interpreters can be implemented ▪ A wide range of book and online course materials on tried algorithm are available,making it easier to learn as you go. ▪ The code can be reused without having to copy it in various sections of software ▪ The program flow can be tracked easily. b) Disadvantages ▪ If Procedural Programming is used , the program code is more difficult to writer. ▪ The Procedural code is often not reusable whichmay pose the need to recreate the code if need to use another application ▪ Diffcult to relate with real-world objects. ▪ The Process is prioritzed over the data ,which can cause problem in data-sensitive situation. ▪ The data is exposed to whole program, making it not so much security friendly.

Section 1.4 : Characteristics of structured programming:

Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines. Structured programming is a program written with only the structured programming constructions: (1) sequence, (2) repetition, and (3) selection.

▪ (1)Sequence. Lines or blocks of code are written and executed in sequential order. ▪ (2)Repetition. Repeat a block of code (Action) while a condition is true. ▪ (3)Selection. Characteristics, Properties : Program = Data structure + Algorithm Data structure : ▪ Data structure: how to describe, organize data ▪ Algorithm: algorithm, steps to solve the problem The basic properties of structured programming are: ▪ Focus on the work to be done (algorithms) ▪ A large program is divided into subroutines, each of which can be called one or more times in any order. A large program is divided into subroutines, each of which can be called one or more times in any order. A large program is divided into subroutines, each of which can be called one or more times in any order. ▪ Most functions use common data ▪ Data in the system is moved from one function to another. ▪ Function that converts data from one form to another ▪ Using a top-down approach in program design Advantages and Defect : Advantages: ▪ Provides an ability to reuse the same code at various places. ▪ Facilitates in tracking the program flow. ▪ Capable of constructing modules. Defect:

Figure 6

Section 1.6 : Variables :

A variable is data name that may used to store a data value and it may be s word or variable name. A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C 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. The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive. Based on the basic types explained in the previous chapter, there will be the following basic variable types.

Sr.No. Type & Description 1 char Typically a single octet(one byte). It is an integer type. 2 int The most natural size of integer for the machine. 3 float A single-precision floating point value. 4 double A double-precision floating point value. 5 void Represents the absence of type. Example 1 : Figure 7 Example 2 : Figure 8

unsigned char 1 byte 0 to 255 signed char 1 byte - 128 to 127 int 2 or 4 bytes

  • 32,768 to 32,767 or - 2,147,483, to 2,147,483, unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967, short 2 bytes - 32,768 to 32, unsigned short 2 bytes 0 to 65, long 8 bytes or (4bytes for 32 bit OS) - 9223372036854775808 to 9223372036854775807 unsigned long 8 bytes 0 to 18446744073709551615 Floating-Point Types : The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision :

Type Storage size Value range Precision float 4 byte 1.2E-38 to 3.4E+38 6 decimal places double 8 byte 2.3E-308 to 1.7E+308 15 decimal places long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places Based on the problem you gave me, I will create variables and set their data types as follows :

  1. If …else statement
  2. Nestled if staterments
  3. If - eles - If ladder
  4. Switch statements 1) If statement : You can use the if statement to control whether or not a program enters a block of code based on wether or not particular condition is true or flase. The if statement allows the computer to choose an action based on the user’s input ,which is one of its most significant roles. Sytax of if statement: Figure 9 2) If-else statement: The if-else statement is used to execute the code if condition is true or false. It is also called two-way selection statement. if the value of test- expression is true, then the true block of statements will be executed. If the value of test-expression if false, then the false block of statements will be executed. In any case, after the execution, the control will be automatically transferred to the statements appearing outside the block of If. Sytax of if - else statement: Figure 10

How "if..else" statement works.. ▪ (^) If the expression is evaluated to nonzero (true) then if block statement(s) are executed. ▪ (^) If the expression is evaluated to zero (false) then else block statement(s) are executed. 3) Nestled if statement: The nested if...else statement is used when a program requires more than one test expression. It is also called a multi-way selection statement. When a series of the decision are involved in a statement, we use if else statement in nested form. Syntax of Nestled if statement: Figure 11 4) If..else If ladder : The if-else-if statement is used to execute one code from multiple conditions. It is also called multipath decision statement. It is a chain of if..else statements in which each if statement is associated with else if statement and last would be an else statement. Syntax if-else-if statement :