Introduction Overview We Will Introduce Basic Concepts and

Introduction Overview We Will ……. . · Introduce Basic Concepts and Terminology · Begin with Bit of History of C++ · Explore the Mechanics of Creating a C++ Program · Create and Execute Some Simple C++ Programs 1

Introduction History First Generation The early machines were mechanical Abacus to Babbage to Jacquard Second Generation - 1940 First electronic computers…. · 16 bit words · 18000 Tubes · No Operating System · Programmed in machine code Copyright 2001 Oxford Consulting, Ltd 2 1 January 2001

Introduction History Third Generation - 1960 Transistors OS - IBM 360 family Early work with Windows, Pointing devices, Networking FORTRAN COBOL Basic Fourth Generation - 1970 First microprocessors OS - UNIX Assembler, C, Pascal, Modula, Smalltalk Copyright 2001 Oxford Consulting, Ltd 3 1 January 2001

Introduction History Fifth Generation - 1980 - 2000 VLSI UNIX continues to evolve Microprocessor OS Introduced C Continues to Mature Smalltalk 86 Developed ADA Work Started C++ and Other Object Centered Languages Developed Beyond 1990 Dawn of Information Age Legitimate Mixed Media Interactive Distributed Computing Copyright 2001 Oxford Consulting, Ltd 4 1 January 2001

Introduction Architecture Copyright 2001 Oxford Consulting, Ltd 5 1 January 2001

Introduction Software and Its Manifestations Copyright 2001 Oxford Consulting, Ltd 6 1 January 2001

Introduction Combining Hardware and Software Problem Find the sum of 2 and 3 1. Must translate into more compatible form Problem stated in natural language Problem stated in computer language Copyright 2001 Oxford Consulting, Ltd 7 1 January 2001

Introduction Combining Hardware and Software Problem stated in natural language 2. More translation Problem stated in computer language by hand · Compiler · Assembler Program translated into assembler using compiler · Linker and Loader Program translated into Machine language using assembler Copyright 2001 Oxford Consulting, Ltd 8 1 January 2001

Introduction Combining Hardware and Software Program linked and loaded into memory using linking loader 3. Into Memory Program copied from hard drive into RAM Program goes from RAM to CACHE Program goes from CACHE to Instruction Register Copyright 2001 Oxford Consulting, Ltd 9 1 January 2001

Introduction A Brief History of C++ In the early 1970 s a series of higher level languages developed Intention was to replace assembly coding The best of these was a language called C Using the C language Programmer could write discrete code blocks called functions Copyright 2001 Oxford Consulting, Ltd 10 1 January 2001

Introduction A Brief History of C++ Ten years after C was introduced…. Bjarne Stroustrup set out to create a new language With object-oriented capabilities similar to Simula In the early 1980’s he looked for a language in which to add O-O capabilities…. . Chose C for a number of reasons After several iterations, the new language was called C++ Copyright 2001 Oxford Consulting, Ltd 11 1 January 2001

Introduction Designing and Developing Software Let’s now see how we might begin to use C++ We’ll begin by taking a closer look programming process Software is integral part of modern computer systems It’s very important that it be • Specified and designed properly • Reliable • Tested comprehensively Copyright 2001 Oxford Consulting, Ltd 12 1 January 2001

Introduction Designing and Developing Software Programming is process of translating Problem stated in one language To another language Result of programming is a program Program Sequence of instructions that direct the computer To solve a problem Copyright 2001 Oxford Consulting, Ltd 13 1 January 2001

Introduction Designing and Developing Software Our goal as designers of software programs it to write programs · Solve problem · Bug free ……. Both of these are approached asymptotically Let’s try to be a bit more specific…. . our goals are, · Performance · Robustness · Ease of change · Style Copyright 2001 Oxford Consulting, Ltd 14 1 January 2001

Introduction Designing and Developing Software development process can be done · Top down · Bottom up · Combination ÞSpecification and Design should be … Major pieces · Specification · Design · Code · Test Copyright 2001 Oxford Consulting, Ltd 70 -80% of the job 15 1 January 2001

Introduction Abstraction All computer programming involves working with real-world things When we write a program…. . • We focus only on that information necessary for our application • We then discard the rest Copyright 2001 Oxford Consulting, Ltd 16 1 January 2001

Introduction Abstraction Can talk of levels of abstraction …… § Higher Major elements of design § Lower Detailed elements of design Copyright 2001 Oxford Consulting, Ltd 17 1 January 2001

Introduction Object Oriented Programming C++ uses a concept called object-oriented programming (OOP) OOP means that rather than have a function as the basic building block of our program…. We group of functions and the associated data into a collection we call an object Copyright 2001 Oxford Consulting, Ltd 18 1 January 2001

Introduction Generic Programming • Give me a list of the following buildings in alphabetic order Grocery, Ball Park, Department Store, Fromagerie, Butcher • Give me a list of the following cars in order of cost Rolls, Mercedes, BMW, Ford, Nissan, Fiat • Give me a list of the following numbers in numeric order Twelve, Twenty One, Two, Fourteen, Sixteen, Ten • Give me a list of the following people according to when they lived Caesar, Attila, Plato, Litotes, Thatcher, King Copyright 2001 Oxford Consulting, Ltd 19 1 January 2001

Introduction Generic Programming In each case …. § We’ve been asked to sort a collection of things § We have a different sorting criteria Copyright 2001 Oxford Consulting, Ltd 20 1 January 2001

Introduction Generic Programming We can propose a generic procedure to sort this stuff 1. Take a collection of things 2. Accept a set of rule describing how to put them in order 3. Apply the rules to the collection This example illustrates what we call Generic Programming Copyright 2001 Oxford Consulting, Ltd 21 1 January 2001

Introduction Creating a C++ Program A single C++ program contains Source code Which is contained in one or more files called Implementation files Copyright 2001 Oxford Consulting, Ltd 22 1 January 2001

Introduction Creating a C++ Program • Each implementation file is first prepared for compiling By a program called a preprocessor • Prepared file then converted to a file of machine instructions Using a program called a compiler • Which creates a file of machine instructions Called an object file • Next object files are combined into a single file Called the executable • Done by a program called a linker • Entire process of compiling and linking is Called a build Copyright 2001 Oxford Consulting, Ltd 23 1 January 2001

Introduction Creating a C++ Program // Sample C++ Program #include <iostream> using namespace std; int main(void) { cout << "Waaaa. Hoo This is my first C++ program" << endl; return 0; } Copyright 2001 Oxford Consulting, Ltd 24 1 January 2001

Introduction Creating a C++ Program • A function Begins at a left brace and Ends at a right brace • Between the braces is the function body • The function body consists of One or more statements • A semi-colon terminates a statement The function name together with the function body Called the function definition Copyright 2001 Oxford Consulting, Ltd 25 1 January 2001

Introduction Creating a C++ Program After the heading of the function…. . int main(void) …. We may insert a comma-separated list of things between the parentheses Each thing we insert is called a function argument Copyright 2001 Oxford Consulting, Ltd 26 1 January 2001

Introduction Creating a C++ Program The double symbol // in C++ defines the start of a comment Anything after a // on that line treated as comment C++ comments may contain comments …. We call that nesting Copyright 2001 Oxford Consulting, Ltd 27 1 January 2001

Introduction Creating a C++ Program We may also use C-style comments: /* Sample C++ Program */ In C a comment…. Starts with a /* and Ends with an */ C-style comments may not be nested Copyright 2001 Oxford Consulting, Ltd 28 1 January 2001

Introduction Creating a C++ Program How about this line…. ? ? #include <iostream> This line is an example of a preprocessor directive It instructs preprocessor to locate something named iostream The preprocessor will insert a copy of the information Into the program at the place where the #include is located iostream is an example of a header file Copyright 2001 Oxford Consulting, Ltd 29 1 January 2001

Introduction Creating a C++ Program One final line…. using namespace std; This line indicates we are using the std namespace Namespace is C++ feature that is beyond this course For now we accept the fact that we need this line of code following the line #include <iostream> Copyright 2001 Oxford Consulting, Ltd 30 1 January 2001

Introduction Creating a C++ Program Recall the line of code from the sample program…. ? ? cout << " Waaaa. Hoo This is my first C++ program " << endl; Here we are using a C++ object called cout << is a C++ operator This particular operator takes the right hand operand passes it to cout where it is displayed on the monitor The object named endl behaves as though we pressed enter on our keyboard Copyright 2001 Oxford Consulting, Ltd 31 1 January 2001

Introduction Creating a C++ Program Formatting our C++ Code? ? // Sample C++ Program #include <iostream> using namespace std; int main(){cout << "Waaaa. Hoo This is my first C++ program " << endl; return 0; } Copyright 2001 Oxford Consulting, Ltd 32 1 January 2001

Introduction Creating a C++ Program · One statement per line · Opening and closing braces on their own line and lined up in the same column · Indent statements in a function from the braces · Leave no space between a function name and the parentheses of the argument list Copyright 2001 Oxford Consulting, Ltd 33 1 January 2001

Introduction Declaring Variables Following program • Declares an age variable • Initializes it • Displays the value on the monitor // C++ Program using a variable #include <iostream> using namespace std; int main() { int age = 21; cout << "The voting age is " << age << endl; age = 65; //change the age variable cout << "The retirement age is " << age << endl; return 0; } Copyright 2001 Oxford Consulting, Ltd 34 1 January 2001

Introduction Using the Keyboard C++ gives us an operator we can use to bring in information from the keyboard With the stream object cin and the >> operator We can write…. cin >> age; When our program encounters this line · It will pause · Wait until we enter a number and Press the enter key Copyright 2001 Oxford Consulting, Ltd 35 1 January 2001

Introduction Using the Keyboard We could add a prompt for the user…. // // notice no endl. This is so the age you enter appears on the same line as the prompt cout << "Please enter your age: "; cin >> age; cout << endl << "You entered: " << age << endl; Copyright 2001 Oxford Consulting, Ltd 36 1 January 2001

Introduction Using the Keyboard cin ignores spaces when processing information from the keyboard int month; int day; int year; cin >> month; cin >> day; cin >> year; cout << month << "/"<< day << "/"<< year << endl; Copyright 2001 Oxford Consulting, Ltd 37 1 January 2001

Introduction Summary At this time you should have a general understanding of ¨ The overall structure of a C++ program ¨ What such a program contains ¨ How a problem evolves from an idea to a running program ¨ How the operating system starts it ¨ How to do basic input and output Copyright 2001 Oxford Consulting, Ltd 38 1 January 2001
- Slides: 38