What are the elements of computer programming?

256 28 18
                                    

What are the elements of computer programming?

A/N: Computer programming is the latest hot item job career. People who can program are making good money and are in high demand, and the good thing is that you don't need a computer science degree. The trick is to learn programming. There are schools out there that will teach you programming for a price. That's the only drawback, but it's less expensive than a four-year college degree.

I'm writing this to give you an idea about what computer programming is all about. We'll talk about C++ language in this simple essay. C++ is considered an advanced language and it's probably one of the most used these days.

Writing computer programs is like writing a well-designed story. First you need characters. These are called variables in programming. Variables, like characters, come in several flavors. They can be numbers or strings. A number can be either an integer or a real, formally called a floating-point number. Strings are a series of alphabet characters (or alpha numeric symbols) that can contain words. After you define your variables, you need to figure out how these variables are going to interact to determine an outcome. In story writing this is called a plot, and in the case of a computer program this plot has to be logical.

So, here is a simple C++ program designed to compute the cost of a pizza.
First you need to include some routines that are part of the language.

#include <iostream.h> this is a header file (a file of programming statements that goes in front of the main program) that contains routines to input and output stuff. A header file has programming for certain routine tasks that the compiler substitutes for certain program statements as needed.

#include <conio.h>: this is header file that contains routines to operate the console i.e. keyboard and screen.

void main() { this is always the start of the main function in a program. It's a void function, meaning it returns no value. If it were to return a value, the 'void' would be 'int' or 'real' depending on what it would return if called in a subsequent programming line.

The next step is to define the variables -- sort of like a character list for a story.

int NumberOfToppings; This is an integer value

int CostForToppings; This is another integer value

int Cost; Same here

Now that we have the list of variables we need the program to use them.

cout << "How many toppings do you want?

; This function outputs this question to the screen

cin >> NuberOfToppings; This function takes what the operator (the person running the program) types in as number

CostForToppings = NumberOfToppings * 2; This multiplies the Number of toppings by 2

Cost = 10 + CostForToppings; this adds ten to the value from the last line

cout << *Your pizza costs $* << Cost << *

*; This puts the result on the screen.

cout << *

Press any key to end*; The

prints a carriage return and linefeed - move the cursor ( a blinking C: character) down on the screen.

while (!kbhit()); This is a loop that checks for a key press--basically, it waits until a keyboard key is pressed and when that happens the kbhit() function returns a value and any positive value makes the loop stop because the kbhit() return is not zero.

Notice that all programming lines in C++ require a semicolon to indicate the end of the line. The reason for this has to do with the way that a compiler reads the program. A compiler is a complicated computer program that reads through the program as written and interprets what you want it to do. It needs the semicolon to know that it has reached the end of a programming line. Actually, the compiler simply reads the programming file one character at a time and looks for key words and then numerical values. Then, it creates the machine (machine language is a more primitive language dealing with the computer processor chip) code necessary to do whatever the line commands. When it sees a semicolon, it knows that the instructions of that line have ended. As long as the syntax (the commands as arranged in the line - this is like grammar) is okay it will chug along to the end of the file. Otherwise it issues an error report telling the programmer that he or she has goofed.

The compilers ultimate job is to create binary code that a computer needs to run a program. The computer doesn't know English or any other language for that matter. It only understands binary.

The final step in the process is accomplished by what is called a Linker, which essentially links binary code together. The reason it's called a linker is because it links object files from the compiler together to form a single executable file that the operating system can use to run the finished program.

The cornerstone of C++ language is the use of objects. An object is a unit of programming that combines both variables and functions in a single unified object. For example we could make a pizza object (also called a class).

class Pizza {

public: this declares the class to be usable by all other routines

void ChooseSize (); this says that this routine doesn't return a value

void ChooseToppings (); same for this

void PrintOrder(); and this

private: this declares that what follows is only used by the main routine

ToppingList *Toppings; *Toppings is a pointer to the location in memory of the variable ToppingsList.

int Size; declares an integer

float Cost; declares a floating value

}; this marks the end of the class declaration

Of course, you must define what the three routines in the public part of the object do. Pointers are tricks in C++ that make it more efficient to access variables.

As you can see from this very simple program that programming is complicated and requires learning a new very complicated language that doesn't allow syntax errors. It makes you respect what programmers have to do.

Thanks for reading.

The Theory of NothingWhere stories live. Discover now