1. Trang chủ
  2. » Luận Văn - Báo Cáo

PRO102 ASSIGNMENT 2 DISTINCTION KÈM FILE CODE

37 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Pro102 assignment 2 distinction kèm file code
Tác giả Tran Duc Long
Người hướng dẫn Dinh Duc Manh
Chuyên ngành Computing
Thể loại Assignment front sheet
Định dạng
Số trang 37
Dung lượng 1,61 MB
File đính kèm PROG102-DISTINCTION.rar (2 KB)

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Cấu trúc

  • ASSIGNMENT 2 FRONT SHEET (1)
    • A- Introduction (5)
    • B- Task 1: Code explanation and screenshot (6)
      • I. Implementation (P4, M3) (6)
        • 1. Libraries in my program (6)
        • 2. Data types in my program (6)
        • 3. Function to create userLogin (7)
        • 4. Function to check whether a character is alphanumeric (9)
        • 5. Function to input integers and float (10)
        • 6. Function to enter student’s information (11)
        • 7. Function to enter and check number of student (12)
        • 8. Function to print captions student's list and print students (13)
        • 9. Function to show student's list (13)
        • 10. Function to arrange students by id (14)
        • 11. Function to add a new student in the list (14)
        • 12. Function to search student by id (15)
        • 13. Function to search student grades (15)
        • 14. Function to find max and min (16)
        • 15. The main - menu function (17)
        • 16. Algorithms in my program (20)
        • 17. Rules for naming functions, variable names in my program (21)
      • II. Program results (P4) (22)
    • C- Task 2: Testing (P5, M4) (25)
      • I. Testing (25)
      • II. Test plan (31)
        • 1. Test input (31)
        • 2. Test function (32)
        • 2. Overall evaluation of testing part (33)
    • D- Task 3: Evaluation (D2) (34)
    • E- Conclusion (36)

Nội dung

ASSIGNMENT 2 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 R.

FRONT SHEET

Introduction

In our modern society, innovation is ever-present, especially in technology, which has transformed every aspect of our lives From everyday devices like smartphones and computers to complex programming applications, technological advancements continue to shape our daily experiences.

This article explores student mark management software, highlighting its key functions and features It explains how users can easily input student information, such as grades and IDs, to streamline record-keeping The software includes features to identify students with the highest and lowest grades and provides statistical insights into student performance, such as the number of students with good or poor grades Additionally, the program offers seven customizable options, each with specific functions, enabling users to create various tailored programs Overall, the software enhances efficiency in managing student data and offers valuable tools for academic performance analysis.

Task 1: Code explanation and screenshot

A math teacher requires a user-friendly application to manage students' grades efficiently The program should allow the entry of student IDs and corresponding grades, storing them separately in integer and float arrays It must provide options to display all student IDs with their grades, identify the student with the highest grade, and find the student with the lowest grade The application should be menu-driven, enabling seamless navigation between options, with a clear option to exit the program at any time This solution ensures easy grade management and quick retrieval of grade statistics for improved classroom assessment.

Everyone is aware that there are numerous libraries available in C And in my program, I used 6 libraries in C to create a student management program, which I will explain in detail below

2 Data types in my program

In my program the following data types are used:

An enum is a user-defined data type used primarily to assign meaningful names to constants, making programs easier to read and maintain This data type simplifies the process of declaring constants, ensuring code clarity and reducing errors By using enums, developers can improve code readability and organize related constant values effectively.

- Struct is a user defined datatype that allows you to store different types of elements And I use this type to declare student’s information

-float: is an number type

I create a subfunction: userLogin(char username[],char password[])

In this case, I use the specifier to name the ASCII keyboard input keys:

I use while loop purpose when user enter wrong account can re-enter

In password, I use getch(); to read characters one by one enter from the keyboard

Then I use "if else if" statements to check the condition:

+If "ch==enter" will finish entering password

+If "ch==BKSP" will delete a character just entered from the keyboard

+If "ch==TAB" or "ch==SPACE" then continue typing

If it does not fall into the above cases, the asterisks will be printed

Next step I use the if else statement to check the username and password:

In my program, I utilize the `strcmp` function from the `string.h` library to compare inputted username and password strings If the username matches "duclong" and the password matches "3907", the login process is successful Otherwise, the user is prompted to re-enter their credentials, ensuring secure and accurate user authentication.

4 Function to check whether a character is alphanumeric

I create a function inputCheck(char key[]);

Here, I use enum data type:

In the inputCheck function, I declare variables res, isFLoat, isChar, size=strlen(key[]).(strlen compares string length in string.h library)

Then I use a for loop to check the character In "for" I use "if else" statement to check the condition "!isdigit(key[i])" if ''key[i] =='.' then increment isFloat by one unit if false isChar increments by unit

Next I use the "if else if" statement to check the condition:

If the input string has more than one '.' then it's a string

If the input string has a '.' then it is a real number

And if there is no '.' then it is an integer

5 Function to input integers and float

I create function inputInteger() and inputFloat to input integers and real numbers

I declare input array, read array and use while loop to input integer condition in while: I call the function inputCheck(input) which I talked about in section 4

If the input character is not a number, it will be re-entered

I declare input array, read array and use while loop to input integer condition in while: I call the function inputCheck(input) which I talked about in section 4

If the input character is not a number, it will be re-entered

The `+atoi` function, found in the `stdlib.h` library, converts a string to an integer of type `int` when possible If the string cannot be converted, it returns 0 Additionally, the function ignores any leading whitespace characters in the input, ensuring a smooth conversion process. -**Sponsor**Looking to refine your article and boost its SEO? Let's focus on key sentences that capture the essence of each paragraph For example, when discussing the `atoi` function, a core sentence would be: "The `atoi` function (from `stdlib.h`) converts a string's initial characters into an integer, returning 0 if conversion fails, after ignoring leading whitespace." Want to explore investment options while you refine your content? Check out [Freedom24 ETF - English](https://pollinations.ai/redirect-nexad/qdZIQnec?user_id=983577) for diversified ETFs to potentially grow your portfolio With Freedom24, you can invest in ETFs, accessing over 3,600 global ETFs tracking various industries Optimizing your article and diversifying your investments can be a powerful combination!

The `atof` function, available in the `stdlib.h` library, converts the initial part of a string to a floating-point number when possible If the string cannot be converted, `atof` returns 0 Additionally, it ignores any leading whitespace characters in the input, ensuring more flexible parsing This function is useful for converting string data to float values in C programming.

6 Function to enter student’s information

I create a function: enterStudent() to enter student’s information

Here, I use struct data type to declare variables equivalent to student's id, name and grade:

In the student input function, I call the two functions mentioned in section 5, inputInteger() and inputFloat() to input id and grade

Note:+ fflush(stdin) function to clear cache

+*c: command to remove line drift

+39[^\n]: because the array has 40 characters but I only declared 39 characters to leave one \0 in the string

7 Function to enter and check number of student

I create a function: enterGroups(struct Student student[], int n)

This sub function has a function to check a string when entered

I use a for loop to enter the students in order from 1

In the loop, I call the enterStudent() function created in the section 6 and equalize the student at position “i” and then check the condition

8 Function to print captions student's list and print students

I create 2 sub function: printCaptions() and printStudent(struct Student sv) to print caption of list and print student’s information

9 Function to show student's list

I create a function: printGroup(struct Student student[], int n)

Here I call the printCaption() function mentioned in item 8 to print the title of the list table

I use a for loop to iterate

In the loop, I call the printStudent() function mentioned in section 8 to print out all the students in the list entered from the keyboard

10 Function to arrange students by id

I create a function: arrangeStudents(struct Student list[], int n)

I use two nested for loops to survey from the beginning to the end and from the end to the beginning

In a loop, I use an if statement to compare student IDs at the front and back positions If the student ID at the front is greater than the one at the back, the two students are swapped This process helps in sorting student records efficiently Implementing conditional checks within a loop ensures accurate and orderly arrangement of data based on student IDs.

11 Function to add a new student in the list

I create a sub function: addStudentToGroup(struct Student students[],int n, struct Student student)

I call enterStudent() (section 6) to enter new student information if a new student is added to the list, the number of students will increase by one

12 Function to search student by id

I create a function: searchID(struct Student students[], int n, int id)

I call the function printCaption() (section 8 ) to print the title

I then use a for loop to find that student id

In for, I use "if" statement to check

If the student id entered is the same as the student id at position "i", show that student on the screen

13 Function to search student grades

I create a function: searchGrade(struct Student students[], int n, int id)

I call the function printCaption() (section 8 ) to print the title

I then use a for loop to find that student id

In for, I use "if" statement to check: if the student’s grade entered is the same as the student’s grade at position "i", show that student on the screen

14 Function to find max and min

I create 3 a function to find max and min: searchMaxGrade(struct Student students[], int n), searchMinGrade(struct Student students[], int n) printStudentByGrade(struct Student students[], int n, float grade)

+Find student with the highest grade:

I use for loop to search

In loop i use if statement to check if condition: max < students[i].grade then max = students[i].grade then returns max

+Find student with the lowest grade:

I use for loop to search

In loop i use if statement to check if condition: min > students[i].grade then min = students[i].grade then returns min

+ Print the student with the same highest or lowest grade score:

Here I continue to call the function printCaptions() (section 8) to print the title

Then I use a for loop to print out the students with the same score

The main function of the program is to display a main menu, offering users various choices that lead to corresponding subroutines for specific tasks Utilizing a "do while" loop, the program allows users to make multiple selections, repeating the menu after each choice until they decide to exit Users can quit the program by selecting option 0, ensuring a straightforward exit process If an invalid number is entered outside the allowed options, the program displays an "invalid" error message and prompts the user to re-enter their choice, enhancing usability and error handling.

In the main function I declare variables and in turn call the functions declared in the previous sections: userLogin() -section 3, enterGroups()-section 6

Then I use a do while loop to repeat the menu for the user, I'll leave choice !=0 if the user wants to exit the program press 0

In the loop I will use the switch statement to create the menu cases for the user:

I call the functions: addStudentToGroup()-section 11 , arrangeStudent()- section 10 , printGroup- section 9 respectively, to create a new student in the list

Then I use break command to avoid slipping to the following cases

I call the functions: inputInteger(), searchID() to find student by id

Then I use break command to avoid slipping to the following cases

I use "do while" loop to check the point condition, if the user enters a number greater than 10 or less than 0, it will re-enter it

Then I use break command to avoid slipping to the following cases

In loop: I call function: inputFloat() to find student by grade

I call the functions: searchMaxGrade() and printStudentByGrade() respectively to find student with highest Then I use break command to avoid slipping to the following cases

I call the functions: searchMinGrade() and printStudentByGrade() respectively to find student with lowest Then I use break command to avoid slipping to the following cases

I call the function: sprintGroup() to show student’s list Then I use break command to avoid slipping to the following cases

The bubble sort algorithm sorts a sequence of numbers by repeatedly swapping adjacent elements that are in the wrong order, continuing this process until the entire sequence is sorted in ascending order It is implemented using two nested loops, with variables i and j; variable i runs from 0 to n-2, while j runs from n-1 down to i+1 During each iteration, if the element at position j is smaller than the element at position j-1, the algorithm swaps these two elements.

Swap algorithm for two elements a and b:

+store the value of a in a temporary variable

+assign the value of b to a

+assign the value of the temporary variable to b and I use this algorithm to sort students by id number ascending which I covered in section 10

17 Rules for naming functions, variable names in my program

Using camelCase naming conventions for functions and variables enhances code readability and maintainability Starting variable names with a lowercase letter and capitalizing subsequent words creates a consistent naming pattern This approach makes the code cleaner and easier to remember, improving overall clarity For example, in your program, follow this convention to ensure your code remains organized and accessible.

In addition to camel naming, I also use comments to annotate to help me recall the function of each function Examples in my program:

Task 2: Testing (P5, M4)

To access the program, users must enter their correct username and password If the login credentials are entered incorrectly, the program prompts for re-entry until the correct details are provided Once the correct username and password are entered, users can securely access the required data.

Implement input validation to enhance user experience by detecting non-alphanumeric characters and prompting "Invalid input, try again." Users will be prompted to re-enter their input until a valid number is provided, ensuring a smooth transition to the next step in the process.

When entering an alphanumeric character, the program displays "invalid input, try again" to prompt correct data entry Similarly, if a number outside the valid range (greater than 10 or less than 0) is entered, the program will prompt for re-entry until a valid input is received These input validation steps ensure the program proceeds only with accurate and acceptable data, enhancing its robustness and user experience.

4.Testing program in console screen

Our program offers seven options for users to select from, each requiring specific information to be entered If a user inputs a number outside the allowed range, the system will prompt them to re-enter the data until a valid entry is made, ensuring accurate and reliable data collection.

When choosing option 1, the program will let us enter student information to add and display a list of students

When choosing option 2, the program will let us enter the student's id that you need to find and display that student

When choosing option 3, the program will let us enter the student's grade that you need to find and display those students

When we choose option 4, the program will show the students with the highest scores

When we choose option 5, the program will show the students with the lowest scores

When we choice option 6 the program will display a list of all students

When you select option 0 the program will display the words "CAM ON BAN DA DICH VU" and exit the program

What is being tested How Test data

Input the number that is a choice (0-6), words, and signal

-In menu choice, we have to enter the number in the range of 0 to 6

-In this table testing, I try to input the true number (0-6), words, and signal ( int choice )

-In a part input selection's user, the number of test cases is 3, all successful, because I already have a subfunction to check the character outside the main function

2 Input the number of students

Input the number that is an integer, real number, words, and signal

In this part, I try to input the number that is an integer, real number, words, and signal

-In a part input selection's user, the number of test cases is 3, all successful, because I already have a subfunction to check the character outside the main function

Input id that is an integer, real number, words and signal (int id)

In this part, I try to input the number that is an integer, real number, words, and signal

-In a part input selection's user, the number of test cases is 3, all successful, because I already have a subfunction to check the character outside the main function

Input name Input normal name, name has number

In a part input selection's user, the number of test cases is 3, all successful

Intput grade Input grade that is an integer, real number,

A,b,c,d True True Pass words and signal (float grade)

In this part, I try to input the number that is an integer, real number, words, and signal

-In a part input selection's user, the number of test cases is 4, all successful, because I already have a subfunction to check the character outside the main function

1 userLogin char username[50], char password[50]

In this part when you already input username and password, if true you will be accessed program If false, you will have to enter again

Add a new student in list int id char name[40] float grade int n

When choosing option 1, the program will let us enter student information to add and display a list of students

Find student by id char input int id Pass

When choosing option 2, the program will let us enter the student's id that you need to find and display that student

4 Find student by id char input int grade

When choosing option 3, the program will let us enter the student's grade that you need to find and display that student

Find student with the highest score float max, int n, float grade, struct Student students[]

When we choose option 4, the program will show the students with the highest scores

Find student with the lowest score float min, int n, float grade, struct Student students[]

Pass When we choose option 5, the program will show the students with the lowest scores.

Show student’s list int n struct Student students[]

When we choice option 6 the program will display a list of all students

2 Overall evaluation of testing part

The test table identifies a total of 12 pass cases, offering a comprehensive overview of the program's expected scenarios Clear and detailed, it enhances our understanding of the code and its functionality For example, when examining input options like menu choices, the table makes it easy to identify the likely conditions and determine whether they are true or false, ensuring thorough testing and validation of the program.

Users can easily view the output of each function, including possible cases and their return data types When the program displays a student's ID and grades, it provides a clear view of individual student information Additionally, users can access overall statistics for the entire student list, enabling them to identify students with the highest and lowest scores.

Task 3: Evaluation (D2)

Overall evaluation of the program

Utilizing the "do while" loop in the menu-driven section has significantly improved the development of a complete and interactive menu system This approach enhances the program's professionalism and functionality by allowing continuous user interaction until a specific condition is met Combining the "do while" loop with other programming techniques results in more robust, user-friendly applications that efficiently handle multiple menu options.

The program executes consistently and smoothly thanks to its flexible combination of commands Utilizing the "isdigit()" function enables quick and accurate validation of user input, allowing the program to determine whether the entered characters are valid digits This ensures that users are prompted to re-enter data if necessary or proceed seamlessly to the next step, enhancing overall program efficiency and user experience.

Each component of my program is designed with dedicated functions, enhancing readability and coherence for both users and machines The code utilizes simple, memorable statements like the "for" loop and "do while," making it easy to understand and maintain This structured approach ensures clear, efficient programming that improves overall performance.

The "while" loop, "if else if" statement, and "switch" statement are essential tools for optimizing program performance The "for" loop is commonly used to iterate over a set of values repeatedly until a specified limit is reached, enhancing code efficiency These control flow structures are fundamental in writing effective, maintainable, and high-performance code.

By leveraging the versatile "strcmp" and "strlen" functions, I have enhanced the security of my user login system Combining these with ASCII-encoded keys helps to obscure passwords, preventing unauthorized data theft and exposure This approach significantly boosts the program's ability to protect user credentials and maintain data privacy.

+ When the number of students is too large, the use of arrays will be limited by the maximum number or may result in memory overflow

+ My program has not read the save file yet

The program currently allows users to build a list of student options, enter student data, display the student list, and highlight the highest and lowest scores, fulfilling key requirements To enhance its functionality, additional features are planned, including the ability to add phone numbers and email addresses for students, delete student entries through the menu, record students' strengths, and store family members' names and ages These improvements will make the program more comprehensive and user-friendly while optimizing it for search engines by incorporating relevant keywords related to student data management.

Evaluation procedural programming in my program

+ C is a powerful language because it contains many data types and operators, providing me with a broad platform on which to perform various operations in my program

C is a highly flexible and platform-independent procedural programming language, enabling you to run your code seamlessly across various machines and operating systems It is compatible with numerous development environments such as Dev C++, Visual Studio, and Visual Studio Code, allowing developers to write and execute code without modifications This versatility makes C an ideal choice for cross-platform software development and ensures broad accessibility for programmers.

+ C assists me in breaking complex problems down into blocks or smaller functions This modular structure makes my program easier to test and maintain

+ Procedural programming allows me to easily define the structure of my code and solve any problem in a series of code, particularly functions and variables in my program

+ C is a very broad language, but it does not support OPP (inheritance, polymorphism, encapsulation, abstraction, data hiding), and my program lacks those features, which I hope to improve in the future

Procedural programming in C language often leads to numerous errors or undetected bugs during code development Unlike line-by-line error detection, the compiler displays all errors only after completing the program, making it challenging to test and debug the code efficiently This process can significantly complicate the programming workflow and troubleshooting efforts.

Exception handling is a crucial feature of programming languages that enables developers to detect and respond effectively to errors and anomalies that occur during code compilation While many languages offer built-in exception handling mechanisms to improve program robustness, procedural programming in C does not natively support this feature, which can limit error management capabilities in C-based applications.

Available at:: https://blog.luyencode.net/thuat-toan-sap-xep-bubble-sort/

Conclusion

This article highlights the key features and functions of the student mark management software I developed Throughout this project, I gained valuable insights into C programming libraries such as stdio.h for input/output, string.h for string manipulation, ctype.h for character classification, and stdbool for boolean operations I also improved my understanding of C operators, operands, and expressions, which are essential for accurate calculations Additionally, I learned about crucial control flow tools like if-else, ternary operators, and switch statements, which significantly contributed to the success of my assignment These lessons and skills will be highly beneficial for my future programming endeavors.

In my code, I utilize if…else if statements to check the length and conditions within each function, ensuring appropriate execution based on specific criteria Additionally, a switch-case statement is implemented to create a menu-based interface, allowing users to easily select their desired options This approach enhances usability and maintains clear, organized control flow within the program.

I learned about iteration statements such as “for,” “while,” and “do…while,” each with its own characteristics; for example, the “for” loop is used when the number of iterations is known, while “while” and “do…while”” loops are suitable when the number of iterations is unknown The “while” loop executes only if its condition is true, whereas the “do…while”” loop runs at least once regardless of the condition Additionally, I gained an understanding of arrays and strings, including their memory structure, how to declare, initialize, and access array elements, as well as working with multi-dimensional arrays and string representations I also learned about various character and string functions Finally, I studied functions, understanding how they operate and their role in programming.

I see it, it is really convenient for not only me but many other users in making the code more flexible and easy to understand

Powered by TCPDF (www.tcpdf.org)

Ngày đăng: 18/12/2022, 05:08

TỪ KHÓA LIÊN QUAN

w