Docsity

Assignment 1 subject Procedural Programming, Exercises of Computer Science

Partial preview of the text

Download Assignment 1 subject Procedural Programming and more Exercises Computer Science in PDF only on Docsity!

Higher National in Computing

Unit 0 : Procedural Programming

ASSIGNMENT 1

Learner’s name: Tran Quang Hien ID: GCS Class: GCS1003A Subject code: PROG Assignment due: Assignment submitted:

ASSIGNMENT 1 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog102: Procedural Programming Submission date 22/02/2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Tran Quang Hien Student ID GCS Class GCS1003A Assessor name Le Ngoc Thanh 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

Assignment Brief 1 (RQF)

Higher National Certificate/Diploma in Computing

Unit Number and Title Unit 0: IT Fundamental & Procedural Programming Academic Year 2021 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 P1 Provide an introduction to procedural programming M1 Discuss on characteristics and features of procedural programming D 1 Critically evaluate the design of your solution against the characteristics and features of procedural programming. P2 Identify the program units and data and file structures required to implement a given design M2 Review the design of a procedural programming solution. P3. Design a procedural programming solution for a given problem Assignment Brief Scenario:

A math teacher wants to manage grades of a class. He asks you to help him to write a small application to do that. He needs to enter student IDs, student’s grades and store these information into 2 separate arrays (integer array for IDs and float array for grades). Then he needs to print all student IDs together with their grades. Finally, he needs to know which student has highest grade and lowest grade. Your program should be menu based with the options above. When an option is done, the program should go back to the main menu so he can choose another option. There should be an option to quit program. Task 1 To prove your programming ability to be appointed to this small project, please prepare an illustrated guide on programming in general and a particular emphasis on procedural programming. Here you will need to include introduction to computer programming languages and discuss key features of procedural programming. Task 2 Your next task is to do the analysis for the scenario mentioned above by doing the following subtasks

  • Identify the variables and data types required in the program.
  • Identify and describe 2 different selection structures, including the condition(s) to check; state why they are needed and where they can be used in the context of the scenario.
  • Identify and describe any iteration constructs.
  • Split the program into functions (sub-functions) and draw a hierarchy diagram to illustrate the structure of your program. Task 3 You need to use a drawing tool to draw design diagram for your program, includes:
  • A use case diagram for actions required
  • Flow chart diagrams for: menu operation, printing IDs and grades, finding max grade and finding min grade.
  • Review / evaluate your design, state clearly pros vs cons and which needs to improve, using characteristics of procedural programming as bases to discuss. Write a report for 3 tasks above and submit the report to CMS in PDF format. Submission Format The submission is in the form of an individual written report. This should be written in a concise, formal business style using single spacing and font size 12. You are required to make use of headings, paragraphs and subsections as appropriate, and all work must be supported with research and referenced using the Harvard referencing system. Please also provide a bibliography using the Harvard referencing system.
  • P1, M1 Provide introduction to procedural programming......................................................
      1. Introduction to computer programming language
        • 1.1 Low-level language
        • 1.2 High-level language
      1. Introduction to procedural programming
      1. Criteria for chossing a programming language to use
  • design........................................................................................................................................... P2. Identify the programming units and data and file strutures required implement a given
      1. The variables
        • 1.1 The variables
        • 1.2 Data types required
          • 1.2.1 Basic types
          • 1.2.2 Enumcrated types
          • 1.2.3 The type void
          • 1.2.4 Derived types
      1. There are 5 data types in procedural programming
        • 2.1 Int
        • 2.2 Float
        • 2.3 Character
        • 2.4 Double
      1. Selection structures
        • 3.1 If
        • 3.2 If else
        • 3.3 Switch-case
      1. Interation constructs
        • 4.1 For
        • 4.2 While
        • 4.3 Do-While......................................................................................................................
      1. Functions...........................................................................................................................
  • P3, M2. Design a procedural programming solution for a given problem - 1. Use case
      1. WBS diagram
    • 3 The menu operation flowchart.
      1. Entering grades and IDs flowchart
      1. Printing IDs and grades flowchart
      1. Print highest grade
      1. Print lowest grade
      1. Review flowchart
  • D1. Evaluate solution
      1. Advantages........................................................................................................................
    1. Disadvantages
    1. Difficulty
    1. Conclusion.........................................................................................................................

ASSIGNMENT 1 ANSWER P1, M1. Provide an introduction to procedural programming

1. Introduction to computer programming language A programming language is a formal language that has a collection of instructions that generate a variety of outputs. In computer programming, programming languages are used to execute algorithms. Any of several languages for implementing directly when in the computer manufacturer's numerical form known as machine language, after a simple substitution procedure when expressed in a matching assembly language, or after translation from some "high-level" language. As you may be aware, there are several computer languages available, but only a handful are commonly utilized. Machine and assembly languages are "low-level," requiring a programmer to manage all of a computer's distinctive data storage and operating characteristics manually. High-level languages, on the other hand, alleviate these problems by offering a notation that is easier for programmers to write and read. As you may be aware, there are a variety of computer languages to choose from, but only a few are widely used. Machine and assembly languages are "low-level," which means that a programmer must manually manage all of a computer's unique data storage and operational properties. High-level languages, on the other hand, relieve a programmer of these worries by offering a notation that is easy to write and understand for programmers. C, C++, C#, and other programming languages are examples. Figure 1: Programming Language Illustration(Source: Sylvain Saurel)

1.2 High-level language In computer science, a high-level programming language is one that has a high level of abstraction from the machine's specifics. It may employ natural language components, be easier to use, or automate (or even hide totally) major sections of computer systems (e.g. memory management), making the process of building a program simpler and more clear than when using a low-level programming language. A computer language's level of abstraction determines how "high-level" it is. An autocode was a high-level programming language that used a compiler in the 1960s. COBOL and Fortran are two examples of autocodes. Figure 3: Source: Sandeep Verma

2. Introduction to procedural programming Procedural programming is a programming paradigm, derived from imperative programming, based on the concept of the procedure call. Procedures (a type of routine or subroutine) simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself. The first major procedural programming languages appeared circa 1957–1964, including Fortran, ALGOL, COBOL, PL/I, and BASIC. Pascal and C were published circa 1970–1972. Computer processors provide hardware support for procedural programming through a stack register and instructions for calling procedures and returning from them. Hardware support for other types of programming is possible, but no attempt was commercially successful (for example Lisp machines or Java processors).

Figure 4: Procedural Programming Illustration (Source: fromabacustoi7)

3. Criteria for choosing a programming language to use Professionally, we don’t generally get to choose the language to use. The customer does. However, in the event that we should be given the chance to choose. In my opinion, I think here are the crucial criteria:

  • Personal preference – for illustration, stoutly or statically compartmented, object- acquainted or functional or sense- grounded, small and simple or large and full- feature
  • Suitability to your particular problem sphere – for illustration, JavaScript for web, C for systems programming, Python for machine learning
  • Existing software mound – too expensive to replace existing IT staff – too expensive to retrain or replay
  • Compatibility with being law base, ie, design extension.

1.2.1 Basic types They are arithmetic types and are further classified into (a) Integer types and (b) floating-point types. 1.2.2 Enumerated types They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program. 1.2.3 The type void The type specifier void indicates that no value is available. 1.2.4 Derived types They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types. Figure 6: Basic types Illustration(Source: tutorialspoint)

2. There are 5 data types in procedural programming 2.1 Int An integer, in the environment of computer programming, is a data type used to represent real figures that don't have fractional values. Different sorts of integer data types are stored in different ways on computers. An integer is also used to determine an item's position within an array.

  • Integers in the range: from - 32,767 to 32,768. For example: 6523, 0, - 5575.
  • Stored numeric data can not store other types. For illustration"Hien" or"Henry".
  • Size (Depends on the Operating System) typically 32 bits (4 bytes).
  • Declaration: int, num; In this 2.2 Float The type float specifies a single-accuracy value that uses 32 bits of the storehouse. A floating-point data type uses a formulaic symbol of real figures as an approximation so as to support a trade-off between range and accuracy. Variables of type float are useful when you need a fractional component, but don’t require a large degree of accuracy. For this reason, the floating-point calculation is frequently found in systems that include very small and very large real numbers, which require fast processing times.
  • Stores values including decimal places can not store other types. Such as "Hien" or "Henry". The accuracy of up to 6 digits.
  • Declaration: float num;
  • Size (Depends on the Operating System) generally 32 bits (4 bytes).
  • Example: 6.5, 2.3, 18. 2.3 Character The character is also used as a reserved keyword in computer languages, where it is written as chr or char in coding languages. It is a data type that carries one character (letter, integer, etc.) of data and plays an important part in computer programming.
  • Other types such as "Hien" or "Henry" cannot be stored since it only stores single character information.
  • Declaration: char c;
  • Size (Depends on the Operating System) usually 8 bits (1 byte).
  • Examples: 'x', 'y', 'z', '$', '%', '1', '2'. 2.4 Double The double is a basic data type built into the compiler that is used to construct numeric variables that carry decimal integers. The double is recognized as a type in C, C#, C++, and many other computer languages. A double type may represent both fractional and full numbers.
  • Stores values containing decimal places cannot store other type e.g.,”Hien” or “Henry” Precision of up to 10 digits
  • Declaration: double num;
  • Size (Depends on the Operating System) Normall 64 bits (8 bytes)
  • Examples: 18.0, 6.523, 2003

3. Selection structures 3.1 If The ability to direct the flow of your program, allowing it to choose which code to run, is extremely beneficial to a programmer. You may use the if statement to control whether or not a program enters a block of code based on whether or not a particular condition is true or false. The if statement allows the computer to choose an action based on the user’s input, which is one of its most significant functions. For example, by checking a user-entered password with an if statement, your application may determine whether a user is given access to the site. Figure 7: Example for structure if Condition statement (s) False True Rest of code

3.2 If else In C++, an if-else statement is a conditional statement. If a condition is satisfied, the C++ of statement executes a block of code. If the condition is not satisfied, an if-else statement performs the same function but executes the second piece of code. It's possible to nest if and if- else statements. Figure 8: Example for if-else Condition If code Else code If condition is true If condition is false

❖ Solutions used in the problem:

  • In the "YourChoice" function, I'll utilize the switch-case statement to construct a menu of alternatives with five selections. If the decision is one of 1 to 5, the following choices will be executed; if the choice is one of the other five alternatives, the software will show the message "wrong input, please import again" on the screen. The following are five alternatives that I want to employ in my program:
  1. Enter the total number of students, together with their grades and ID numbers.
  2. Look up a student's ID and their grades.
  3. Determine which student gets the highest grade.
  4. Determine which student gets the lowest grade.
  5. Shut down the software.
  • The if-else statement may really be used to construct a menu of possibilities. The switch- case statement, on the other hand, seems more suitable because it was designed to be used in circumstances when the expression is checked in several values (cases) and the menu of alternatives contains a lot of possibilities.
  • About the if statement, I will use it to find out which student has the highest grade and lowest grade, so it’s used in the “FindOutMax” function, “FindOutMin” function. Its condition is :” max < grades[i]” and “min

grades[i]”, and it will help me compare the grade of the first student with the grades of the next student in the array, and if other students' grades are lower than the grade of the first student, it will display the grade of the first student known as the highest grade with his/her ID. In opposite, it will show the grades of the next student with his/her ID. It’s similar to finding out min grade.

  • In terms of the if statement, I'll utilize it to determine which kid has the highest and lowest grade, therefore it'll be used in the "FindOutMax" and "FindOutMin" functions. Its conditions are "max grades[i]" and "min > grades[i]," and it will assist me in comparing the grade of the first student with the grades of the next student in the array, and if other students' grades are lower than the grade of the first student, it will display the grade of the first student, known as the highest grade, along with his or her ID. On the other hand, it will display the grades of the next student along with his or her ID. It's akin to figuring out your minimum grade.

4. Iteration constructs 4.1 For A "For" loop is a programming construct that is used to repeat a block of code (statement) for a specified number of times. The for-loop statement is a highly customized while loop that improves program readability. The for loop has the following syntax.

4.2 While Another name for while loop is pre-tested loop. In general, a while loop allows a portion of code to be repeated several times based on a boolean value. It's a looping if statement, if you will. When the number of iterations is unknown in advance, the while loop is frequently used. Test Expression While Loop Body False True