Unit 18 Procedural programming Assignment Sample

 Unit 18 Procedural programming Assignment Sample

Unit 18 Procedural programming Assignment Sample

TASK 1: Understand the principles of Procedural Programming

1.1 (a) Write maximum 400 words explaining briefly what procedural programming is and define clearly what do we mean by methods, variables and loops with an example for each?

Procedural Programming:

Procedures correspond to functions. Both allow the reuse of the same code in various parts of the programs, and at various points of its execution.
Beginning Visual

By the same token, procedure calls correspond to function application.
Functions and their invocations are modularly separated from each other in the same manner, by the use of function arguments, return values and variable scopes.
Decomposing of a big task into smaller tasks holds the concept of procedural programming. Procedures are called and some inputs are given into it to be processed, then these procedures process the data and gives output according to the logic of the program. Valid data is given to the function as arguments then valid data is the output of the function if it does not holds then the particular function can be checked.
        Procedures corresponds to functions. Both allow the reuse of the same code in various parts of the programs and at various points of its execution. By the same token procedure call corresponds to the same token. Functions and their invocations are modularly separated from each other in the same manner by the use of function arguments, return values and variable scopes. It is a better approach that a function process its own set of data and not the same shared data or variables declared as global. It is good practice to make another procedure to do another task. And then this process can be called wherever we want that function to be executed. This enhances various factors of good programming like code reusability, code readability, easy debugging, etc.

Function:
Beginning Visual C# 2010
Function is a subprogram which is used to enclose set of code which provides the ease of code reusability. Functions can be used in a place where calculations are to be performed or any logic is combined with the solution. It helps when you designs the logic once and uses it wherever you require. Functions can also take arguments and return values according to the logic but functions can only return one value whereas they can take as many as the require.

Ex:       int square(int no)

{

return no * no;

}

Here square() function receives a number as argument and returns square of it.

Variables:
Variables are the identifiers which hold memory in the primary storage and they store values at the time of program execution and these values varies at the time of program execution.
Variable names should be meaningful in a program according to convention.
Rules to declare a variable name:

  • It cannot contain spaces.
  • It must begin with an alphabet or underscore(_).
  • It cannot start with a digit but it can contain digits after any alphabet or underscore (_).
  • It cannot contain keywords of the language. Keywords are the reserved words used by the language to denote some important terms.

Ex:       int price = 12000;

Loops:
Looping refers
Repetitive statement or group of statements are called as loops. They always contain some condition which is when true iterates and when it is false it stops iterating and goes to the next statement after the loop. There are two type of loops:
Entry control loop: Condition is checked first and then execution starts.
If the condition gives a false then it does not execute even a single time.
Exit Control loop: Condition is checked at last and if the condition then gives a false result then it stops execution. But it execute once always whether the condition is true or not.

For Loop:
for(int i = 0; i  < 15; i++){

            ....

            ……

}

While loop:

int i = 10;

while(i != 0){

            …

            …

}

(b) Explain briefly the benefits of procedural programming in terms of code readability, usability, maintenance and error tracking.

Benefits of Procedural Programming:
There are many benefits of procedural programming these are the following:

  • It is easy to learn
  • It is easy to use.
  • It execute quickly.

It helps us to divide the large task into multiple simple tasks that performs specific task.
In modular programming every task is defined as separate and independent task so our application can be changed any without changing other modules.
Benefits offered by modular programming to the programmers:

Code Readability:
The term code readability is used to denote the grace of code’s readability which includes following facts:

  • Name of the methods and variables should have meaningful denoting its function.
  • Every task should have a separate function.
  • The code should be indented properly.

Code Usability:
            The main concept of code reusability is design once and use wherever and whenever required by just calling the function using its function name. It helps to save the programmers time where method designed once is not redesigned again and used several times wherever required.  

Maintenance:
Each task is divided into subtasks or separate functions and these subtasks are easy to maintain and trace. When any bug occurs then it can be easily traced and debug on that separate subtask only rather the manipulating the function of the whole task. This is very useful as it is easy in it tracing and debugging the bugs.

Debugging is Easy:
As stated above the function as a whole is divided into subprograms and these subprograms perform specific tasks. In these specific subtasks if anything goes irrespective to the program and program goes wrong then we can easily trace that which subprogram is going out of its bounds and after finding the task we can easily debug it without even touching the other code.

TASK 2: Design Procedural Programming Solutions

2.1 Explain briefly the benefits of pseudo code and flowcharts, then develop an Algorithm using pseudo code (‘Divide’ the Algorithm into simple action steps) to show how you design the key functions/methods created in your program.

Pseudo codes are simple texts representing logic of the program and it is easily understandable by the people does not belong to programming background. This is an efficient way to create basic logic used to solve the problem.
Following are the benefits of the Pseudo Code:

  • Simple
  • Easy to understand.
  • Non-Specific to any programming language.
  • Mostly English is used as a language for the pseudo codes.
  • Logic can be implemented in any language.
  • Defines a specific process of application.
  • Programmer can focus on logic instead of the syntax of particular programming language in which the logic is implemented.

Flow charts are diagrammatic representation of a pseudo codes. They are widely used in software development. Basically flow charts are used to represent any process in any business. So it is an easy approach for overview of the approach that can be used to solve the problem.
Benefits:

  • It represents a step by step flow of the program execution.
  • It shows each process as a diagram using arrows, blocks (diamond or ellipse or rectangle).
  • It is easily understandable and readable by any non-programmer or programmer category of people.
  • It contains all the step by step description of every level of the flow of the program.
  • It clearly states and explains the logic of the program in its each step.

Pseudo Code:

Get_Employees_From_File

Pseudo Code

Pseudo Code 2

Pseudo Code 3

Pseudo Code 4

Pseudo Code 12

Pseudo Code 6

Pseudo Code 16

Pseudo Code 14

Pseudo Code 123

Pseudo Code 164

Flow Chart
flowchart code

2.2 Develop a basic architecture of your system showing the different components.

I have defined two structures to make it easy to represent employee and invoice information.

flowchart aas

The data related to employee and invoice will be stored in plain text files as the assignment required and the each record will be in a single line, in which each value will be separated by semicolon.

The file name used to store information

store information

Employee information file will have the following structure

The information will be stored in file in one record per line, and the values will be in separated by semicolon, following will be the format
{employee_ID};{employee_password};{employee_name};{employee_job_title};{employee_rate}

Employee information

Invoice information file will have the following structure

The information will be stored in file in one record per line, and the values will be in separated by semicolon, following will be the format
{invoice_ID};{ invoice_month};{invoice_amount};{ invoice_is_accepted}

Invoice information

TASK 3: Implement Procedural Programming Solutions

3.1 You are required to implement the developed Algorithm for a given scenario and drawn Flowchart (in task 2) into a C# Program Code using MS Visual Studio Express 2010/2012.

I have developed Basic Accounting System using Microsoft Visual Studio 2012. I have implemented the overall functionality of the application separated modules, which makes the debugging easy and increases the reuse of code and increased the readability of the code.

Procedure used to present menu for employer user
Employer_Login ()  It is used to present menu if the employer logged in. It displays task that can be performed by Employer. The Employer can do the following task
Register New Employee: Employee can create a new employee.
Confirm the monthly payment: The Employer can confirm the monthly payment of an Employee.
List all employee id and name: The Employee can see the list of all Employees.

List all employee id

Procedure used to present menu for employer user
Employee_Login ()  It is used to present menu if any employee logged in. It displays task that can be performed by Employee. The Employee can do the following task
Check Payment: Employee can check for the confirmation of its invoices.
Invoice Employer: Employee can create new invoice to Employer that the Employee will have to confirm.

Employee_Login

Procedures that are used to retrieve and save data to text files
Get_Data (): It is used to get data from the files, it uses or calls other procedure to perform this task.
Put_Data (): It is used to put data into the files, it uses or calls other procedure to perform this task.

Get_Data

3.2 You are supposed to learn the programming in this unit like array, methods, output to text files as built-in I/O Standard Input Output Library and the Functions used to the program User to Input the selected Menu.

All the above specified programming skills are well learnt like arrays, file reading/writing, methods, getting user inputs and use I/O library.
Arrays are used to store similar type of data sequentially. This data can be accessed randomly by using its index. Index in array starts with 0 to n-1 where n is the number of objects array can store.
Methods or functions are used to divide the project into separate small parts which as a whole perform the task of the given project.
File I/O Input Output standard libraries are used to manipulate the data in the files. Here manipulating contains all the functions that can be performed on the file are performed using these libraries.

Detail and the approaches that are used to develop the application are described below:
It is a console based application in which inputs are been fed by using I/O methods of .net environment. The user should first login into the application to use it. Different-Different menus are given for different-different users to use this application.
       There are two classes which are used from System.IO to retrieve and save data to/from the text file in the comma separated format. These files are StreamWriter and StreamReader. To increase reusability and readability of code separate modules are divided for each function. This approach makes debugging easy.

Following procedures are implemented in the application:
Employer_Login() : It prints list of task to the Employee and read choice form the user and calls other procedures to perform the task.
Employee_Login() : It prints the list of the task if the Employee logged in, it read choice from the user and calls other procedures to perform the task.
User_Login() : It reads the user credentials, validate them and returns a Boolean value representing success or failure of the login operation.
Print_Menu() : It is used to display the main menu of the application, which is the start screen where the application user have to choose his/her role that whether he/she is an employee or employer.

TASK 4: Test Procedural Programming Solutions

4.1 Critically review and test your solution

Testing is a very crucial phase which is very important in the process of any software development. In testing many test cases are checked to be working correctly i.e. on some input the output of the program should be correct according to the user requirements. In this the assigned application and the developed application should have no difference. If this condition satisfies then the developed program is very well developed as well as tested.
Steps of testing:

  • User Input validation.
  • User Authentication and Authorization.
  • Saving information in formatted text files.
  • Testing of menu driven application flow.

I have checked the developed application and it is well tested and all validations are working perfect to get input by user.

4.2 ANALYZE actual test results against expected results to identify discrepancies
ANALYZE actual test

ANALYZE actual test  2

4.3 Evaluate independent feedback on your solution and make recommendations for improvements.

Evaluate independent

Conclusion

Post rectification of the above mentioned errors and some minor formatting issues, I did not find any errors in the application, and it is working well to fulfil the requirement specified to complete the assignment.

4.4 Create user documentation for the solution 

Below chart show the basic flow of the application, it can be used to know that how a user should use the application.

the basic flow of the application

Application Control Flow

Application Starts

Read user role (Employee/Employer)

Read and validate username and password to login

If Employer gets logged in

  • Register New Employee
  • Confirm the Monthly Payment
  • List All Employee Id and Name

If Employee gets logged in

  • Check Payment
  • Generate Invoice to Employer

Main Screen of the application
Main Screen of the application

Employer Menu Screen
Employer Menu Screen

Create new employee screen

Accept employee invoice screen
Accept employee invoice screen

List of employee screen
List of employee screen

Employee screen
Employee screen

Check invoice payment screen
Check invoice payment screen

Create invoice screen
Create invoice screen

4.5 Create technical documentation for the support and maintenance of your system

Following are the System Requirements For the application

  • Windows Operation System
  • .net framework should be installed

The application is designed and developed with all care to fulfil the requirement, proper modules are developed to perform a task in the application.
System.IO.StreamReader and System.IO.StreamWriter classes are used to read and store information in the files. All application data is store in plain text file, one record per line and the values are separated by semicolon (;)
It is a console based menu driven application so no GUI will be available to application users and the all input and output can be done through console.

References

  • Beginning Visual C# 2012 Programming Paperback by Karli Watson (Author), Jacob Vibe Hammer (Author), Jon D. Reid (Author), Morgan Skinner (Author), Daniel Kemper (Author), Christian Nagel (Author)
  • C# Essentials by Neil Smyth
  • The C# Yellow Book by Rob Miles
  • Beginning Visual C# 2010 (wrox)
  • Profession C#, 3rd Edition (wrox)
  • Greene, J. and Stellman, A., (2013). Head First C#, (2nd Edition). O'Reilly Media
  • Troelsen, A., (2007). Pro C# 2008 and the .NET 3.5 Platform. Apress publications
  • C# 4.0 The Complete Reference by Herbert Schildt
  • C# 2012 Programming, Covers .Net 4.5, Black Book by by Kogent Learning Solutions Inc.
  • Illustrated C# 2012 Paperback by Daniel Solis