Principles Of Procedural Programming Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Procedural programming is the most natural way of telling a computer what to do as the computer processors own language and machine code is procedural. It is also referred as structured or modular programming. Procedural programming is performed by telling the computer what to do and how to do it through a list of step-by-step instructions. Therefore, procedural programming involves procedures, which implies that there are steps that need to be followed to complete a specific task. For example read a number, add 7 or display a specific message. Procedural programming is quite straightforward and efficient as more than often to begin with, the program is written in a common and plain language by applying logic before actually writing the code.

The main features of procedural programming is that it is relatively easy to read and write program code and maintain program code as numerous procedures can be debugged separately. Furthermore, large programs are divided into smaller ones and that most of the data is shared and can therefore be reached from any other point within the program.

Conclusively, taking into account that the main characteristics of procedural programing being sequential logic, simplicity, easy implementation of compilers and interpreters, ability to make use of the same code in the program by calling it instead of copying, ease with which the program flow can be tracked, ability to be strongly modular or structured, it can definitely be said that procedural programming is an essential stepping stone towards learning further programming skills.

2. Implementing Procedural Programming Solutions.

An algorithm can be defined as a set of steps for performing a task that can be written down and implemented. An algorithm details how to start with known information specified in the problem and how to use that information to reach a solution. In this particular task, the following algorithm using pseudo code has been developed a program which will help a small High Street Curry House manage their business operations.

Algorithm using pseudo code

Show Login and Exit ( Press 1 to Login/ else exit)

Request monthly salary and other income

Calculate and Display Total Income

Request All Personal Expenses ( i.e. college fees/ rent/ food/travel/entertainment/phone bill/ gas bill/electricity bill/ TV license/ council tax/ club membership and charity contribution and any other expenses)

Calculate all expenses and display Total Expenses

Calculate and Display Balance (Total Income - Total Expenses)

If Balance is positive display credit amount and if negative display no more funds available.

Diagram 1| Flowchart illustrating Algorithm's Logical Flow & Functions.

START

IF 1

OR

IF 2

Salary + Other Income = Total Income & Display

Request Salary & Other income

Login

Request all Expenses

Calculate Total Expenses & Display

Total Income - Total Expenses = Balance

If Balance is +ve (Balance > 0)

If Balance is -ve

(Balance <0)

Display You are in Credit

EXIT

No More Funds Available

3| Implement Procedural Programming Solution

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Unit18_CW_ID10571

{

class Program

{

static void Main(string[] args)

{

double monthlySalary, otherIncome, totalIncome,balance;

/*************************************************************************************************************************************

About : This program answers Task 3 of the Coursework for Unit18_Procedural Programming,

BTEC HND in Computing and Systems Development (CSD). Icon College of Technology and Management.

Date : 10.04.2013

By : Ibrahim Khan Mahomudally . Student ID : 10571

Tutor : Y M Gebremichael

*************************************************************************************************************************************/

Console.WriteLine(" ****************************************************************************** \n");

Console.WriteLine(" ~~~~~~~~~~~~~~~~~ Profit & Loss Accounting 2013 ~~~~~~~~~~~~~~~~~~~~ ");

Console.WriteLine("\t\t\t\t [Menu]\n\n");

Console.WriteLine("\t\t\t\t 1. Login\n\n");

Console.WriteLine("\t\t\t\t 2. Exit\n\n");

Console.WriteLine("\t\t\t To Login Please Press 1\n\n");

Console.WriteLine("\t\t\t To Exit Please Press 2\n\n");

Console.WriteLine(" ****************************************************************************** ");

int Menu = int.Parse(Console.ReadLine());

if (Menu == 1)

{

// input income

//calculate total income and display

Console.WriteLine("************************* All income***************************************");

Console.WriteLine("Enter Monthly Salary: ");

monthlySalary = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Any Other Income");

otherIncome = double.Parse(Console.ReadLine());

totalIncome = monthlySalary + otherIncome;

Console.WriteLine("Total Income = " + monthlySalary + "+" + otherIncome + "=" + totalIncome);

/******************************************************************************/

//input expenses

//calculate total expenses and display

Console.WriteLine("************************* All Expenses***************************************");

double totalExpenses, rent, collegeFees, food, travel, entertainment, phonebill, gasbill, electricitybill,

tvlicense, counciltax, clubmembership, charitycontribution, anyotherexpenses;

Console.WriteLine("Enter College fees");

collegeFees = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Rent");

rent = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Food");

food = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Travel");

travel = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Entertainment");

entertainment = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Phone Bill");

phonebill = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Gas Bill");

gasbill = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Electricity Bill");

electricitybill = double.Parse(Console.ReadLine());

Console.WriteLine("Enter TV License");

tvlicense = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Council Tax");

counciltax = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Club Membership");

clubmembership = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Charity Contribution");

charitycontribution = double.Parse(Console.ReadLine());

Console.WriteLine("Enter Any Other Expenses");

anyotherexpenses = double.Parse(Console.ReadLine());

totalExpenses = collegeFees + rent + food + travel + entertainment + phonebill + gasbill +

electricitybill + tvlicense + counciltax + clubmembership + charitycontribution + anyotherexpenses;

Console.WriteLine("Total Expenses = " + totalExpenses);

Console.WriteLine("************************* Balance***************************************");

//work out balance and display relevant message

balance = totalIncome - totalExpenses;

Console.WriteLine("Balance = " + balance);

if (balance >= 0)

{

Console.WriteLine(" :) You Are In Credit by £ " + balance);

}

else

{

Console.WriteLine(":( No More Funds Available");

}

}

else if (Menu == 2)

{

Environment.Exit(1);

}

else

{

Console.WriteLine("Enter a number from the menu");

// this should return back to the menu again

}

Console.ReadLine()

}

}

}

4| Testing Procedural Programming Solutions.

Below are enclosed screenshots of the above-designed program demonstrating that every aspects of program is tested and compared against the design specification.

Screenshot 1| Menu Options.

Main menu presenting the user with the following options:

Press 1 to Login

Press 2 to Exit

Screenshot 2| Request for Income.

When 1 is pressed, User is requested to start entering figures for incomes

Screenshot 3| Total Income.

When all incomes are entered, Total Income is calculated and displayed.

Screenshot 4| Input Expenses.

User is requested to input figures for all expenses.

Screenshot 5| Total Expenses, Positive Balance and Message.

Total Expenses is calculated and displayed. Balance is obtained and if the result is positive, 'You Are In Credit' message displayed.

Screenshot 6| Negative Balance & Relevant Message.

Total Expenses is calculated and displayed. Balance is obtained and if result is negative,

'No More Funds Available' message displayed

4b| Difference between syntax error and semantic error

Syntax is the required grammar and punctuation of the language while semantics is all about meaning, that is, what the statements do, what the programs do. Applying the correct syntax is essential as if not done properly, the program won't run. The syntax of a language greatly affects how easy it is to write, read and understand programs. Syntax errors usually occur when program statements do not conform to the rule of the language. Therefore, Syntax errors occur during the parsing of input code, and are the result of grammatically incorrect statements. Some examples of syntax errors are misspelled keywords, unmatched quotation marks, missing semicolon, illegal character in the input, missing operator, two operators in a row, two statements on the same line with no intervening semicolon, unbalanced parentheses, misplaced reserved word etc.

Semantic errors occur when the form of the elements in a statement is correct but the elements are not valid for its use. Semantic errors are normally detected at compile time. Semantic errors occur during the execution of the code, after it has been parsed as grammatically correct. These errors have to do not with how statements are constructed, but with what they mean. Regular examples of sematic errors are such things as incorrect variable types or sizes, non-existent variables, subscripts out of range, specifying the wrong number of arguments for a function, using numeric variable name where only character variable is valid and non-existent references.