Download Programming with List Data Types: Int, String, and Structures in C# - Prof. Trương and more Assignments Computer Vision in PDF only on Docsity!
ASSIGNMENT 1 FRONT SHEET
Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 1: Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyen Huu Tien Thuan Student ID GCH Class GCH0907 Assessor name Do Tien 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 M1 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date: Lecturer Signature:
- I. Introduce
- Problem
- Solution
- C#
- Algorithm
- II. Software development life cycle
- Definition and how it works
- Waterfall model
- 2.1. Pros and cons................................................................................................................................
- Spiral model
- 3.1 Pros and cons................................................................................................................................
- III. Analysis and design
- Function
- List data types
- Conditional statement
- Loop statements
- Flowchart
- 5.1. Main
- 5.2. Enter food
- 5.3. Display food list
- 5.4. Calculate price
- 5.5. Sort price
- IV. Implementation
- Structure
- Main function
- EnterFood function
- calculatePrice function
- sortPrice function
- DisplayFood function
- Result
- V. Test case
- VI. Conclusion
- References
I. Introduce
I applied for an internship position at a software development company and was invited for an interview. I was asked to demonstrate my basic programming problem- solving skills. I need to prepare a report on the use of problem-solving algorithms. I will explain problems using examples, algorithms used to solve simple business problems, and necessary steps to follow to create a working program solution. The problem to be solved will involve basic procedural programming instructions - sequence instructions (input, output, and assignment statements), loops, conditional statements. Problems should be analyzed and designed using flowcharts and demonstrated using modules (procedures).
1. Problem A restaurant owner wants to manage the store's sales. He wanted me to write a small application to manage. He needs to enter dish information, quantity sold, total revenue etc… When an option is made, the program will return to the main menu where another option can be selected. There will be an option to exit the program. 2. Solution To solve this problem, I use C# programming language to write a small program that helps the restaurant owner to manage the sales of his shop with functions such as: - Enter food information - Display food list - Calculate total price after selling - Sort amount - Exit 3. C# C# is a programming language developed by Microsoft and designed specifically for the .NET Framework. This allows developers to take full advantage of the features of the .NET API. But C# applications can only run-on platforms that support the .NET runtime, such as Windows, Windows Server... For programs written in C# to run on other platforms, the code must be compiled with a conversion tool like Microsoft .NET Native. (Christensson, 2014) C# is also another version of C++ and is similar to C++. Using the same basic operators, the object-oriented and syntax are almost the same. Some things are different between C# and C++ like: - Arrays in C++ are pointers, while in C#, they are objects that may include methods and properties. - The keywords typedef, extern, and static all have different meanings in C# than they do in C++. … 4. Algorithm In basic terms, an algorithm is a well-defined set of steps or rules that you need to follow to get a predetermined result. Algorithm flowchart would have three major components: - Input: What we already know or the things we have to begin with. - Algorithm: A set of sequenced steps that we need to follow one by one. - Output: The expected results we need to achieve in the end.
find out the strengths and weaknesses of the system and improvement is the goal.
- Planning: planning for the quality assurance requirements and identification of the risks associated with the project is also done in the planning stage. The outcome of the technical feasibility study is to define the various technical approaches that can be followed to implement the project successfully with minimum risks.
- Design: approach clearly defines all the architectural modules of the product along with its communication and data flow representation with the external and third-party modules (if any). The internal design of all the modules of the proposed architecture should be clearly defined with the minutest of the details in Design Document Specification.
- Software development: In this stage of SDLC the actual development starts, and the product is built. The programming code is generated as per DDS during this stage. If the design is performed in a detailed and organized manner, code generation can be accomplished without much hassle. Developers must follow the coding guidelines defined by their organization and programming tools like compilers, interpreters, debuggers, etc. are used to generate the code. Different high level programming languages such as C, C++, Pascal, Java and PHP are used for coding. The programming language is chosen with respect to the type of software being developed.
- Testing: This stage is usually a subset of all the stages as in the modern SDLC models, the testing activities are mostly involved in all the stages of SDLC. However, this stage refers to the testing only stage of the product where product defects are reported, tracked, fixed and retested, until the product reaches the quality standards defined in the SRS.
- Deployment: Once the product is tested and ready to be deployed it is released formally in the appropriate market. Sometimes product deployment happens in stages as per the business strategy of that organization. The product may first be released in a limited segment and tested in the real business environment (UAT- User acceptance testing). Then based on the feedback, the product may be released as it is or with suggested enhancements in the targeting market segment. After the product is released in the market, its maintenance is done for the existing customer base. 2. Waterfall model
- The waterfall model is a linear, sequential approach to the software development life cycle (SDLC), common in software engineering and product development. The waterfall model will fulfill each goal set for each stage of development and cannot be turned back once completed. (Lewis, 2019)
- Stage of the waterfall model
- Requirement: This phase involves identifying and planning to address project issues but does not address specific processes
- Analysis: The system specifications are analyzed to generate product models and business logic that will guide production. This is also when financial and technical resources are audited for feasibility.
- Design: Design a specific document that outlines technical requirements such as programming languages, hardware, data, and services.
- Code: From the requirements and design defined in the previous stages then we can develop the source code.
- Testing: This is when quality assurance, unit, system and beta tests take place to report issues that may need to be resolved. This may cause a forced repeat of the coding stage for debugging. If the system passes the tests, the waterfall continues forward.
- Deployment: The product or application is deemed fully functional and is deployed to a live environment.
- Maintenance: Corrective, adaptive and perfective maintenance is carried out indefinitely to improve, update and enhance the final product. 2.1.Pros and cons
- Pros:
- Resolve risks: All the possible solutions are evaluated to select the best possible solution. Then the risks associated with that solution are identified and the risks are resolved using the best possible strategy.
- Develop next version of the product: The identified features are developed and verified through testing.
- Review and plan for the next phase: The Customers evaluate the so far developed version of the software. In the end, planning for the next phase is started.
3.1 Pros and cons
- Pros:
- Risk Handling: The projects with many unknown risks
that occur as the development proceeds, in that case,
Spiral Model is the best development model to follow
due to the risk analysis and risk handling at every phase.
- Good for large projects: It is recommended to use the
Spiral Model in large and complex projects.
- Flexibility in Requirements: Change requests in the
Requirements at later phase can be incorporated
accurately by using this model.
- Customer Satisfaction: Customer can see the
development of the product at the early phase of the
software development and thus, they habituated with the
system by using it before completion of the total product.
- Cons:
- Complex: The Spiral Model is much more complex than
other SDLC models.
- Expensive: Spiral Model is not suitable for small projects
as it is expensive.
- Too much dependability on Risk Analysis: The
successful completion of the project is very much
dependent on Risk Analysis. Without very highly
experienced experts, it is going to be a failure to develop
a project using this model.
- Difficulty in time management: As the number of phases
is unknown at the start of the project, so time estimation
is very difficult.
III. Analysis and design
1. Function
In C#, a function is a way of encapsulating code that does something and then returns a value. Unlike in C, C++ and some other languages, functions do not exist on their own. They are part of an object-oriented approach to programming. (Bolton, 2019) In the program i use void function, the function does not return a value. and when we need to act, we just need to call the function in main again to be able to execute the statements in the void function
2. List data types - int: int is a keyword that is used to declare a variable which can store an integral type of value (signed integer) the range from - 2,147,483,648 to 2,147,483,647. In the program I use data type int to declare for price, amout, foodCode, total. because the input values of the above variables will be integer types. Example: price = 8; foodCode = 13 and 8 or 13 are both integers - string: is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. (Kumar, 2020) Because when entering the values of variables, for example name is thuan, user is Administrator... then values like "thuan", "Administrator" will include strings of characters like 'a', 'm', 'n'... so I use string data type in the program. 3. Conditional statement - A statement that can be executed based on a condition is known as a “Conditional Statement”. The statement is often a block of code. This
I use the for loop in the program to be able to enter basic information for many types of food
- While loop: It repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body. in the program i use while loop to create an infinite loop by making the condition of while true. because when selecting options in the program it can go back and select more options until the command exits the program.
- Do…while loop: will execute the statement in the body of the loop and will check the condition at the end of the loop.
I use do...while to create a loop for login. and if i enter wrong credentials i can still enter again provided the while is still true.
5. Flowchart 5.1. Main - Step 1: Enter number food - Step 2: Use switch case to choose the option to manage the program - Step 3: if option 1 = true, then enter information of food and back to main menu to choose more option, if option 1 false, next to step 4. - Step 4: if option 2 = true, then display information of food, and back to main menu to choose more option, if option 2 false, next to step 5.
- Step 1: Print “Food code” “Food name” “Price” “Amount”
- Step 2: Initialize variable i = 0 with data type int.
- Step 3: Compare i with bss.Length, if i < bss.Length, then print food information, if false stop program.
- Step 4: After display the first food information, the value of i will be increased by 1 unit and go back to step 2 to check the condition and display the next food information. 5.4. Calculate price
- Step 1: Initialize variable i = 0 with data type int.
- Step 2: Compare i with bss.Length. if i < bss.Length, calculate the total price of food and print “ Total price of bss[i].name is bss[i].total. if it false, stop program.
- Step 3: After print total price, value of i will be increased by 1 unit and go back to check condition and print total price of next food. 5.5. Sort price
- Step 1: initialize variable i = 0; j = i + 1 with data type int and a variable temp as a temporary variable with data type Business.
- Step 2: compare i with bss.Length. if true, go to step 3. False then stop program.
- Step 3:in next loop compare j with bss.Length. if j < bss.Length, we continue compare bss[i].amount > bss[j].amount. if it false will go back to step 2
- Step 4: if bss[i].amount > bss[j].amount true, then the position swap will be performed temp = bss[i]; bss[i] = bss[j]; bss[j] = temp. if it false, then back to step 3.
IV. Implementation
1. Structure A structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined
- Because the program menu has a lot of options, I use the switch case command to be able to enter the options cause in main menu: - Case 1: Print “ Enter food information” and I re-call EnterFood function in case 1 with bss as input data. And break command to stop this case and go back to menu and choose next option. - Case 2: Print “Food list” and I re-call DisplayFood function in case 2 with bss as input data. And break command to stop this case and go back to menu and choose next option.
- Case 3: Print “Total amount after selling” and I re-call calculatePrice function in case 2 with bss as input data. And break command to stop this case and go back to menu and choose next option.
- Case 4: Print “Food list after sorting” and I re-call sortPrice function, DisplayFood function with bss as input data. And break command to stop this case and go back to menu and choose next option.
- Case 0: Print “Have a nice day” and Environment.Exit(0) command to exit program.
- Default: Print “ Error! Pleases re-enter your option.”. And break command to stop this case and go back to menu and choose next option. 3. EnterFood function initialize i = 0 variable with data type int and enter the information of the food. and initialize more variables l = i + 1 so that the element in the array starts from 1 to avoid program errors. and after entering the food information, it will return to increase the variable i and continue to compare with the word length until i > bss.Length will stop the loop.