Procedural Programming in C: A Practical Guide for Beginners - Prof. Phan Minh, Thesis of Programming Paradigms

Procedural programming đạt điểm M

Typology: Thesis

2021/2022

Uploaded on 12/11/2022

thangttq233
thangttq233 🇻🇳

2 documents

1 / 33

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
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
Trương Trần Quang Thắng
Student ID
GCD210665
Class
GCD1103
Assessor name
Phan Thanh Trà
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
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

Partial preview of the text

Download Procedural Programming in C: A Practical Guide for Beginners - Prof. Phan Minh and more Thesis Programming Paradigms 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Trương Trần Quang Thắng Student ID GCD Class GCD1103 Assessor name Phan Thanh Trà 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

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

  • Scenario: Contents
  • A. Introduction:.............................................................................................................................................................
    • I. Programming languages:(P1)
        1. Definition:
        1. Programming high-level:
        1. Low-level languages:
    • II. C programming language
        1. History begin
        1. Features:
    • III. Procedural programming:
        1. Definition:
        1. Structure of programming languages:
        1. Key features of procedural programming:
    • IV. User requirement:
    • V. Use case diagram: (M1)
    • VI. Advantages and disadvantages of procedural programming: (M1)
        1. Advantages:
        1. Disadvantages:
  • B. ANALYZE THE SITUATION: P2
    • I. Variables and Data Types
        1. Variables:
        1. Data types:
        1. Array:
        1. Struct:
    • II. Conditional statement (P2):
        1. If :
        1. If … else statement:
        1. Switch-case:
    • III. Loop Statement:
        1. For:
        1. Do – While:
        1. While:
    • IV. Design (P3,M2)
        1. WBS
        1. Flowcharts
        1. Review the flowchart:
        1. Discuss alternative solution if possible:
    • V. Evaluation: D1
  • Reference:
  • Figure 1. Statistics of TABLE OF FIGURE
  • Figure 2.High level programming languages................................................................................................................
  • Figure 3.Features of C language
  • Figure 4.Structure of programming languages
  • Figure 5.Local variable
  • Figure 6.Global variable
  • Figure 7.Call by value.................................................................................................................................................
  • Figure 8.Call by value.................................................................................................................................................
  • Figure 9.Output of call by value
  • Figure 10.Call by reference
  • Figure 11.Call by reference
  • Figure 12.Output of call by reference
  • Figure 13.stdio.h library..............................................................................................................................................
  • Figure 14.Use case diagram
  • Figure 15.Declare data types
  • Figure 16.declared with a specific value.....................................................................................................................
  • Figure 17.Data types
  • Figure 18.Data types I choose for my assignment
  • Figure 19.Flowchart of If condition
  • Figure 20 Syntax of if - else......................................................................................................................................
  • Figure 21.Syntax of switch-case
  • Figure 22.Flowchart of switch-case
  • Figure 23.Syntax of do while loop..............................................................................................................................
  • Figure 24.Flowchart of do-while loop
  • Figure 25.Syntax of while loop...................................................................................................................................
  • Figure 26.Flowchart of while loop..............................................................................................................................
  • Figure 27.WBS
  • Figure 28.Flowchart
  • Figure 29.Flowchart
  • Figure 30.Flowchart
  • Figure 31.Flowchart
  • Figure 32.Flowchart

Figure 1. Statistics of 2019

2. Programming high-level: Any programming language that makes it possible to create programs in a much more user-friendly environment and is typically independent of the hardware architecture of the computer is referred to as a high-level language. A high-level language is more abstracted from the computer and concentrates on the programming logic rather than the supporting hardware, such as register usage and memory addressing. Figure 2 .High level programming languages 3. Low-level languages: A programming language known as a low-level language works with the limitations and hardware of a computer. It operates to control a computer's operational semantics and has no (or very little) abstraction in relation to computers. A computer's native language is another name for a low-level language. **II. C programming language

  1. History begin** Bell Labs produced the C programming language in the early 1970s. The C programming language was developed in the early 1970s as a system implementation language for the developing Unix operating system, claims Dennis Ritchie's Bell Labs paper The Development of the C Language.

2. Features: Figure 3 .Features of C language **III. Procedural programming:

  1. Definition:** A sort of development code called procedural programming language gives instructions to a gadget so it can carry out specific tasks. Professional programmers often start out learning to use this as one of their first languages. To construct a set of instructions for a device, procedural programming languages divide stages into consequential functions. As a result, a task can be effortlessly completed by the computer, tablet, or phone with minimum user involvement. 2. Structure of programming languages: The three primary building blocks of every programming language are listed in this essay as follows: (1) the fundamental program statement; (2) the mechanisms for connecting fundamental statements; and (3) the methods through which a program can receive data inputs. Additionally, various alternate versions of each of these elements are discussed, contrasted, and assessed. Examples abound, many of which come from list processing languages, to show the various forms. The study finishes by suggesting that programming languages grow toward ones that will allow all the most practical ways of constructing programs, organizing systems, and referencing data. The pros, cons, and factors influencing the choice of a kind of component for a language are examined.

3.3. Global variable: In contrast to local variables, global variables operate differently. Global variables are accessible to developers in almost all functions. In contrast to a global variable, which is visible across the whole programming language, a local variable only exists within a predefined scope. Figure 6 .Global variable 3.4. Parameter passing: The data values that are transferred from each function in a series are known as parameters. Developers that use parameter passing pass input parameters to a module or device and get output parameters back. Parameters can be passed to functions and procedures via this technique. 3.4.1. Important methods of parameter passing: 3.4.1.1. Pass by value: Utilizing in-mode semantics is this way. Formal parameter changes are not sent back to the caller. Any changes to the formal parameter variable made inside the called function or method will only have an impact on the separate storage location and not the real parameter in the calling environment. Call by value is another name for this technique. Figure 7 .Call by value

Figure 8 .Call by value Figure 9 .Output of call by value 3.4.1.2. Pass by reference (aliasing): This method employs the semantics of in/out-mode. Through parameter passing, changes made to formal parameters are returned to the caller. The formal parameter obtains a reference (or pointer) to the actual data, thus any changes to the formal parameter are reflected in the actual parameter in the calling environment. Another name for this mechanism is call by reference. This approach is effective in terms of time and distance.

Figure 12 .Output of call by reference 3.5. Modularity: The structure of modularity is when a developer breaks down the functionality of their code into a number of smaller components. Then, the programmer can access these blocks, which are frequently referred to as methods or functions in procedural programming languages, by calling them in their code. 3.6. Procedures: A procedure is a way of carrying out a work that includes steps and instructions for every part of the job. Once developed, procedures are frequently followed consistently to ensure a common understanding of what personnel should do in various situations. In order for staff to follow procedures effortlessly and for new hires to use them as a resource for learning how the office runs, those who develop procedures frequently strive for maximum specificity. Each aspect of a firm may have its own procedures, but you may encounter them through training manuals, information sessions, and guided tutorials. Example: Client check-in emails are a crucial component of our business. We service a number of accounts concurrently, so it's important to keep track of the progress we're making with each customer to make sure we're giving them all they require. The two main personnel categories most likely to use this approach regularly are account executives and sales reps. The procedures for sending a check-in email to your clients will be outlined in this procedure, including how to address them, what to include, and how to sign off. The following materials are required for this process:  a computer  internet access  your company email account  a client list with email addresses Steps for sending check-in emails to clients:  Find the client's email address to check in with.  Identify the services we rendered to the client.  Open a new email draft in your company's email program.

 Include the client's first name or their title and last name in the salutation when addressing the email to them.  In the first paragraph of the email, mention the service we offer to the client using the following words: "Just wanted to give you an update on the ____ we did for you on.  In the email's second paragraph, provide an extra service by saying something like, "We also provide __ services for all of your __ needs."  Use words like these to invite the client to get in touch with you: "You may reach out to me at any time with any 3.7. Programming libraries: A library is a group of documents, applications, scripts, routines, or other pieces of code that can be used as references in computer programming. The programmers who created the programming language may have even created these libraries, which are more sophisticated than routines and optimized. Example: Figure 13 .stdio.h library 3.8. Programming paradigm: Programming paradigm is a word used to describe a general method of writing program code. The procedural programming paradigm divides program code into distinct chunks called procedures, each of which performs a specific task. Procedures, which are sometimes known as subroutines or functions, include a number of computational processes that must be completed in the order determined by the programmer. A purely procedural language is one like the programming language C. Numerous programming languages do, however, allow various paradigms. For instance, the well-liked general-purpose programming language Python enables you to write code that is procedural, object-oriented, or functional. Examples of Procedural programming paradigm: C: developed by Dennis Ritchie and Ken Thompson IV. User requirement:  As a teacher, I want to enter my students' IDs and grades so that I can access any or all of them when I need to.  As a teacher, I want to print all student IDs together with their grade so that I can send grades to the parents of the students.

 Numerous books and online courses on tried-and-true algorithms are accessible, making it simpler to pick things up as you go.  Because the source code is portable, it can also be used to target a different CPU.  Without having to copy it, the code can be used in multiple areas of the application.  Additionally, reduced by using procedural programming is the memory need.  Tracking the program flow is simple.

2. Disadvantages:  When procedural programming is used, writing the program code is more difficult.  Because procedural code is frequently not reusable, it could be necessary to rebuild it if it needs to be used in another application.  Difficult to link to objects in the actual world  The procedure is given more importance than the data, which could cause problems in particular circumstances where the data is sensitive.  Because the data is accessible to the entire program, it is less security-friendly. **B. ANALYZE THE SITUATION: P I. Variables and Data Types

  1. Variables:** A variable is nothing more than a name given to a storage space that is accessible to our applications. Each variable in C has a unique type that specifies its memory size and organization, the range of values that can be placed inside, and the range of operations that can be performed on the variable. Figure 15 .Declare data types The statement int I j, k; tells the compiler to create int variables with the names I j, and k. These variables are declared and defined in this statement. In their declaration, variables can be initialized (given a starting value). The equal sign is followed by a constant expression in the initializer, as shown below-

Figure 16 .declared with a specific value

2. Data types: A variable's data type and the kinds of mathematical, relational, and logical operations that can be performed on it without producing an error are classified as data types in programming. For instance, a data type called a string is used to categorize text, while a data type called an integer is used to categorize whole numbers. Figure 17 .Data types 3. Array: An array is a grouping of data elements of a similar sort that are kept in close proximity to one another in memory. In the C programming language, arrays are a derived data type that may contain primitive data types like int, char, double, float, etc. Additionally, it has the capacity to store a variety of derived data types, including pointers, structures, and so forth. The following attributes are present in the array:  An array's elements all have the same data type and size, which is int = 4 bytes.

Student has lowest score Mingrade Float Student’s grade is a real number from 0 to 10 Option n Integer Option is a number from 1 to 5 Figure 18 .Data types I choose for my assignment II. Conditional statement (P2):

1. If : The if statement is used to examine a given condition and carry out actions based on whether or not it is true. It is frequently employed in situations where we must carry out several procedures under various circumstances. Below is a list of the if statement's syntax. Figure 19 .Flowchart of If condition 2. If … else statement: There might be an optional else block in the if statement. The if..else statement has the following syntax:

Figure 20. Syntax of if - else How if...else statement works? If the test expression is evaluated to true,  statements inside the body of if are executed.  statements inside the body of else are skipped from execution. If the test expression is evaluated to false,  statements inside the body of else are executed  statements inside the body of if are skipped from execution. 3. Switch-case: In C, the switch statement is an alternative to the if-else-if ladder statement that enables us to do several operations for the various potential values of a single variable called the switch variable. Here, we can define different statements in a variety of situations for varied values of a single variable. The following is the syntax for the switch statement in the C language: Figure 21 .Syntax of switch-case