Introduction to Programming Languages: Focusing on C, Assignments of Programming Languages

An overview of programming languages, with a focus on C. It covers the definition and types of programming languages, the benefits of using C, and an introduction to the C language. Topics include data types, variables, functions, and control structures.

Typology: Assignments

2021/2022

Uploaded on 08/01/2022

trantuantd14
trantuantd14 🇻🇳

4.3

(4)

25 documents

1 / 36

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
23rd of October 2021
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Tran Anh Tuan
Student ID
GCD201675
Class
GED1001
Assessor name
Phan Thanh Tra
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
Tuan
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
pf23
pf24

Partial preview of the text

Download Introduction to Programming Languages: Focusing on C and more Assignments Programming Languages in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog^102 :^ Procedural^ Programming Submission date 23 rd^ of October 2021 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Tran Anh Tuan Student ID GCD Class GED1001 Assessor name Phan Thanh Tra 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 Tuan Grading grid P1 P2 P3 M1 M2 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Table of table

  • Chapter 1. Procedural programming
      1. Programming languages
      • 1.1. Definition
      • 1.2. Types of programming language
      1. C Language
      • 2.1. Definition
      • 2.2. Classification of programming languages
      • 2.3. Introduction to C language
      1. Procedural programming
      • 3.1. What is procedural programming
      • 3.2. Characteristics of procedural programming
        • 3.2.1. Predefined functions.............................................................................................................................
        • 3.2.2. Local variable
        • 3.2.3. Global variable
        • 3.2.4. Modularity
        • 3.2.5. Parameter passing
      • 3.3. Advantages and Disadvantages of Procedural Programming......................................................................
  • Chapter 2. Analysis of the problem is given
      1. Identify Input, Output
      • 1.1. In/Out variables
      • 1.2. Main Variable
      • 1.3. Menu selection
      1. Data type in Procedural Programming (C language)
      • 2.1. Integer data type
      • 2.2. Floating point type
      • 2.3. Double type..................................................................................................................................................
      • 2.4. Character type
      • 2.5. Variable and datatypes in this program.......................................................................................................
      1. What is variables and data types
      • 3.1. Solutions used in the problem
      1. What is conditional statement
      • 4.1. If Statement
      • 4.2. If-else statement
      • 4.3. Switch-case statement
      • 4.4. Variables outside the main function
      1. Loop statement
      • 5.1. While Loop
      • 5.2. Do-While Loop
      • 5.3. For loop
      1. Functions.............................................................................................................................................................
  • Chapter 3. Design a procedural programming solution for a given proble
      1. WBS
      1. Flowchart
  • Table 1. Different between high level and low level language.....................................................................................
  • Table 2. Integer datatype
  • Table 3. Floating point type
  • Table 4. Double type
  • Table 5. Character type
  • Table 6. Variable names and Data types
  • Figure 1. Programming languages Table of figure
  • Figure 2. Types of programming language
  • Figure 3. C language
  • Figure 4. High Level and Low Level
  • Figure 5. Structure of C program
  • Figure 6. Procedural programming
  • Figure 7. Predefined functions....................................................................................................................................
  • Figure 8. Local variable
  • Figure 9. Global variable
  • Figure 10. Simple program..........................................................................................................................................
  • Figure 11. Variable
  • Figure 12. Modularity
  • Figure 13. Pass by value
  • Figure 14. Pass by reference
  • Figure 15. Pass by the name
  • Figure 16. Pass by result
  • Figure 17. Main Variable
  • Figure 18. Menu
  • Figure 19. A variable
  • Figure 20. Data types
  • Figure 21. If-else statement
  • Figure 22. If-else statement (max)
  • Figure 23. If-else statement (min)
  • Figure 24. Switch-case statement
  • Figure 25. Input ID
  • Figure 26. InputGrade
  • Figure 27. Find Highest Grade
  • Figure 28. Find Lowest Grade
  • Figure 29. While Loop
  • Figure 30. Do-While Loop
  • Figure 31. For Loop
  • Figure 32. Functions....................................................................................................................................................

1.2. Types of programming language Currently there are more than 700 programming languages but the following 10 are hot in recent years:

  • JavaScript
  • Python
  • C/C++
  • Java
  • PHP
  • Swift
  • C# (C-Sharp)
  • Ruby
  • Objective-C
  • SQL Figure 2. Types of programming language

2. C Language

2.1. Definition

  • C is a general-purpose programming language that is 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. [2] Figure 3. C language
  • C has facilities for structured programming and allows lexical and recursive variable scoping. Its static type system prevents unintended operations.
  • The C programming language is an imperative language developed in the early 1970s by Dennis Ritchie for use in the UNIX operating system. Since then, this language has spread to many other operating systems and has become one of the most popular languages. 2.2. Classification of programming languages Programming languages are divided into two categories:
  • High-Level: C, C++, Java, Python, etc
  • Low-Level: assembly language and machine language

2 .3. Introduction to C language C is a procedural programming language. Dennis Ritchie was the first to create it in 1972. It was created primarily as a system programming language for creating an operating system. The fundamental characteristics of the C language include low-level memory access, a simple set of keywords, and a clean style; these characteristics make the C language appropriate for system programming, such as operating system or compiler development. (GeeksforGeeks, 2021) Figure 5. Structure of C program The greatest benefit of C, in my opinion, is its tremendous interoperability. C program is being utilized for this one computer and one operating system; It can be simply changed to another computer or operating system. C is a fast-loading language that is appropriate for a wide range of microprocessors. As a result, most computers today utilize the C programming language C, on the other hand, is only appropriate for high-speed applications or system programs. When confronted with more complicated issues, C became confused and difficult to handle.

3. Procedural programming

Figure 6. Procedural programming For general-purpose programming, procedural programming is useful. On the other hand, procedural programming is difficult to express using real-world objects. Procedure-oriented systems concentrate on mainipulation rather than data, which might pose issues in some data- sensitive situations. 3.1. What is procedural programming Procedural programming may be the first programming paradigm leamed by a new developer. Fundamentally, procedural code is the code that tells a device how to do a task in logical stages. This paradigm employs a top-down linear approach and regards data and methods as distinct entitles. Procedural programming splits the program into sections based on the idea of a procedure call. Simply put, procedural programming is putting down a series of instructions that inform the computer what to do step-by-step to complete the task at hand. (Bhatia, 2021)

3.2.2. Local variable A local variable is a variable that is given local scope. Local variable references in the function or block in which it is declared override the same variable name in the larger scope. Figure 8. Local variable 3.2.3. Global variable A global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program unless shadowed. The set of all global variables is known as the global environment or global state. Figure 9. Global variable

As we learn to code, we will learn the basics of how to output “Hello World!” to the screen. To do this, we start with the simplest “printf” command that prints the words “Hello World!” Figure 10. Simple program

  • Variable are containers for storing data values.
  • In C there are 5 basic data types. All other data types are based on one of these. The 5 data types are: ➢ Int: is an integer, it basically denotes the natural size of integers. ➢ Float and double: are used for floating point numbers. The float (read number) type takes up 4 bytes and can have up to 6 part numbers after the decimal point, while double occupies 8 bytes and can have up to 10 decimal places. ➢ Char: occupies 1 byte and can store a single character. ➢ Void: is typically used to declare a function that does not return a value. This will be discussed more clearly in the function section.
  • The memory capacity and range of these types vary with each processor type and the installlation of C compilers. Rules for naming C variable:
  • The variable name must start with a letter or an underscore.
  • Case matters when it comes to variables.
  • They can be made up of digits or letters.
  • Except for underscore, no other special characters are permitted.
  • Variable names include sum,height, and_value. [ 3 ]

3.2.5. Parameter passing Parameter passing is a technique that allows parameters to be sent to funtions, subroutines, or procedures. Passing parameters can be performed “pass by value”, ”pass by reference”, “ pass by result”, “pass by value results” and “pass by the name”.

  • Pass by value Figure 13. Pass by value
  • Pass by reference Figure 14. Pass by reference
  • Pass by the name Figure 15. Pass by the name
  • Pass by value-result Figure 16. Pass by result

The use of local variable can have some benefit and drawbacks Benefits:

  • Using local variables avoid atteration of the function on global variables, retaining data integrity.
  • Since the variables are only recognized within the function that they get declared in, diffirent functions can declare local variables with the same name.
  • Local variable values get destroyed at the end of the function, this helps release the storage that they take, reduce the toll of memory. Chapter 2. Analysis of the problem is given

1. Identify Input, Output

1.1. In/Out variables

  • Input variables ➢ Student stdList[100]: used to store student information ➢ Struct student{}: to store each student ➢ Char name[50]: to store the name of each student ➢ Int ID: to store each student’s ID ➢ Double grade: to store a grade of each student
  • Output variables ➢ The student with the highest score ➢ The student with the lowest score 1.2. Main Variable
  • Int IDs: Used to store each student’s ID
  • Double grade: Used to store each student’s grade Figure 17. Main Variable

1.3. Menu selection Figure 18. Menu

  • The switch statement allows a variable to be checked for equality against a list of values. And using switch cases will make our code easier to write and read

2. Data type in Procedural Programming (C language)

Each variable in C has a corresponding data type. Each data type necessitates a different amount of memory and has its own set of operations that can be performed on it. Let us go through them one by one. The following are some examples of very common data types used in C 2 .1. Integer data type An int variable is used to store an integer, as the name implies. Table 2. Integer datatype Type Size (bytes) Range Int or signed int 2 - 32.768 to 32767 Unsigned int 2 0 to 65535 Short in or signed short int 1 - 128 to 128 Unsigned short int 1 0 to 255 Long int or signed long int 4 - 2,147,483,648 to 2,147.483, Unsigned long int 4 0 to 4,294,967,