What do you call the set of rules that must be followed to write a program in computer language?

What is a program and why do we create them?

The book C++ Early Objects, defines a program as "a set of instructions a computer follows in order to perform a task. A programming language is a special language used to write computer programs."

Computers and software go hand in hand. Computers are powerful because they can do many things and programs are the way that we get computers to do these many things.

Video: What is Programming?

Computer hardware

A typical computer consists of:
  1. The central processing unit (CPU)
  2. Main memory (random-access memory, or RAM)
  3. Secondary storage devices
  4. Input devices
  5. Output devices

The CPU

The CPU is the heart of the computer. A program is a sequence of instructions stored in main memory. When a program is run, the CPU fetches the instructions and executes or follows the instructions.

The fetch/decode/execute cycle

  • fetch - get the next instruction from main memory.
  • decode - determine what instruction to perform.
  • execute - perform the instruction.

Every program ends up as a sequence of basic instructions that consist of arithmetic and logic operations and control flow operations.

Arithmetic and logic operations include add, subtract, multiply, divide and comparison of values (equality, less than, greater than).

Control flow operations are used to determine what instruction to execute next. For example, based on the instruction, the program may skip or branch to another part of the instructions list.

You will learn the details of how CPUs process instructions in CS 271, Computer architecture and assembly language.

Main memory

Main memory or RAM is used to store the program while it is executing and to store the data that the program is working with.

RAM details

  • The CPU is able to quickly access any location in RAM.
  • RAM is called volatile storage. Unlike persistent storage, when a computer is turned off or when a program finishes executing, the values stored in RAM are erased.
  • RAM is divided into storage units called bytes. A byte is a sequence of eight bits.
  • A bit is the smallest element of the RAM and it stores a binary digit, either a 0 or a 1. Every program and every data value in your computer is stored as sequences of Os and ls.

Secondary storage

Secondary storage provides long lasting and persistent storage. Unlike RAM, data stored within secondary storage does not disappear when a computers is turned off or restarted. The most common form of secondary storage for large computers is a disk drive but computers can use other forms of secondary storage such as solid state drives which use memory chips that maintain data values without power.

Like main memory, secondary storage also stores information as sequences of 0s and 1s as bits and bytes.

Input devices

We typically think of keyboards and mice but input devices can include cameras, microphones, and many other types of various sensors when you start thinking of computers embedded in cars, electronics, and almost any electrical device.

Output devices

The information a computer sends to the outside world is called output. If a person is involved, output is typically sent to an output device such as the computer screen or a printer. Not all programs will output data to an output device. Instead, the output may be sent out over a computer network or stored in a database.

Video: Hardware and software

Programs and programming languages

As stated above, programming involves creating a set of instructions that a computer will follow to solve a problem or accomplish a task. Let's refine our terminology in this section.

Algorithms

An algorithm specifies a finite sequence of clearly defined operations to solve a specific problem or class of problems. You can describe the steps of an algorithm in many ways including words (also known as natural language), flow charts, pseudo-code (described below), and programming language code.

As the complexity of the problems increase, it is important to design algorithms that are efficient (i.e. quick) and correct in that they produce the specified output for any valid input. In CS 325, Analysis of Algorithms, you will learn techniques for analyzing complexity and for proving correctness.

Turning algorithms into programs

An algorithm can be implemented in many different computer languages and a single program may use or implement many different algorithms. For example, you may use a sorting algorithm to order messages and a decryption algorithm to understand the messages.

Machine code, assembly language, and compilers

A computer's CPU executes your program's instructions. However, while you write a program in a language like C++, a computer CPU can only follow instructions coded as sequences of Os and s. A software compiler is a special program that converts statements written in the computer language to a binary form (Os and s} called machine code. Since it is hard for us to recognize 0 and 1sequences, there is a low-level (close to hardware) programming language called assembly language which uses short abbreviations and patterns to describe what the CPU must do. For example, the assembly statement "MOV AL, 61h;" means copy the following value (61h, hexadecimal representation of 97) into memory location "AL".

You will learn much more about machine code and assembly language in CS 271,Computer architecture and Assembly Language.

High level languages

In this class, you will learn C++ which is a high level language. High level languages are those computer languages that hide many of the low level details of the computer system and tend to use more natural words and symbols versus words such as "MOV" in assembly language which is a low level language.

C++ is one of many high level languages. To see the current popularity of all computer languages, go to the TIOBE Index.

Source code, object code, and executable code

Source code

When you start creating programs in this class, you will be creating source code. Source code is saved in a simple text file called a source file.

Converting source code to executable code

Your computer does not understand source code. You must use a compiler to convert source code to executable code, which you can start and run on your computer.

During the process of converting your source code to an executable file, the C++ compiler will create object code.

Source code is converted to what is called object code by the compiler. The object code for a C++ program is saved in files with an .o or .obj suffix. In a final step called linking, the object files are combined with any library routines (routines provided by the language for use by you) to produce the final executable file with an .exe extension.

Depending on how you compile your program, you may or may not actually see the various steps of converting your source files into an executable. For example in many IDEs (integrated development environments such as Visual Studio, Code:: Blocks, or XCode), the intermediate steps are taken care of automatically so you can click on a "build" button and the executable is created.

What is a program made of?

Language elements

Most programming languages include the following elements.

Key words

Key words are words that have a special meaning in the language. They can only be used for their intended purpose. Also known as reserved words.

Programmer-defined identifiers

Programmer-defined identifiers are words you choose as the programmer to define variables or programming routines.

Operators

Operators preform operations on one or more operands. An operand is a piece of data. The various arithmetic symbols such as +, *, and / are examples of operators.

Punctuation

Punctuation characters mark the beginning or ending of a statement or separate items in a list.

Syntax

Rules that must be followed when constructing a program. These rules define how you can combine key words, programmer-defined identifiers, operators, and punctuation.

C++ Specifics - You will start learning the C++specific language elements in Chapter 2.

Lines and statements

We often think of programs as made of up lines and statements. A line is just a single line in the program. You can display line numbers in most IDE source code editors. In Visual Studio 2013, you have to turn them on as they are off by default. You will often see references to line numbers when you compile your program and you have an error.

What do you call the set of rules that must be followed to write a program in computer language?

The screen shot shows a program with an error. When the program was compiled, the output (gray shaded windows above) included "source.cpp(B)" indicating that the problem was on line 8 of thefile called source. cpp.

A statement is a complete instruction that causes the computer to perform some action. A statement may span more than one line. The meaning of a statement will make more sense once you start programming in Chapter 2.

Variables

A statement is a complete instruction that causes the computer to perform some action. A statement may span more than one line. The meaning of a statement will make more sense once you start programming in Chapter 2.

Input and output

Two of the most important considerations when programming are the input and output. Many of the programs you will write for the class assignments will use keyboard inputs. The program will prompt for input and you will type in a response. As you progress through the degree program, you will gain experience using files, databases, web resources, and other sources for input.

In many if not all of your CS 161 assignments, you will direct the program output to the console. You don't often see console output if you are running applications on Windows or OS X because those types of application programs use graphical user interfaces (GUI). However, GUI programming adds a lot more work to creating a program and our job in CS 161 is to teach you the fundamentals of programming so we will stick with console output.

Example of console output

What do you call the set of rules that must be followed to write a program in computer language?

What do you call the set of rules that must be followed to write a program in a computer language?

In computer science, the syntax of a computer language is the rules that defines the combinations of symbols that are considered to be correctly structured statements or expressions in that language.

What is set of rules of programming language?

A programming language is any set of rules that converts strings, or graphical program elements in the case of visual programming languages, to various kinds of machine code output., formerly known as A programming language is a formal language comprising a set of strings that produce various kinds of machine code ...

What is a set of rules that must be followed when constructing a program?

The rules that must be followed when constructing a program are called syntax.