Introduction to C History and First C Program






















- Slides: 22

Introduction to C++ History and First C++ Program The contents of this lecture prepared by the instructors at the University of Manitoba in Canada and modified by Dr. Ahmad Reza Hadaegh A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 1

A Brief History • A Brief History of Hardware and Software • 1 st Generation • Vacuum tubes (1944 - 1958) • 1 st generation programming language • 1’s and 0’s, switches A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 2

2 nd Generation • 2 nd generation computer • Transistor (1959 -1963) • 2 nd generation programming language • Assembly language A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 3

3 rd Generation • 3 rd generation computer • Integrated circuit (1964 -1970) • 3 rd generation programming language • High level languages • More English-like A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 4

4 th Generation • 4 th generation computer • Microprocessor (1971 - present) • 4 th generation programming language • Very high level languages • Query languages A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 5

5 th Generation • 5 th generation computer • ? • 5 th generation programming language • English • Little ways to go yet A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 6

The focus of this course is on: • A 3 rd generation language • C++ • Using a 4 th generation machine, UNIX A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 7

History of C++ • C++ evolved from C and C evolved from BCPL and B • BCPL was developed by Martin Richards in 1967. • B was developed by Ken Thompson in 1970. • Both B and BCPL were “typeless” language A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 8

History of C++ • In 1972 Dennis Ritchie at Bell Laboratories developed the C language that was originally implemented on DEC PDP-11 computer. • C initially became known as a development language of the Unix operating system • In 1970’s C had evolved into what is now known as Traditional C or Classic C. • The widespread use of C with various types of computers lead to creation of standard C or ANSI C (American National Standard C) A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 9

• ANSI C was approved by International Standard Organization (ISO) in 1989. • An extension of C, C++ was developed by Bjarne Stroustrup in the early 1980 s at bell Laboratories. • C++ provides almost all the features of C plus it adds object -oriented capabilities. • Object-orientation allows • software reusability • more reliability • faster development • easier to understand the code • works much better to solve the complex problems A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 10

Other High Level Languages • There are many high-level languages (3 rd generation languages) • C, C++, COBOL, Fortran, Pascal, … • Some of you might be familiar with other languages such as Pascal • Good language designed for teaching, and was the language previously thought in academy. • For a variety of reasons, it was decided that C++ would serve everyone better. A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 11

• C++ is a large, complex language--much larger and more complex than old languages • That’s the bad news • C++ can be presented in an introductory manner avoiding many of its complexities • That’s the good news • That’s what will happen in this course A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 12

Our first C++ program: #include <iostream> using namespace std; // This is the “Hello World!” program int main () int main() { cout<<“Hello World!”; } <See: Example 1> A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 13

Like other languages, C++ program • Consists of a series of statements as defined by the language syntax • Running a C++ program is a complex process as computers are not able to do anything directly with C++ code • Must go through the compilation process A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 14

Compilation Process Source Program (Hello World) Preprocessor Compilation of Source Program Object Program (Hello World!) • This compilation process effectively translates a C++ program into a form your computer can understand. • Machine language • Differs depending on what kind of machine you use. A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 15

• The compilation process requires a program called a compiler • We will use C++ compiler in Unix for this course A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 16

Comments #include <iostream> using namespace std; // This line is a comment int main () { cout<< “Hello World!”; } A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 17

Comments #include <iostream> using namespace std; // This line is a comment // This line is also a comment int main () { cout<< “Hello World!”; } A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 18

Comments #include <iostream> using namespace std; /* Comments can look like this too!*/ int main () { cout<< “Hello World!”; } A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 19

Comments #include <iostream> using namespace std; /* Comments of this sort can span many lines */ int main () // another comment { cout<< “Hello World!”; } A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 20

Comments #include <iostream> using namespace std; /* Comments of this sort can span many lines*/ int /* a funny place for a comment */ main () { cout<< “Hello World!”; } A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 21

Comments • Are ignored by the compiler. • Are for the exclusive benefit of the programmer. • Used to describe code that otherwise might be misinterpreted. • Also used for other relevant information such as your name, student number, course and assignment number, and so on. A. R. Hadaegh Dr. Ahmad R. Hadaegh California State University San Marcos (CSUSM) Page 22