1 / 38

Exploring C++ Programming: Basics and Terminology

Delve into the history of C++, creating programs, and understanding the software-hardware combination. Learn about C++ development, object-oriented and generic programming concepts. Begin your journey in C++ today!

ehutchins
Download Presentation

Exploring C++ Programming: Basics and Terminology

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 January 2001

  2. 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 1 January 2001

  3. 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 1 January 2001

  4. 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 1 January 2001

  5. Introduction • Architecture 1 January 2001

  6. Introduction • Software and Its Manifestations 1 January 2001

  7. 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 1 January 2001

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

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

  10. Introduction • A Brief History of C++ • In the early 1970s 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 1 January 2001

  11. 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++ 1 January 2001

  12. 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 1 January 2001

  13. Introduction • Designing and Developing Software • Programming • 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 1 January 2001

  14. 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 1 January 2001

  15. Introduction • Designing and Developing Software • Software development process can be done • Top down • Bottom up • Combination • Major pieces • Specification • Design • Code • Test • Specification and Design should be … • 70-80% of the job 1 January 2001

  16. 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 1 January 2001

  17. Introduction • Abstraction • Can talk of levels of abstraction …… • Higher • Major elements of design • Lower • Detailed elements of design 1 January 2001

  18. 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 1 January 2001

  19. 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 1 January 2001

  20. Introduction • Generic Programming • In each case …. • We’ve been asked to sort a collection of things • We have a different sorting criteria 1 January 2001

  21. 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 1 January 2001

  22. Introduction • Creating a C++ Program • A single C++ program contains • Source code • Which is contained in one or more files called • Implementation files 1 January 2001

  23. 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 theexecutable • Done by a program called a linker • Entire process of compiling and linking is • Called a build 1 January 2001

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

  25. 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 1 January 2001

  26. 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 1 January 2001

  27. 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 1 January 2001

  28. 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 1 January 2001

  29. 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 1 January 2001

  30. 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> 1 January 2001

  31. Introduction • Creating a C++ Program • Recall the line of code from the sample program….???? • cout << " WaaaaHoo 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 and passes • it to cout where it is displayed on the monitor • The object named endl behaves as though we pressed enter on • our keyboard 1 January 2001

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

  33. 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 1 January 2001

  34. 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; • } 1 January 2001

  35. 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 1 January 2001

  36. 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; 1 January 2001

  37. 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; 1 January 2001

  38. 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 1 January 2001

More Related