Introduction to Programming. When you program, you are programming the instruction set of the CPU...
-
Upload
angelina-jennings -
Category
Documents
-
view
220 -
download
1
Transcript of Introduction to Programming. When you program, you are programming the instruction set of the CPU...
When you program, you are programming the instruction set of the CPU (machine language).
Intel 8080 CPU
Machine Language / Assembly Language
The only programming language a CPU can directly execute is machine language (or machine code).
Since machine languageinstructions are in binary,Assembly Language is createdto allow a programmer to codethe instructions in a familiarlanguage, then compile theseinstructions into machinelanguage.
With Assembly Language,you are still programming usingthe instruction set of the CPU.
The Hierarchy of Programming Languages
End-User
Database,Worksheet, Document
Access, Excel, Word
C++, Java, C#
Assembly Language
Machine Language
Hardware - CPU
Lo
we
r L
ev
el
-
Hig
her
Le
vel
10011100001001111110001101010110
#include <iostream.h>main(){ int Total,Kiwi,Bananas; Kiwi = 5; Bananas = 6; Total = Kiwi + Bananas; cout << Total << endl;}
Compiled versus Interpreted
• A compiler translates an entire program (source code) into machine language for execution by the CPU. The result is an executable (.exe) file that can be run on a computer.
A = 5 program.exe
B = A + 3 110001101101101100110101
Print B 001100001110110110101101
• An interpreter translates or compiles a program one line at a time while it is executing. An older example of an interpreted language is Basic. A newer example is JavaScript.
Enter temperature in Fahrenheit: 75It is 23.8889 degrees Celsius.
#include <iostream.h>float Convert(float);
main(){ float F,C; cout << "Enter temperature in Fahrenheit: "; cin >> F;
C = Convert(F);
cout << "It is " << C << " degrees Celsius.\n";}
float Convert (float F){ float C = (5.0/9.0) * (F - 32.0); return C;}
Structured Programming
Program Source Code
Program Output
Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops—in contrast to using simple tests and jumps such as the goto statement which could lead to "spaghetti code" which is difficult both to follow and to maintain.
DeckofCards Lucky; // define object Lucky to be a deck of cardsPlayer Kirk; // define object Kirk to be a player
Lucky.Shuffle; // shuffle the deck of cardsLucky.Cut; // cut the deck or cards
Kirk.Cards = Lucky.Deal(5); // deal 5 cards to KirkKirk.ShowCards; // display the cardsKirk.PokerHand; // display poker hand
Object Oriented Programming (OOP)
Full House
Program Source Code
Program Output
Object-oriented programming (OOP) is a newer approach to program design. It focuses on creating objects. Objects have both properties (data) and methods (functions). For example, an object might be a deck of cards. It’s properties are the number and order of the cards. Its methods/functions are shuffling, cutting, dealing, etc.
Software Development Life Cycle
Phase Comments
Problem Analysis System analysts study the problem and define the specifications for the software.
Program Design The specifications are used to develop an algorithm for the program
Program Coding Programmers produce the code for the program. Alpha versions of the program are created.
Program Debugging and Testing Program testing may be done in-house, or a Beta version may be produced to allow end-users test the program.
Program Implementation and Maintenance
After the program is put into production, the maintenance phase begins. New versions will be released to fix bugs and add requested functionality.
Programming Languages
Language Description
Machine Language The native programming language of the computer's CPU. This low-level language is tedious – CPUs come with a specified set of very basic instructions and operations. For example, a load instruction will move each piece of data from memory to a register on the CPU for processing. Machine language is written in binary – all 1's and 0's.
Assembly Language A more efficient way to write machine language. This low-level language allows instructions to be written in a more understandable format (instead of binary), then converted to machine language.
C A high-level structured, procedural programming language that is widely used for programming applications as well as operating systems. It was developed on a UNIX system and later used to reprogram UNIX.
C++ A high-level object oriented programming language that is a superset of C. Originally designed by Bjarne Stroustrup of AT&T's Bell Labs in 1979. It adds better type checking, data abstraction, and object oriented programming to C.
C# Pronounced C-Sharp, this programming language was developed by Microsoft for its .NET Framework. In many ways, it is an upgrade to C++ and was made to compete with the Java language.
BASIC An early high-level programming language that is simple to use and widely popular. Many of the first home computers in the 1970's and 1980's included this programming language.
COBOL COBOL (Common Business Oriented Language) was the first widely used high-level language for business applications such as payroll and accounting. This older programming language has been updated and is still used today, mostly on mainframe computers.
FORTRAN FORTRAN (Formula Translation) is an older high-level language that was designed for scientific applications.
Objective-C A programming language similar to C that is used by Apple in programming iOS apps. In 2014, Apple created a new language called Swift that will operate within Objective-C.
Pascal Pascal is an older high-level language that was also designed for math and science applications. It was popular as a teaching tool for structured programming before C became popular.
Visual Basic (VB) Microsoft's Visual Basic adds object-oriented features and a graphical user interface to the standard BASIC language.
Java A high-level object-oriented programming language developed by Sun Microsystems for creating programs that are platform independent. Java programs are .class files and will execute on any operating system that has the
Java run-time console installed. Java is now the programming language used for Android apps.
JavaScript A scripting language used in web pages that enhances the limited capabilities of HTML. JavaScript adds many functions to HTML including event handlers, cookies, and pop-up windows.