Fortran Fortran (1958) was unveiled as "The IBM Mathematical FORmula TRANslating system." It was designed for scientific calculations, without
string handling facilities. Along with
declarations,
expressions, and
statements, it supported: •
arrays •
subroutines •
"do" loops It succeeded because: • programming and debugging costs were below computer running costs • it was supported by IBM • applications at the time were scientific. However, non-IBM vendors also wrote Fortran compilers, but with a syntax that would likely fail IBM's compiler. The
US Department of Defense influenced COBOL's development, with
Grace Hopper being a major contributor. The statements were English-like and verbose. The goal was to design a language so managers could read the programs. However, the lack of structured statements hindered this goal. Development of COBOL was tightly controlled, so dialects did not emerge to require ANSI standards. As a consequence, it was not changed for 15 years until 1974. The 1990s version did make consequential changes, like
object-oriented programming. Emerging from a committee of European and American programming language experts, it used standard mathematical notation and had a readable structured design. ALGOL was first to define its
syntax using the
Backus–Naur form. If a student did not go on to a more powerful language, the student would still remember BASIC.
C C programming language (1973) got its name because the language
BCPL was replaced with
B, and
AT&T Bell Labs called the next version "C." Its purpose was to write the
UNIX operating system. C is a relatively small language -- making it easy to write compilers. Its growth mirrored the hardware growth in the 1980s. One region is called the
initialized data segment, where variables declared with default values are stored. The other region is called the
block started by segment, where variables declared without default values are stored. • Variables stored in the
global and static data region have their
addresses set at compile-time. They retain their values throughout the life of the process. • The global and static region stores the
global variables that are declared on top of (outside) the main() function. Global variables are visible to main() and every other function in the source code. • On the other hand, variable declarations inside of main(), other functions, or within { }
block delimiters are
local variables. Local variables also include
formal parameter variables. Parameter variables are enclosed within the parenthesis of function definitions. They provide an
interface to the function. •
Local variables declared using the static prefix are also stored in the
global and static data region. Variables placed in the stack are populated from top to bottom. are called
automatic variables Like the stack, the addresses of heap variables are set during runtime. An
out of memory error occurs when the heap pointer and the stack pointer meet. •
C provides the malloc() library function to
allocate heap memory. Populating the heap with data is an additional copy function. Variables stored in the heap are economically passed to functions using pointers. Without pointers, the entire block of data would have to be passed to the function via the stack.
C++ In the 1970s,
software engineers needed language support to break large projects down into
modules. One obvious feature was to decompose large projects
physically into separate
files. A less obvious feature was to decompose large projects
logically into
abstract datatypes. Abstract datatypes are
structures of concrete datatypes — with a new name assigned. For example, a
list of integers could be called integer_list. In object-oriented jargon, abstract datatypes are called
classes. However, a
class is only a definition; no memory is allocated. When memory is allocated to a class, it's called an
object.
Object-oriented imperative languages developed by combining the need for classes and the need for safe
functional programming. A function, in an object-oriented language, is assigned to a class. An assigned function is then referred to as a
method,
member function, or
operation.
Object-oriented programming is executing
operations on
objects.
Object-oriented languages support a syntax to model
subset/superset relationships. In
set theory, an
element of a subset inherits all the attributes contained in the superset. For example, a student is a person. Therefore, the set of students is a subset of the set of persons. As a result, students inherit all the attributes common to all persons. Additionally, students have unique attributes that other persons don't have.
Object-oriented languages model
subset/superset relationships using
inheritance.
Object-oriented programming became the dominant language paradigm by the late 1990s. It was designed to expand
C's capabilities by adding the object-oriented facilities of the language
Simula. An object-oriented module is composed of two files. The definitions file is called the
header file. Here is a C++
header file for the
GRADE class in a simple school application: // grade.h // ------- // Used to allow multiple source files to include // this header file without duplication errors. // See: https://en.wikipedia.org/wiki/Include_guard // ---------------------------------------------- • ifndef GRADE_H • define GRADE_H class GRADE { public: // This is the constructor operation. // ---------------------------------- GRADE ( const char letter ); // This is a class variable. // ------------------------- char letter; // This is a member operation. // --------------------------- int grade_numeric( const char letter ); // This is a class variable. // ------------------------- int numeric; }; • endif A
constructor operation is a function with the same name as the class name. It is executed when the calling operation executes the new statement. A module's other file is the
source file. Here is a C++ source file for the
GRADE class in a simple school application: // grade.cpp // --------- • include "grade.h" GRADE::GRADE( const char letter ) { // Reference the object using the keyword 'this'. // ---------------------------------------------- this->letter = letter; // This is Temporal Cohesion // ------------------------- this->numeric = grade_numeric( letter ); } int GRADE::grade_numeric( const char letter ) { if ( ( letter == 'A' || letter == 'a' ) ) return 4; else if ( ( letter == 'B' || letter == 'b' ) ) return 3; else if ( ( letter == 'C' || letter == 'c' ) ) return 2; else if ( ( letter == 'D' || letter == 'd' ) ) return 1; else if ( ( letter == 'F' || letter == 'f' ) ) return 0; else return -1; } Here is a C++
header file for the
PERSON class in a simple school application: // person.h // -------- • ifndef PERSON_H • define PERSON_H class PERSON { public: PERSON ( const char *name ); const char *name; }; • endif Here is a C++
source file for the
PERSON class in a simple school application: // person.cpp // ---------- • include "person.h" PERSON::PERSON ( const char *name ) { this->name = name; } Here is a C++
header file for the
STUDENT class in a simple school application: // student.h // --------- • ifndef STUDENT_H • define STUDENT_H • include "person.h" • include "grade.h" // A STUDENT is a subset of PERSON. // -------------------------------- class STUDENT : public PERSON{ public: STUDENT ( const char *name ); ~STUDENT(); GRADE *grade; }; • endif Here is a C++
source file for the
STUDENT class in a simple school application: // student.cpp // ----------- • include "student.h" • include "person.h" STUDENT::STUDENT ( const char *name ): // Execute the constructor of the PERSON superclass. // ------------------------------------------------- PERSON( name ) { // Nothing else to do. // ------------------- } STUDENT::~STUDENT() { // deallocate grade's memory // to avoid memory leaks. // ------------------------------------------------- delete this->grade; } Here is a driver program for demonstration: // student_dvr.cpp // --------------- • include • include "student.h" int main( void ) { STUDENT *student = new STUDENT( "The Student" ); student->grade = new GRADE( 'a' ); std::cout // Notice student inherits PERSON's name name grade->numeric Here is a
makefile to compile everything: • makefile • -------- all: student_dvr clean: rm student_dvr *.o student_dvr: student_dvr.cpp grade.o student.o person.o c++ student_dvr.cpp grade.o student.o person.o -o student_dvr grade.o: grade.cpp grade.h c++ -c grade.cpp student.o: student.cpp student.h c++ -c student.cpp person.o: person.cpp person.h c++ -c person.cpp ==See also==