1 / 37

MECH 215 Programming for Mech. and Ind. Eng. I

Prof. Chadi Assi CB-410-13, Ext. 5799 assi@ciise.concordia.ca. MECH 215 Programming for Mech. and Ind. Eng. I. Lecture: Tuesday/Thursday 8:45 — 10:00 H-920 Office hours: Monday/Wednesday 2:30—3:30 Textbook : C++ How to Program/5e ISBN: 0131857576 by DEITEL&DEITEL

amanda
Download Presentation

MECH 215 Programming for Mech. and Ind. Eng. I

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. Prof. Chadi Assi CB-410-13, Ext. 5799 assi@ciise.concordia.ca MECH 215Programming for Mech. and Ind. Eng. I

  2. Lecture: Tuesday/Thursday 8:45 — 10:00 H-920 Office hours: Monday/Wednesday 2:30—3:30 Textbook: C++ How to Program/5e ISBN: 0131857576 by DEITEL&DEITEL Tutorials: (starts the week of September 11) TA ----J---- 15:15 16:05 FG-B055 Mr. Christopher Johnston (chrisjohnston600@hotmail.com) TB ----J---- 15:15 16:05 H-613 Mr. Alborz Arzpeyna (a_arzpey@alcor.concordia.ca) Lab: (starts the week of September 18) TI ----J---- 16:15 17:05 TBD TJ ----J---- 17:15 18:05 TBD TK ----J---- 16:15 17:05 TBD TL ----J---- 17:15 18:05 TBD Course Highlight

  3. 1. Homework should be submitted by e-mail to Ms. Alessandra Pollifrone (alessandrapollifrone@hotmail.com) 2. No late homework. No exception 4. Copying from the internet or any other source is unacceptable and considered cheating 5. Programming assignments should be given both hard and soft copy (hard copies are submitted to me in class; if you cannot make it to the class, e-mail your assignment) Grading and Rules

  4. 1. Introduction to Computers2. Introduction to C++ Programming3. Introduction to Classes and Objects4. Control Statements Part 15. Control Statements Part 26. Functions7. Arrays and Vectors8. Pointers and Strings9. Classes and Data Abstraction Course Outline

  5. Introduction to Computers Outline -Introduction-What is a Computer?-Computer Organization-Evolution of Operating Systems-Machine Languages, Assembly Languages, and High-Level - Languages-History of C and C++-C++ Standard Library-Visual C++ -Other High-Level Languages-Structured Programming-The Key Software Trend: Object Technology-- OOP -Basics of a Typical C++ Environment-Hardware Trends

  6. Introduction • Software • Instructions to command computer to perform actions and make decisions • Hardware (controlled by software) • C++ is today’s most popular software development language • Standardized version of C++ • United States • American National Standards Institute (ANSI) • Worldwide • International Organization for Standardization (ISO) • Structured programming • Object-oriented programming

  7. What is a Computer? • Computer • Device capable of performing computations and making logical decisions • Computer programs • Sets of instructions that control computer’s processing of data • Hardware • Various devices comprising computer • Keyboard, screen, mouse, disks, memory, CD-ROM, processing units, … • Software • Programs that run on computer

  8. Computer Organization • Six logical units of computer • Input unit • “Receiving” section • Obtains information (e.g., data) from input devices • Keyboard, mouse, microphone, scanner, networks, … • Output unit • “Shipping” section • Takes information processed by computer • Places information on output devices • Screen, printer, networks, … • Information used to control other devices

  9. Computer Organization • Six logical units of computer • Memory unit • Rapid access, relatively low capacity “warehouse” section • Retains information from input unit • Immediately available for processing • Retains processed information • Until placed on output devices • Often called: memory or primary memory • Arithmetic and logic unit (ALU) • “Manufacturing” section • Performs arithmetic calculations and logic decisions

  10. Computer Organization • Six logical units of computer • Central processing unit (CPU) • “Administrative” section • Supervises and coordinates other sections of computer • Secondary storage unit • Long-term, high-capacity “warehouse” section • Storage for • Inactive programs or data • Secondary storage devices • Disks • Longer to access than primary memory • However, less expensive storage per unit than primary memory

  11. Computer Organization

  12. Main (or primary) Memory (1) • It stores • programs • data • results

  13. Main Memory (2) Address Content • Memory: an ordered sequence of storage locations called memory cells • Every cell has a content (to store data) and an address -27.2 0 1 354 107 RTV0001 108 ADD1024 109 STR0005 0.005 1023 75.62 1024

  14. Main Memory (3) • To access cell info: • each cell has a unique address • Content of a cell may or may not be meaningful to our program (unless initialized or accessed by the program) • A cell = • A grouping of smaller units called bytes • A byte = • Amount of storage required to store a single character • Number of bytes per cell varies

  15. 0 1 2 3 4 5 6 7 byte Main Memory (4) • A byte : • Composed of smaller units of storage called bits • Binary: • a numbering system of two numbers 0 & 1 • Bit = Binary digit: • Smallest element a computer can deal with (computers deal only with binary numbers) a bit

  16. Evolution of Operating Systems (OS) • Early computers • Single-user batch processing • Only one job or task at a time • Process data in groups (batches) • Operating systems (developed to make the use of computers more convenient and improve the efficiency of computing systems) • Software systems • Manage transitions between jobs (early OS) • Increased throughput • Amount of work computers process

  17. Evolution of Operating Systems • As computers became more powerful, computing resources were not used more efficiently under the single-user batch processing model • Most of the time machine was waiting for slow input/output devices • Multiprogramming • Many jobs or tasks sharing computer’s resources • “Simultaneous” operation of many jobs (i.e., sharing)

  18. Evolution of Operating Systems • Timesharing • 1960s • Special case of multiprogramming • Users access computer through terminals • Devices with keyboards and screens • Dozens, even hundreds of users • Perform small portion of one user’s job, then moves on to service next user • Does not run all users programs simultaneously • Advantage: • User receives almost immediate responses to requests (no pipelining of tasks)

  19. Machine Languages, Assembly Languages, and High-level Languages • Machine language • Only language computer directly understands • “Natural or native language” of computer • Defined by hardware design • Machine-dependent (a particular machine language can be used only on one type of computer) • Generally consist of strings of numbers • Ultimately 0s and 1s (binary) • Instruct computers to perform elementary operations • One at a time • Cumbersome for humans • Example: +1300042774+1400593419+1200274027

  20. Machine Languages, Assembly Languages, and High-level Languages • Assembly language • English-like abbreviations representing elementary computer operations • Clearer to humans • Incomprehensible to computers • Translator programs (assemblers) • Convert from assembly to machine language • Example: LOAD BASEPAYADD OVERPAYSTORE GROSSPAY (addition of OVERPAY to BASEPAY and store result in GROSSPAY)

  21. Machine Languages, Assembly Languages, and High-level Languages • High-level languages • Similar to everyday English, use common mathematical notations • Single statements accomplish substantial tasks • Assembly language requires many instructions to accomplish simple tasks • Translator programs (compilers) • Convert from high level to machine language • Interpreter programs • Directly execute high-level language programs (w/out compiling into machine language) • Example: grossPay = basePay + overTimePay

  22. History of C and C++ • History of C • Evolved from two other programming languages • BCPL and B • “Typeless” languages • Dennis Ritchie (Bell Laboratories) • Added data typing, other features • Development language of UNIX • Hardware independent • Portable programs • 1989: ANSI standard • 1990: ANSI and ISO standard published • ANSI/ISO 9899: 1990

  23. History of C and C++ • History of C++ • Extension of C • Provides capabilities for object-oriented programming (OOP) • Objects: reusable software components • Model items in real world • Object-oriented programs • Easy to understand, correct and modify • Hybrid language • C-like style • Object-oriented style • Both

  24. C++ Standard Library • C++ programs • Built from pieces called classes and functions • C++ standard library • Rich collections of existing classes and functions • You can use them instead of re-writing them! • “Building block approach” to creating programs • “Software reuse” • Learning C++ essentially is • Learning the language itself • Learning how to use its functions and classes

  25. Visual C++ • Visual C++ • Microsoft’s implementation of C++ • Includes extensions • Microsoft Foundation Classes (MFC) • Common library • GUI, graphics, networking, multithreading, … • Shared among Visual Basic, Visual C++, C# • .NET platform • Web-based applications • Distributed to great variety of devices • Cell phones, desktop computers • Applications in disparate languages can communicate

  26. Other High-level Languages • FORTRAN • Complex mathematical computations • Scientific and engineering applications • COBOL • COmmon Business Oriented Language • 1959: computer manufacturers, government and industrial computer users • Precise and efficient manipulation of large amounts of data • Commercial applications • Pascal • Academic use

  27. Structured Programming • Structured programming (1960s) • Disciplined approach to writing programs • Clear, easy to test and debug, and easy to modify • A program: • a set of procedures (or functions) on a set of data values stored in the memory • Emphasis on functions • Function: • performs a sub task of the program • Abstraction of a behavior • Separation of the behavior of a ‘thing’ from its representation or implementation

  28. The Key Software Trend: Object Technology • Objects • Reusable software components that model real world items • Meaningful software units • Date objects, time objects, paycheck objects, invoice objects, audio objects, video objects, file objects, record objects, etc. • Any noun can be represented as an object • More understandable, better organized and easier to maintain than procedural programming • OOP promotes thinking about software in a way that models the real world • OOP supports good software engineering

  29. Object Oriented Programming, OOP • Emphasis is on • the objects (data) and • how to manipulate them • A program: • A network of objects with their attributes • Attributes = data and operations

  30. Object Oriented Programming, OOP • Real-world problem: e.g., Automated banking system • A Bank Account = a real object Class BankAccount { Data: int number; float balance; Operations: deposit(); wihtdraw(); } • A class: • A definition of something (real thing) • A class is an entity that defines the attributes of an object • Attributes include data and operations (methods)

  31. Object Oriented Programming, OOP • Class: • an entity that defines the attributes of an object • Object: • An instance of a class • A bank Account is a class • A particular bank account (yours) is an object Class Hierarchy • Assume you want to define a new class similar to a predefined class • Example: • Bank-Account • Saving Account • International Account

  32. Basics of a Typical C++ Environment • C++ systems consists of • Program-development environment • Language • C++ Standard Library

  33. Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Compiler Linker links the object code with the libraries, creates a.out and stores it on disk Primary Memory Loader Loader puts program in memory. Primary Memory CPU takes each instruction and executes it, possibly storing new data values as the program executes. Preprocessor Linker Editor Disk Disk Disk Disk Disk CPU . . . . . . . . . . . . Basics of a Typical C++ Environment • Phases of C++ Programs: • Edit (any text editor; VC++ and other packages provide built in editor (a source code file usually ends with .cpp, .cc, .c, etc.)) • Preprocess (to include other files in the file being compiled, definition of symbolic constants, etc. all preprocessor directives start with #, e.g.: # include <filename>)

  34. Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Compiler Linker links the object code with the libraries, creates a.out and stores it on disk Primary Memory Loader Loader puts program in memory. Primary Memory CPU takes each instruction and executes it, possibly storing new data values as the program executes. Preprocessor Linker Editor Disk Disk Disk Disk Disk CPU . . . . . . . . . . . . Basics of a Typical C++ Environment • Phases of C++ Programs: • Compile (generate machine language) • Link (functions and data defined elsewhere: e.g., standard or private libraries ) • Load (load program from disk into memory) • Execute(CPU in charge)

  35. Basics of a Typical C++ Environment • Input/output • cin • Standard input stream • Normally keyboard • cout • Standard output stream • Normally computer screen • cerr • Standard error stream • Display error messages

  36. Hardware Trends • Capacities of computers • Approximately double every year or two • Memory used to execute programs • Amount of secondary storage • Disk storage • Hold programs and data over long term • Processor speeds • Speed at which computers execute programs

  37. General Notes About C++and This Book • Book geared toward novice programmers • Stress programming clarity and simplicity • Easier to understand, debug and test • C and C++ are portable languages • Portability • C and C++ programs can run on many different computers

More Related