1 / 44

Introduction

Introduction. Chapter 1 – Introduction to Computers and C++ Programming. Hardware Physical components that make up your computer Software Instructions to command computer to perform actions and make decisions. What is a Computer?. Computer

dmayes
Download Presentation

Introduction

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 Chapter 1 – Introduction to Computers and C++ Programming • Hardware • Physical components that make up your computer • Software • Instructions to command computer to perform actions and make decisions

  2. What is a Computer? • Computer • Device capable of performing computations and making logical decisions • Characteristics ( Speed – Reliability – Storage Capacity)

  3. Computer Organization • Input unit • “Receiving” section • Obtains information from input devices • Keyboard, mouse, microphone, scanner, … • Output unit • “Shipping” section • Takes information processed by computer • Places information on output devices • Screen, printer, networks, … • Information can be used to control other devices

  4. Computer Organization • 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 • Also known as primary memory or primary storage • RAM, ROM, PROM, EPROM, EEPROM • CPU = Control Unit + Arithmetic and logic unit Control Unit (CU) • “Administrative” section • Supervises and coordinates other sections of the computer

  5. Computer Organization 4. CPU = Control Unit + Arithmetic and logic unit Arithmetic and Logic Unit (ALU) • “Manufacturing” section • Performs arithmetic calculations and logic decisions • Secondary storage unit • Long-term, high-capacity “warehouse” section • Storage • Inactive programs or data • Secondary storage devices • Disks, Tapes, CDs, DVDs…. • Longer to access than primary memory • Less expensive per unit than primary memory

  6. Classification Of Computers • Supercomputer • Mainframe • Minicomputer • Microcomputer (IBM PC – APPLE MAC – Notebooks – Personal Digital Assistants) • Network Computers (NC) Accessed through a TERMINAL

  7. Peripheral Equipments • Definition • devices which are connected to a computer via a local interface such as displays, printers, scanners, and so on.

  8. Computer System Configuration • Centralized • Decentralized • Distributed Data Processing • Network

  9. Software Types • Firmware (Bootstrap, BIOS) • Low Level Programs in ROM • Operating systems software • The operating system is a set of programs that loads automatically when you start your computer • Functions : Controlling I/O devices, Memory and file storage management, CPU scheduling and controlling processes, Executing and servicing applications software, Handling errors and restarting, User interface • Examples: DOS – UNIX – Win 95/98/2000/XP/NT – OS/2… • Applications software • An application program is the type of program that you use once the operating system has been loaded. • Programming Languages

  10. Hardware User Operating System Applications Software Software Types

  11. Levels of Programming Languages • Described as low level or high level • It depends on how close they are to the computer language • If close their level is low • If closer to the English-like language their level is high • We have 3 levels: • Machine Language • Assembly Language • High level Language

  12. Programming Languages • Machine language • The only language that a computer directly understands • Machine-dependent • Generally consist of strings of numbers • Ultimately 0s and 1s • Instruct computers to perform elementary operations • One at a time • Cumbersome for humans • Example: +1300042774+1400593419+1200274027

  13. Programming Languages • Assembly language • English-like abbreviations representing elementary computer operations • Clearer to humans • Incomprehensible to computers • Translator programs (assemblers) • Convert to machine language • Example: LOAD BASEPAYADD OVERPAYSTORE GROSSPAY

  14. Programming 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 • Need Translator programs (compilers) • Convert whole program to machine language or Interpreter programs • Directly execute high-level language programs • Example: grossPay = basePay + overTimePay

  15. Examples of High-level Languages • FORTRAN • FORmula TRANslator • 1954-1957: IBM • 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

  16. Examples of High-Level Languages • BASIC • Beginner’s All-Purpose Symbolic Instruction Code • Mid-1960s for academic use • Visual Basic • Developed late 1980s, early 1990s • Powerful features • GUI, event handling, object-oriented programming, error handling …. • Visual Basic .NET • It is the next generation of Visual Basic • Designed to be the easiest and most productive tool for creating .NET applications, including Windows applications, Web Services, and Web applications

  17. Examples of High-Level Languages • Pascal • Introduced in 1971 • Named for Blaise Pascal the 17th century French mathematician • For academic use • Less Wordy with few features

  18. Examples of High-Level Languages • C • Evolved from two other programming languages • BCPL and B • “Typeless” languages, for writing OS and compilers. • C was created by Dennis Ritchie (Bell Laboratories) • Added data typing, other features compared to B language • Development language of UNIX • Hardware independent • Portable programs

  19. Examples of High-Level Languages • C++ • Extension of C • Early 1980s: Bjarne Stroustrup (Bell Laboratories) • “Spruces up” C • Provides capabilities for object-oriented programming • Hybrid language • C-like style • Object-oriented style • Both • C++ standard library • Rich collections of existing classes and functions

  20. Examples of High-Level Languages • 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# • Visual C ++ under the .NET platform • Web-based applications • Distributed to great variety of devices • Cell phones, desktop computers • Applications in disparate languages can communicate

  21. Examples of High-Level Languages • C# (.NET) • Anders Hejlsberg and Scott Wiltamuth (Microsoft) • Designed specifically for .NET platform • Roots in C, C++ and Java • Easy migration to .NET • Event-driven, fully object-oriented, visual programming language • Integrated Development Environment (IDE) • Create, run, test and debug C# programs • Language interoperability

  22. Examples of High-Level Languages • Java • Developped by: Sun Microsystems • Derived from C++ • Runs on many platforms • Used for web pages with dynamic and interactive content • Also used to develop large-scale enterprise applications • Enhance functionality of web servers • Provide applications for consumer devices • Cell phones, pagers, personal digital assistants, …

  23. Structured Programming • Structured programming (1960s) • Disciplined approach to writing programs • Clear, easy to test and debug, and easy to modify • Also known as Procedural Programming • Major task is divided into smaller tasks

  24. Object Oriented Programming • Objects • Reusable software components that model real world items (Student object, Class object, Course object). These objects have attributes and behaviors. • In OOP, the code is more understandable, better organized and easier to maintain than procedural programming • OOP favors modularity (Software reuse)

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

  26. 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 • Preprocess • Compile • Link • Load • Execute

  27. // A first program in C++. #include <iostream> using namespace std; // function main begins program execution int main() { cout << "Welcome to C++!\n"; return0; // indicate that program ended successfully } // end function main Single-line comments. Function main returns an integer value. Preprocessor directive to include input/output stream header file <iostream>. Left brace { begins function body. Function main appears exactly once in every C++ program.. Statements end with a semicolon ;. Corresponding right brace } ends function body. Stream insertion operator. Name cout belongs to namespace std. Keyword return is one of several means to exit function; value 0 indicates program terminated successfully. Welcome to C++!

  28. // Printing a line with multiple statements. #include <iostream> using namespacestd; // function main begins program execution int main() { cout << "Welcome "; cout << "to C++!\n"; return0; // indicate that program ended successfully } // end function main Multiple stream insertion statements produce one line of output. Welcome to C++!

  29. // Printing multiple lines with a single statement #include <iostream> using namespacestd; // function main begins program execution int main() { cout << "Welcome\nto\n\nC++!\n"; return0; // indicate that program ended successfully } // end function main Using newline characters to print on multiple lines. Welcome to C++!

  30. Storage Locations and Addresses • Each memory locations is identified by a number called Memory Address • The address doesn’t change but its contents may change • A memory address holds a fixed amount of data

  31. Variables • Variables • Location in memory where value can be stored • For a programmer a variable is referred to by a name called a Symbolic Address • A variable is declared by a name and a data type before being useddata_type varaiable list; • Common data types • int - integer numbers • char - characters • double - floating point numbers • Declaring variables int integer1; char title; • Can declare several variables of same type in one declaration • Comma-separated list int integer1, integer2, sum; • You cannot use C++ keywords as variable names.

  32. Variables • Variables • Variable names • Valid identifier • Series of characters (letters, digits, underscores) • Cannot begin with digit • Case sensitive

  33. // Addition program. #include <iostream> using namespacestd; // function main begins program execution int main() { int integer1; // first number to be input by user int integer2; // second number to be input by user int sum; // variable in which sum will be stored cout << "Enter first integer\n"; // prompt cin >> integer1; // read an integer cout << "Enter second integer\n"; // prompt cin >> integer2; // read an integer sum = integer1 + integer2; // assign result to sum cout << "Sum is " << sum << endl; // print sum return0; // indicate that program ended successfully } // end function main Declare integer variables. Use stream extraction operator with standard input stream to obtain user input. Calculations can also be performed in output statements cout << "Sum is " << integer1 + integer2 << endl; Stream manipulator endl outputs a newline, then “flushes output buffer.” Concatenating, chaining or cascading stream insertion operations.

  34. Enter first integer 45 Enter second integer 72 Sum is 117

  35. Memory Concepts • Variable names • Correspond to actual locations in computer's memory • Every variable has name, type, size and value • When new value placed into variable, overwrites previous value • Reading variables from memory nondestructive

  36. 45 45 72 45 72 integer1 integer1 integer2 integer1 integer2 117 sum Memory Concepts cin >> integer1; • Assume user entered 45 cin >> integer2; • Assume user entered 72 sum = integer1 + integer2;

  37. Arithmetic • Arithmetic calculations in C++ use arithmetic operators (binary operators) like • * Multiplication • / Division (truncates the remainder if the 2 operands are integer for example 7 / 5 evaluates to 1) • % Modulus operator (returns the remainder of an integer division for example 7 % 5 evaluates to 2. If the operands are not integer we get a syntax error) • + / - Addition/Subtraction • ( ) Sets the order of evaluation

  38. Arithmetic • Rules of operator precedence • Operators in parentheses evaluates first • Nested/embedded parentheses • Operators in innermost pair first • Multiplication, division, modulus comes next • Operators apply from left to right • Addition, subtraction applies last • Operators apply from left to right

  39. Decision Making: Equality and Relational Operators • if structure • Make decision based on truth or falsity of condition • If condition met, body executed • Else, body not executed • Equality and relational operators • Equality operators • Same level of precedence • Relational operators • Same level of precedence • Associate left to right

  40. 1.25 Decision Making: Equality and Relational Operators

  41. // Using if statements, relational // operators, and equality operators. #include <iostream> using namespace std; // function main begins program execution int main() { int num1; // first number to be read from user int num2; // second number to be read from user cout << "Enter two integers, and I will tell you\n" << "the relationships they satisfy: "; cin >> num1 >> num2; // read two integers if ( num1 == num2 ) cout << num1 << " is equal to " << num2 << endl; if ( num1 != num2 ) cout << num1 << " is not equal to " << num2 << endl; Declare variables. if structure compares values of num1 and num2 to test for equality. if structure compares values of num1 and num2 to test for inequality. If condition is true (i.e., values are equal), execute this statement. If condition is true (i.e., values are not equal), execute this statement.

  42. if ( num1 < num2 ) cout << num1 << " is less than " << num2 << endl; if ( num1 > num2 ) cout << num1 << " is greater than " << num2 << endl; if ( num1 <= num2 ) cout << num1 << " is less than or equal to " << num2 << endl; if ( num1 >= num2 ) cout << num1 << " is greater than or equal to " << num2 << endl; return0; // indicate that program ended successfully } // end function main Statements may be split over several lines. Enter two integers, and I will tell you the relationships they satisfy: 22 12 22 is not equal to 12 22 is greater than 12 22 is greater than or equal to 12

  43. Precedence and Associativity of Operations

More Related