Docsity

ASM1-Prog102-IT Functional, Study Guides, Projects, Research of C programming

Partial preview of the text

Download ASM1-Prog102-IT Functional and more Study Guides, Projects, Research C programming in PDF only on Docsity!

Assignment 1

Au Lam Thanh Dat

ID: GCS

Class: GCS1003A

Subject code: PROG

Date: 02/22/

Version: 1.

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 Au Lam Thanh Dat 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 Dat 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 D1 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. Provide an introduction to procedural programming

1. Introduction: 1.1. Introduction to computer programming languages: Programming language is a standardized language based on a set of principles that allows programmers to define workable programs for both human and technological devices. All of this is understandable.  Computer programming languages includes: 1.2. High-level languages: This is a highly abstract language in computer science (machine learning). To understand programs that operate on different platforms and architectures, high-level programming languages are frequently utilized. High-level programming languages are extremely self- contained. It is unaffected by the sorts of processing devices or translators used. It may employ natural language features that are easier to use or can automate important portions of a computer system (e.g. memory management) compared to low-level programming languages, making program creation simpler and comparably easier to grasp. The FORTRAN language was the first high-level language created in 1956. There are several high-level languages available today. PASCAL, C, C+, C++, C#, Visual Basic, Python, Cobol, BASIC, Ruby, Java, and more programming languages.

  • Example coding by FORTRAN, C++: Outputing “Hello World” + FORTRAN program NewProgramF Write(,) “Hello World” End program NewProgramF + C++ #include <stdio.h> int main(); { printf(“Hello World”); }

1.3. Low-level languages: A low-level programming language is a programming language that is closely tied to computer hardware in computer science. The term "low" does not imply that this language is inferior to high-level programming languages; rather, it indicates that its instructions are extremely similar to those of a machine. However, the term "low-level programming language" is only used in a limited sense; for example, Java programmers may believe C to be a low-level programming language, despite the fact that it is categorized as such.Assembly is a well-known example of a low- level programming language among computer languages. It's a term used to describe languages that aren't machine languages but are quite similar to them.

2. Introduction to procedural programming: 2.1. Procedural programming: Procedural programming is a programming paradigm that uses a direct or top-down approach. It relies on procedures or subroutines to perform computations. Procedural programming is also known as imperative programming. 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 launch and an endpoint and has its own data and sense. In a program system, variables have clearly visible reaches. In a program, functions work singly of each other. Data is converted back and forth through function call parameters. 2.2. Procedural programming's main characteristics. Control-oriented programming focuses on a data block with optional actions that the program can do at the declaration event. Each "event" in the Word processor, for example, refers to any mouse or keyboard adjustments (or files) that influence data or documents (s). They don't have to be made in any particular order. Tiny programs (event handlers) are used in event-driven programming to act on a shared data set, allowing each small program to use the same data and documents in this example.

 E.g.,  Integer constants: 1, 2, 3,…  Floating constants: 1.1, 2.3, 4.0,...  Character constants: ‘a’, ‘b’, ‘c’,…  (^) String literals: “Hello”, “Hi”, … 1.2. Data types required A data type is a property of a piece of data that instructs a computer system on how to interpret the data's value. Understanding data types ensures that data is collected in the correct format and that the values of each attribute are correct. A data type instructs the compiler to store a bit value from a range y in memory cell x alone. It prevents the compiler from storing new values outside of the specified range. Please keep in mind that data kinds are not the same as the two sorts of consumer data: reality and event data. To put it another way, "a data type is a means for notifying the compiler whose data (integer, character, pier, etc.) is expected to be stored and how much memory to allot as a result."

1.2.1 Basic types

They are arithmetic types that are divided into two categories: integer types and floating- point types.

1.2.2 Enumerated types

They're arithmetic types again, and they're utilized throughout the program to construct variables that can only assign discrete integer values.

1.2.3 The type void

The type specifier void indicates that no value is available.

1.2.4 Derived types

Pointer kinds, Array types, Structure types, Union types, and Function types are some of them.  Solutions used in the problem: To solve the problem, I'll use two types of data to create relevant variables: integer and float. Because these variables can only hold integer values, I'll use an integer to specify the number of students, student IDs, MaxGrade, MinGrade, and the menu option. Because these variables contain both integer and real values, the float will be utilized to declare a student's greatest grade, lowest grade, and cumulative grade.

2. Selection Structures (if-else, switch-case) 2.1. If-else  if (condition) { Statement 1; Condition is true } else { Statement 2; Condition is false }  Example: Exercise: Enter an integer, check if the number is even? #include <stdio.h> int main() { int a;

Long if statements that compare a variable to several integral values can be replaced with switch-case statements. The switch statement is a branch statement that may be used in a variety of ways. It's simple to dispatch code execution sections based on the expression's value. A switch statement is a control statement that allows you to change the execution control of a value. 2.2.2. Example Exercise: Enter a number between 1 -> 5 and print out the corresponding reading. { int a; printf("Input a = "); scanf("%d", &a); switch(a) { case 1: printf("One\n"); break; case 2: printf("Two\n"); break; case 3: printf("Three\n"); break; case 4: printf("Four\n"); break; case 5: printf("Five\n"); break; default: printf("You inputed other number\n"); break;  Solutions used in the problem:

  • I'll use the switch-case statement in the "Display menu" function to create a menu of options with five options. If you choose one of the options from 1 to 5, the program will display the message "wrong input, please import again" on the screen; if you choose one of the other five options, the software will display the message "wrong input, please import again." The following are five options that I would want to use in my program:
  1. List the total number of students, their grades, and their ID numbers.
  2. Find out a student's ID and grades.
  3. Decide who will receive the highest rating.
  4. Find out who had the lowest grade.
  5. Turn off the computer.
  • The if-else expression may really be used to build a menu of options. The switchcase statement, on the other hand, appears to be more appropriate because it was created to be used in situations when the expression is tested in several values (cases) and the menu of options has a large number of options.
  • I'll use the if statement to determine which student gets the highest and lowest grade, thus it'll be utilized in the "Print Max Grade" and "Print Min Grade" functions. Its

conditions are "maxGrade arrGrade[i]" and "minGrade > arrGrade[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/her ID. On the other hand, it will display the grades of the following student along with his or her ID. It's akin to learning your minimum grade.

  • I'll use the if statement to figure out which child gets the highest and lowest grade, thus it'll be utilized in the "Print Max Grade" and "Print Min Grade" routines. Its conditions are "maxGrade > arrGrade[i]" and "minGrade > arrGrade[i]," and it will help me compare the grade of the first student to 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 first student's grade, which is known as the highest grade. On the other side, it will show the following student's grades. It's similar to determining your minimal grade.

3. Iteration constructs (for, while, do-while) 3.1. For A "For" loop is a programming construct that repeatedly executes a block of code (statement). The for-loop statement is a highly customizable while loop that improves your app's readability. The for loop has the following syntax.  for ( variable _initialization; condition; variable _update) { Statement; }  Example: for ( int count = 1 ; count <= 10 ; count ++) { count << “ count = “ << count <<endl ; } 3.2. While Pre-tested loop is another term for while loop. A while loop, in general, allows a section of code to be repeated several times based on a boolean value. To put it another way, it's a looping if statement. The while loop is typically employed when the number of iterations is unknown ahead of time.  while (expression) { Statements; }

understand. We're frequently obliged to rewrite the same line of code, which might lead to redundant code or even bugs. Procedural programming addresses this problem by allowing users to create and construct a set of statements in the form of functions, which they can then use and reuse as required.  Printf (“control string”, argument list);  Scanf (“clain of formats”, “list of parameters”);  (^) Example void main() { int a; float d; char ch, name[40]; printf(“Please enter the date \n”); scanf(“%d %f %c %s”, &a, &d, &ch, name); printf(“\nThe values accepted are: %d, %f, %c, %s”, a, d, ch, name); }  Solutions used in the problem:

  • I'll create a basic application for a math instructor employing seven functions for this work since they make it easier for me to tweak and update the program while also making it appear cleaner.
  • The main function is used to call routines that perform the "displaying menu" and "choosing options" functions within it.
  • The second feature, Displaying Menu, allows customers to see a menu of options. The user's selection will then be returned to the main function, where it will be utilized to execute the following functions.
  • The Choosing Options function is the third function, and it is used to carry out the user's choice by completing the necessary functions.
  • The fourth option, Inputting Student Information, allows you to utilize the keyboard to input the number of students, their grades, and their ID.
  • Student Information Display is the fifth feature, and it displays the grades and IDs of students.
  • The sixth function, Find the highest grade, prints the ID of the student with the highest grade to find which student in the array has the highest grade.
  • Find the lowest grade, the seventh function, is used to find which student in the array has the lowest grade by publishing the student's ID with the lowest grade.

P3.Design a procedural programming solution for a given problem

1. Use-case diagram  Use case diagrams are used to gather the requirements of a system  So when a system is analyzed to gather its functionalities use cases are prepared and actors are identified.  The purposes of use case diagrams can be as follows: - Used to gather requirements of a system - Used to get an outside view of a system - Identify external and internal factors influencing the system - Show the interacting among the requirements are actors. The math teacher must create a grade management system for the students. Start by choosing a menu option. The four basic functions are to enter student information, input the highest grade, input the lowest grade, and print all student information.

2.2. Input student information With the step of entering student information, we'll establish two array variables to record the student's ID and score at this phase.

Begin

Input student ID

Input student grade

Save student ID into array

Save student grade into array

End

2.3. Print all student information We'll use the loop statement in this step to print out the information for all of the students that were input in the previous stage.

Begin

Input all student informations

Save all information into array

End