StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Programming Is C and Structured Programming - Assignment Example

Summary
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER94.9% of users find it useful

Extract of sample "Programming Is C and Structured Programming"

Programming is C and Structured programming: Name: Course: Tutor: Date: Question 1 DESCRIPTION OF STRUCTURED PROGRAMMING Structured programming is programming uses blocks in form of functions and procedures among other artefacts to form a block which links to the scopes of variables. The variable therefore declared inside the block will not be visible outside the block. Structured programming principle requires that codes within a function or a procedure must be organized in to blocks or instance looping and branching. Previously, before structured programming came in to being, spaghetti code was used whereby the control flow mechanism was: if and goto only; this made it very difficult to understand the codes. The structured programming concept came as a result of the problems incurred due to the use of Spaghetti Code, a code that has no simple direct logical structure. Branching is a concept used in structured programming, it gives a computer various options to choose on which to execute based on the values of a condition. Here the branch follows the principle of structured programming that each component in the code should have single entry point and a single exit point. An example of branching is the if statement where the program selectively select to run a code based on a condition. The condition else is therefore executed if the condition is false. They have sequentially executed statements, conditional execution of statements for instance the if statements, case statements and switch statements. This gives a computer a chance to test a condition and execute that which meets a given condition. For example if (result >= 45) printf("Pass\n"); else printf("Fail\n"); Another branching statement is the case statement. Here the developer is given an option to create a path that shall be executed whenever there is match with the value in the expression. The case statement therefore has one entry point, several paths and a single exit point. For example { switch(number) { case 0 : printf("Nothing\n"); break; case 1 : printf("once\n"); break; case 2 : printf("Twice\n"); break; case 3 : case 4 : case 5 : printf("frequent\n"); There is also the aspect of looping of instructions to enable the program repeats a given instruction. Structured programming uses looping to control the sequence of actions in the program. In a loop a given action is executed repeatedly. The pretest loop and post test loops are therefore actions in programming. Example of post test loop include do….while loop. For instance the for loop can be used as follows float avg(float array[], int count) { float sum = 0.0; int x; for(x = 0; x < count; x++) total += array[x]; return(sum / count); } All developers must learn to place comments in their program code. These comments are not translated to machine language but rather skipped by the computer when reading lines of code. The main purpose of using comments is to ensure the other developers understand the written code especially for further development. Question 2 Descriptions of the artefacts, actions, and terms covered. ARTEFACTS When designing a program one needs to understand the problem and get the facts of what need to be performed, then identify the artefacts that he/she is going to use, this leads to mapping the artefacts to the code and finally compile and run the program. For the purpose of design, the developer can use neutral language pseudocode. This is not actually the code but an elaborate structured depiction on how the program is expected to work. In programming, artefacts are created and used in the program codes. Examples of artefacts in C programming include program, procedure, functions, library and type. Program A program is a set of instructions that tells a computer what to do, the computer understand machine language and therefore need assemblers and compilers to be able to execute source codes. The programmers cannot write lines of codes using machine language because they are not human friendly. In all the programming languages, hello world program is very crucial to any developer because is ensures that all the tools in the terminal are well set for programming. We can therefore say that computers need programs in order to do what we want them to do; it is the intelligence of the developer that will make the computer execute the right instructions. Procedure The part of a program that performs specific task is called a procedure. This procedure can be called within a program to perform its function. Procedures are called and identified by procedure calls. These procedures are sometimes referred to as subroutines or methods. Library Every programming language has a library which contains several reusable codes that can be called to perform specific instructions. Example in C programming #include located in the C libraries Type There ate data types that assist the computer understand how the data stored in the computer memory is interpreted by the program. The data types include integers, floating points and strings. Every variable is therefore declared by first indicating which type it is for instance Int number; This declaration indicates that number is a variable whose data type is integer. TERMS Terms in programming include statements, expressions and identifiers. Statement A statement is an instruction in a code. The statement instructs a computer on what to do. It is therefore an instruction in a code. Each program has a set of statements that instructs the computer on a action to be performed. Assignment statement is used to calculate a value and store it in a variable Expressions These are values used in a program statement. The values can either be calculated or entered directly in to the program. The expressions will therefore provide a value to be used by a statement in the program. Identifiers Identifiers give names to the given artefact for instance the program names must be identified based on what it is doing. The name is an identifier. Identifiers therefore help the compiler to know each artefact in the program. Each artefact must be named for identification. Procedure call identifies a procedure to call for execution. This is only possible if the procedure is identified. ACTIONS Actions are the things a developer can command a computer to do. Examples of actions include procedure calls, function calls, assignment statements, return statements and exit statement. A procedure call is a statement that tells a computer to run a code in a procedure. Question 3 The program creation in C language is not actually hard on needs to save the text file with a C extension for instance HelloWorld.c C programming language is case sensitive where lower case letters and upper case letters are recognised differently. The codes therefore are written in lower case letters. The uppers case letters are used in preprocessor definitions or inside quotes being parts of character strings. There must me a header file #include which is part of the C Program that gives access to the code in the Standard Input Output Library. There is also the function main() which is part of the C Program that marks the entry point and has the instructions that are performed when the program runs. The most important thing again is the Curly brackets { } in C which are used to group statements together in a function, or within the loop to make a block. Program code written to demonstrate • Write and use a program, procedure, and function. #include /* Print the question numbers tackled */ main() { int i; printf("This is my class submission\n"); for(i = 0; i < 5; i = i + 1) printf("I have done the following questions %d\n", i); return 0; } • Create and constants and variables: both local variables and parameters. • Use simple statements: assignment statement, procedure call, and return statement. #include /* Print the various variables */ main() { int result; int number printf("The following are my expected results\n"); printf("Enter your Mark: "); scanf("%d", &result); // printf("Your Mark is %d \n", result); if (result >= 45) printf("Pass\n"); else printf("Fail\n"); do { result = 45) printf("Pass\n"); else printf("Fail\n"); } while (result < 100); return 0; } Read More
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us