Free Essay

How to Write a Computer Program

In:

Submitted By CEKKERT
Words 1031
Pages 5
How to Write a Computer Program Everyone at one point in their life has had to solve a problem. In school we are taught problem solving techniques such as: identify the problem, analyze the problem, identify possible solutions, analyze and compare possible solutions, implement solutions and review the results. Writing a computer program is essentially solving a problem, so it follows similar steps. The steps in writing a computer program are: analyze the problem, design the program, code the program and test the program. As there is a vast amount of computer languages that programs can be written in, these steps are not language specific and more are a form of programming prewriting. In analyzing the problem you first need to answer a few questions. The most important of these is what result do you want? The result will be the output of the program. Next, you need to determine what information needs to be inputted into your program to receive the desired output. Lastly, you need to determine how you are going to take your input information and turn it into your output information. An example problem is that you want to determine the price of items before and after tax. Your inputs would be: the price of the item, expressed as ItemPrice; the amount of tax, expressed as TaxRate; and the amount of that item, expressed as ItemQuantity. The output would then be the amount of the item before and after tax has been included, expressed as OriginalPrice and TaxPrice respectively. One way to solve this would be to use the following equations: ItemPrice * ItemQuantity = OriginalPrice and then OriginalPrice * TaxRate + OriginalPrice = TaxPrice. Once the problem has been analyzed, the variables identified, and the algorithm has been determined, it is time to design the program. Designing the program is no more than creating a set of step by step instructions, starting at inputting your variables, to arriving at the solution or output. If you were going to give someone step by step directions to get from their home to yours, you would probably start the directions by telling them which way to head on the nearest main road. You wouldn’t say take a left out of your driveway, then take the first right and so on. We leave out obvious steps or small ones because humans can think outside of the parameters of the information given. If you were to give directions to your computer you would need to include steps such as: put on the left shoe, tie the left shoe; put on the right shoe, tie the right shoe; walk to your car keys, pick up the car keys, and so on. You must detail every last step because a computer can only do what it is told, it cannot infer anything. That is why the design is so important; it will establish every step that needs to be taken. The design can be done in plain English, or as diagrams similar to flow charts. An example of a simple design is:
Input the price of an item (to variable ItemPrice) from user
Input the quantity of an item (to variable ItemQuantity) from user
Input the tax amount (to variable TaxRate) from user
Calculate OrigianlPrice as: ItemPrice * ItemQuantity
Calculate TaxPrice as: OriginalPrice * Taxrate + OriginalPrice
Output OriginalPrice and TaxPrice

Every step and function is specific, and leaves no gaps in the instruction. Now we can move to the coding of the program.
Once problem has been analyzed, and the program designed, you can start to code the program. Programming the code involves taking that blueprint created in the design process, and translating it into the programming language you are going to use. In addition to the design you created, when coding, you will also add descriptions into your code to document the program. This documentation will only be visible in the code and not on the program the user sees. There are several reasons to do this, such as explaining the code so other programmers can see what you did, and why, and to give a little bit of information like your name and the program's name. An example code looks like this:

// Program name: Price Calculator
// Author Name: Clifton Ekkert
// Description: This program calculates the total price of items before and after tax. Declare ItemPrice as Float
Declare ItemQuantity as Integer
Declare OriginalPrice as Float
Declare TaxRate as Float
Delcare TaxPrice as Float
Write “This program calculates the total price of items before and after tax.”
Write “Enter Item price in decimal format. i.e. 2.50"
Input ItemPrice
Write “Enter item quantity as a whole number.”
Input ItemQuantity
Write “Enter the tax percentage in decimal form.”
Input TaxRate
Set OriginalPrice = ItemPrice * ItemQuantity
Set TaxPrice = OriginalPrice * TaxRate + OriginalPrice
Write "The total cost before tax is " + OriginalPrice + " dollars."
Write "The total cost after tax is " + TaxPrice + " dollars."

For this program, declarations are defining what type of input each variable needs to be. In this instance, float means a decimal number, and integer means a whole number. In addition, write is the command to display text to the user of the program, and input is the variable required to be provided by the user. Finally, after the program is coded, it must be tested. The program must be run to ensure it performs all steps and gives an output. If it does not output a solution to the problem, you will need to examine the code for where you went wrong. If the program does provide a solution, a wise step would be to verify the answer is correct by performing hand calculations to verify the accuracy of the solution, with two different sets of numbers. In conclusion, a computer program is a tool to solve a problem, and to solve that problem you must follow the problem solving steps. In addition you will need to follow the steps of programming: Analyze the problem, design the program, code the program and test the program. Without following these steps you may still be able to create a functional program but will most likely spend more time fixing errors and attempting to organize the program than if you follow these steps.

Similar Documents

Free Essay

C++ Case Statements

...state-of-the-art gaming computer from components available on the internet. A. Problem Analysis – Following the directions in the assignment, clearly write up your problem analysis in this section. The input consists of computer base price (CompPrice), the CPU choice (CPU_choice), the RAM choice (RAM_choice), and the Graphics Card choice (VideoCard_choice). Once the customer has entered a choice of an option, the program will determine the corresponding cost of that option: CPU_cost, RAM_cost, VideoCard_cost. The only item output is the computer selling price (ComputerPrice). To determine the ComputerPrice, the following computation is: ComputerPrice = CompPrice + CPU_cost + RAM_cost + VideoCard_cost. B. Program Design – Following the directions in the assignment, clearly write up your problem design in this section and comment your pseudocode. Things the program must do: 1. Input the computer base price 2. Process the various options to compute the additional costs 3. Total all the costs 4. Display the final selling price The main Module will contain the following submodules: Compute_CPU_Cost Compute_RAM_Cost Compute_VideoCard_Cost Display_Computer_Price The Hierarchy chart for Computer Price program Pseudocode as follows: // Computer Price calculator // Programmer: Ariel Cintron, University Of Maryland University College // Version 1.0 – February 03, 2012 // This program calculate the...

Words: 908 - Pages: 4

Premium Essay

Prg 211 Week 5

...power of computers to solve problems and perform various tasks (Trott, 2004). Research shows good communication with customers and organizations ensures a meticulous understanding of a distinct problem. Subsequently a program can be designed to meet needs and expectations of customers and organizations (Trott, 2004). Successfully solving problems with program software requires planning, analyzing, and program management to ensure all aspects of the problem meet the required expectations. I believe planning your program following the program development cycle, will enable you to use your time efficiently thus helping design error-free programs that produce the desired output. In the development cycle a programmer needs to first understand the problem by a extracting the requirements or requirements specification (Bronson & Rosenthal, 2005). The programmer then needs to analyze requirements using the information given to provide a repeatable, predictable process that improves productivity and quality results. Then coding takes place by writing statements in computer language to carry out the program design (Bronson & Rosenthal, 2005). After the program has been implemented software testing or validation phases ensures that bugs are recognized. Also accurate documentation of program implementation and testing is done throughout development cycle for future maintenance and enhancement (http://itfp.lps.org). Problem Statement An organization has awarded our program development...

Words: 1533 - Pages: 7

Premium Essay

Calorie

...power of computers to solve problems and perform various tasks (Trott, 2004). Research shows good communication with customers and organizations ensures a meticulous understanding of a distinct problem. Subsequently a program can be designed to meet needs and expectations of customers and organizations (Trott, 2004). Successfully solving problems with program software requires planning, analyzing, and program management to ensure all aspects of the problem meet the required expectations. I believe planning your program following the program development cycle, will enable you to use your time efficiently thus helping design error-free programs that produce the desired output. In the development cycle a programmer needs to first understand the problem by a extracting the requirements or requirements specification (Bronson & Rosenthal, 2005). The programmer then needs to analyze requirements using the information given to provide a repeatable, predictable process that improves productivity and quality results. Then coding takes place by writing statements in computer language to carry out the program design (Bronson & Rosenthal, 2005). After the program has been implemented software testing or validation phases ensures that bugs are recognized. Also accurate documentation of program implementation and testing is done throughout development cycle for future maintenance and enhancement (http://itfp.lps.org). Problem Statement An organization has awarded our program development...

Words: 1551 - Pages: 7

Premium Essay

Programming Languages

...Unit 1 Research Assignment 1: Exploring Programming Languages Computers don't do anything without someone telling them what to do, much like the average teenager. To make the computer do something useful, you must give it instructions in either of the following two ways: * Write a program that tells a computer what to do, step by step, much as you write out a recipe. * Buy a program that someone else has already written that tells the computer what to do. Ultimately, to get a computer to do something useful, you (or somebody else) must write a program. A program does nothing more than tell the computer how to accept some type of input, manipulate that input, and spit it back out again in some form that humans find useful. Table 1 lists some common types of programs, the types of input that they accept, and the output that they produce. Essentially, a program tells the computer how to solve a specific problem. Because the world is full of problems, the number and variety of programs that people can write for computers is practically endless. But to tell a computer how to solve one big problem, you usually must tell the computer how to solve a bunch of little problems that make up the bigger problem. If you want to make your own video game, for example, you need to solve some of the following problems: * Determine how far to move a cartoon figure (such as a car, a spaceship, or a man) on-screen as the user moves a joystick. * Detect whether the cartoon figure...

Words: 3836 - Pages: 16

Premium Essay

Supply and Demand

...In this paper I will choose to write about buying a computer. I will explain the factor that causes the supply and the demand in buying a certain computer. Next I will give two substitutes for the computer that could be used instead of this type of computer. I will give two complements about the type of computer and the programs that were on it. The last thing that will be written about is the necessity of my computer and the impact of the price elasticity. Decision Making When choosing to buy a computer I that it had to have certain programs on the computer so that I may get the task at hand completed. The First thing that was done was too decided in buying the computer is what kind did I want and need. What type of programs would I need on the computer and if the programs cost more than I had? These are just some of the factors that I had to decide on what computer that I really wanted and needed for the task that I had to do. The factor that I had to look at also was what they had at the store that I went to. The next factor that I had was to consider what all I was going to do with this computer. The actors that were shown to me is the different types of programs on each computer and how much each computer memory had. The last factor for the computers were was how long each warranty was so that I could get my money back if something went wrong. The last factor that I had to choose on was deciding the brand on the computer and if it was going to be wireless...

Words: 899 - Pages: 4

Premium Essay

Pta Nhi

...Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Ref Page Chapter 11: Planning the Computer Program Slide 1/44 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Learning Objectives In this chapter you will learn about: § Programs must be planned before they are written § Algorithm § Flowchart § Pseudocode § Plan the logic of a computer program § Commonly used tools for program planning and their use Ref Page 183 Chapter 11: Planning the Computer Program Slide 2/44 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Purpose of Program Planning § To write a correct program, a programmer must write each and every instruction in the correct sequence § Logic (instruction sequence) of a program can be very complex § Hence, programs must be planned before they are written to ensure program instructions are: § Appropriate for the problem § In the correct sequence Ref Page 183 Chapter 11: Planning the Computer Program Slide 3/44 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Algorithm § Refers to the logic of a program and a step-by-step description of how to arrive at the solution of a given problem § In order to qualify as an algorithm, a sequence of instructions must have following...

Words: 3284 - Pages: 14

Premium Essay

Bus 230

...30Chapter  7 major topics: -Keyboards- Input device that contains keys you press to enter data and information into a computer or mobile device -Pointing devices         -Mouse- fits under palm of your hand comfortably                     -as you move the mouse, the pointer on the screen moves with it         -Touchpad- small, flat, rectangular pointing device                        - sensitive to pressure and motion                        -move finger on the touchpad in direction you want pointer to go         -Pointing Stick- ball in-between keys on the keyboard that can control the                                                  pointer-- push in the direction you want the pointer to go                                 -pressure sensitive, shaped like eraser on end of a pencil          -Trackball- stationary device on the side of the mouse the size of a Ping-Pong                                         ball -Optical Scanners- Light-sensing input device that converts printed text and images into a form the computer can process                        -Optical Readers- a device that uses a light source to read characters, marks, codes and then converts them into digital data that the computer can process -OCR (Optical Character Recognition) Devices- devices that usually include a small optical scanner for reading characters and sophisticated software to analyze what is read -OMR (Optical Mark Recognition) Devices- devices that read hand-drawn marks, such as...

Words: 3963 - Pages: 16

Free Essay

Eula

...Terms User Rights Granted by Microsoft Write a paragraph defining the rights of the user in Microsoft’s EULA. Your paragraph must include what rights the user has to use, copy, and install the software. Can you sell or transfer the software to someone else? On how many devices may you install the software? Microsoft’s EULA states that the user has the right to install 1 copy of the software on 1 computer to be used by one person at a time. One cannot sell the software. They can however transfer it with seemingly strict guidelines. They may do so directly on a licensed computer with a COA. The user may reassign this software license to a different computer any number of times, but not more than one time every 90 days. You may not retain any copies. The software is also not licensed for commercial hosting Warranty with the Microsoft License Write a paragraph describing the warranty, if any, which comes with Microsoft Office. Microsoft does offer a limited warranty for this software. The warranty states that it is not responsible for any problems that the user causes due to not following instructions. The limited warranty starts when the user gets their copy and lasts for 1 year. If the user gets any updates or replacement software during that year, they are covered for the remainder of the year, or 30 days, whichever is longer. GNU General Public License User Rights Granted by GNU General Public License Write a paragraph defining the rights of the user...

Words: 656 - Pages: 3

Free Essay

Business Organization

...Computer Organization and Design The Hardware/Software Interface F I F T H E D I T I O N David A. Patterson University of California, Berkeley John L. Hennessy Stanford University With contributions by Perry Alexander The University of Kansas Peter J. Ashenden Ashenden Designs Pty Ltd Jason D. Bakos University of South Carolina Javier Bruguera Universidade de Santiago de Compostela Jichuan Chang Hewlett-Packard Matthew Farrens University of California, Davis David Kaeli Northeastern University Nicole Kaiyan University of Adelaide David Kirk NVIDIA James R. Larus School of Computer and Communications Science at EPFL Jacob Leverich Hewlett-Packard Kevin Lim Hewlett-Packard John Nickolls NVIDIA John Oliver Cal Poly, San Luis Obispo Milos Prvulovic Georgia Tech Partha Ranganathan Hewlett-Packard Table of Contents Cover image Title page In Praise of Computer Organization and Design: The Hardware/Software Interface, Fifth Edition Front-matter Copyright Dedication Acknowledgments Preface About This Book About the Other Book Changes for the Fifth Edition Changes for the Fifth Edition Concluding Remarks Acknowledgments for the Fifth Edition 1. Computer Abstractions and Technology 1.1 Introduction 1.2 Eight Great Ideas in Computer Architecture 1.3 Below Your Program 1.4 Under the Covers 1.5 Technologies for Building Processors and Memory 1.6 Performance 1.7 The Power Wall 1.8 The Sea Change: The Switch from Uniprocessors to Multiprocessors 1.9 Real Stuff: Benchmarking...

Words: 79060 - Pages: 317

Premium Essay

Pic Note

...Basics What is a computer? • Seriously? What is a computer program? • Series of commands that the computer interprets and executes. • For a program to accomplish a task the commands must be put together in a meaningful way. What are the ingredients of a program that does something? • The program must be written in a programming language that the computer can understand. There are several languages: Pascal, Fortran, Basic, C, C++, Java etc. • The program must follow the rules of the language. The programmer must know the words and the grammar. • The instructions must be written in the correct sequence. • The totallity of instructions must accomplish the intended task. • Often the program must be translated into a machine readable language. • The program must be run on a correct platform. What is studying C++ like? • It is much like learning a foreign language. • You learn new words and grammar. The commands are much like words, and grammar is the interaction of the commands. • This class is not about memorizing every single phrase. • Think of the things you learn as tools. As you learn more of the language, you will be able to build more complex programs. • Programming is a creative activity! How is a C++ program written? • It is written using the normal English alphabet and a few extra symbols such as parenthesis ( ) and semicolons ; . • You can write a C++ program on any text editor! • It is, however, easier to use a program such as Microsoft...

Words: 478 - Pages: 2

Premium Essay

Techology

...operate the Device Manager of MS Windows 7 independently; 2. To determine the different hardware that makes up the entire computer system; 3. To validate the theories related to computer hardware structures. DISCUSSION: The Device Manager (see Figure 1.1) is a system software that comes with MS Windows 7 operating system. It is a powerful tool that lets you inspect, manage, and troubleshoot drivers for the hardware already installed in a computer. Figure 1.1 Device Manager EQUIPMENTS: One (1) Set Desktop Computer with MS Windows 7 operating system installed PROCEDURE: 1. Boot the computer using MS Windows 7 operating system. 2. Choose Start>Control Panel>System and Maintenance>System>Device Manager. - or - Choose Start, type “device manager” in the Search box, and then press Enter. 3. Expand the “Display adapters” category by clicking its corresponding plus (+) symbol. 4. List down below all installed devices under Display adapters. Display adapter devices: a. AMD Radeon HD 7640G 5. Show the device’s properties of first listed device by right-clicking its device name and then clicking“Properties” on the active menu (see Figure 1.2). Figure 1.2 Device Properties 6. On the Properties dialog box, click each of the following tabs: General, Details, Driver and Resources. Write the description below of each tab relating to that device. General: AMD Radeon HD 7640G Device type: Display Adapters ...

Words: 4193 - Pages: 17

Premium Essay

Hello Happy

...access is based on something you do that is unique. • Example: Your signature. 4. What You Are • This security system uses biometrics—the science of measuring individual body characteristics. • Example: Fingerprints, retinal scans, and hand characteristics. 1 Chapter 2 Threats To Computer System Q2. 1998 – 1999 Sem B B-1.a) [9 marks] 2000 – 2001 Sem B 3.a) [9 marks] 2003 – 2004 Sem A 5.c) [9 marks] 2004 – 2005 Sem B 5.b) [9 marks] There are three different types of threats: namely disclosure threat, integrity threat and denial of service threat. Describe the characteristics of these threats and the importance of them with example in affecting the normal operations of some computer or organization activities. Answer: Disclosure threat • This threat involves the dissemination of information to an individual for whom that information should not be seen • This information may be in computer storage or in transit between computer systems • disclosure of information is called “leak” • important for confidential organization such as military, government etc. Integrity threat • This threat involves any unauthorized change to information stored on a computer system or in transit between computer systems • non-critical information has less consequence, but critical information can...

Words: 2843 - Pages: 12

Premium Essay

Java for Dummies

...grammar of Java • How to save time by reusing code • All about if, for, switch, and while statements • An overview of object-oriented programming • Building blocks — learn to work with Java classes and methods and add comments • Hints about handling exceptions • How to write Java applets ® • The Java scoop — get an overview of Java, the enhancements in Java 7, and the software tools you need • Get loopy — understand the value of variables and learn to control program flow with loops or decision-making statements 5th Edition 5th Edition Java Java, the object-oriented programming language that works on almost any computer, is what powers many of those cool multimedia applications. Thousands have learned Java programming from previous editions of this book — now it’s your turn! Whether you’re new to programming or already know a little Visual Basic or C++, you’ll be doing Java in a jiffy. g Easier! Making Everythin • Ten ways to avoid mistakes • Class it up — explore classes and objects, constructors, and subclasses, and see how to reuse your code • A click ahead — experiment with variables and methods, use arrays and collections to juggle values, and create programs that respond to mouse clicks Learn to: Visit the companion website at www.dummies.com/go/ javafordummies5e for lots of code samples that you can use in your Java programs • Combine several smaller programs to create a bigger program Go to Dummies.com® ...

Words: 34460 - Pages: 138

Free Essay

Fortran

...Random numbers and Monte Carlo simulations 11. Simple input and output 12. Format statements 13. File I/O 14. Common blocks 15. data and block data 16. Debugging 17. Running Fortran on the Physics Department’s VAX (OHSTPY) computer 18. A sample Fortran program for Lab 1 1. WHAT IS FORTRAN? Fortran is a general purpose programming language, mainly intended for mathematical computations in science applications (e.g. physics). Fortran is an acronym for FORmula TRANslation, and was originally capitalized as FORTRAN. However, following the current trend to only capitalize the first letter in acronyms, we will call it Fortran. Fortran was the first high-level programming language. The work on Fortran started in the 1950's at IBM and there have been many versions since. By convention, a Fortran version is denoted by the last two digits of the year the standard was proposed. Thus we have Fortran 66, Fortran 77 and Fortran 90 (95). The most common Fortran version today is still Fortran 77, although Fortran 90 is growing in popularity. Fortran 95 is a revised version of Fortran 90 which is expected to be approved by ANSI soon (1996). There are also several versions of Fortran aimed at parallel computers. The most important one is High Performance Fortran (HPF), which is a de-facto standard. Users should be aware that most Fortran 77 compilers allow a superset of Fortran 77, i.e. they allow non-standard extensions. In this tutorial we will...

Words: 10641 - Pages: 43

Premium Essay

Programming in Unix

...today’s society, computers have played a major part of how corporations and individuals conduct business. In a sense, they have made some of the hardest tasks fairly easy by the click of a button or by typing a certain command. Computer programs perform both simple and complex calculations with user seeing the end result. However, computer programs have to be written by computer programmers. To understand how programs work, you must consider how the computer interprets the information entered by the programmer. “A program is a set of instructions that guide the computer in performing its basic and logical arithmetic operations (Afzal, 2008, p. 349).” These programs have to be written in a certain language for the computer to interpret. There are several types of languages used to write programs. Although the programmer types words and numbers to perform these mathematical and logical calculations, the computer sees only 1’s and 0’s. This is called machine language. There is also assembler language. “Instead of a series of zeros and ones, assembler language uses some recognized symbols, called mnemonics (memory aids), to represent instructions (Afzal, 2008, p. 349).” High level language is the language in which the programmer desires to write in such as Pascal, C++, C, and Java to name a few. To translate a high level language to machine language, a compiler or an interpreter must be used. The first step to writing a program is to draw a diagram of how you want your...

Words: 1049 - Pages: 5