Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1044 – Intro. To Programming in C++ Dr. Craig A. Struble.

Similar presentations


Presentation on theme: "CS1044 – Intro. To Programming in C++ Dr. Craig A. Struble."— Presentation transcript:

1 CS1044 – Intro. To Programming in C++ Dr. Craig A. Struble

2 Chapter 1 2 What is Programming? Planning or scheduling the performance of a task. Consciously thinking about each step Example: Accelerating in a car 1. Move right foot to gas pedal 2. Apply pressure to gas pedal with right foot 3. If speed is too high, apply less pressure. 4. If speed is too low, apply more pressure.

3 Chapter 1 3 Are Computers Intelligent? Do we really need to be involved in programming computers? – They have beaten world chess champions. – They help predict weather patterns. – They can perform arithmetic quickly. So, a computer has an IQ of _____.

4 Chapter 1 4 What Do We Have To Do? Computers cannot analyze problems and devise solutions. Humans (that’s us) must – Analyze and understand a problem; – Devise a sequence of steps to solve the problem; – Translate the steps into a computer language.

5 Chapter 1 5 Basic Computer Components Central Processing Unit (CPU) Arithmetic/Logic Unit Control Unit Memory Unit Input Devices Output Devices

6 Chapter 1 6 Central Processing Unit (CPU) Executes stored instructions Arithmetic/Logic Unit (ALU) – Performs arithmetic and logical operations Control Unit – Controls the other components – Guarantees instructions are executed in sequence

7 Chapter 1 7 Memory Unit Ordered sequence of cells or locations Stores instructions and data in binary Types of memory – Read-Only Memory (ROM) – Random Access Memory (RAM) 1001 1002 1003 1004 1005 1006 1007 1008 1009 Address

8 Chapter 1 8 Input and Output Devices Interaction with humans Gathers data (Input) Displays results (Output)

9 Chapter 1 9 What is Computer Programming? Planning or scheduling a sequence of steps for a computer to follow to perform a task. Basically, telling a computer what to do and how to do it.

10 Chapter 1 10 What Is A Computer Program? A sequence of steps to be performed by a computer. Expressed in a computer language.

11 Chapter 1 11 A Computer Program In C++ // This program converts miles to kilometers. // From Problem Solving, Abstraction, & Design Using C++ // by Frank L. Friedman and Elliot B. Koffman #include using namespace std; int main() { const float KM_PER_MILE = 1.609; // 1.609 km in a mile float miles, // input: distance in miles kms; // output: distance in kilometers // Get the distance in miles cout << "Enter the distance in miles: "; cin >> miles; // Convert the distance to kilometers and display it. kms = KM_PER_MILE * miles; cout << "The distance in kilometers is " << kms << endl; return 0; }

12 Chapter 1 12 Computer Languages A set of – Symbols (punctuation), – Special words or keywords (vocabulary), – And rules (grammar) used to construct a computer program.

13 Chapter 1 13 Differences In Computer Languages Languages differ in – Size (or complexity) – Readability – Expressivity (or writability) – "Level" closeness to instructions for the CPU

14 Chapter 1 14 Machine Language Binary-coded instructions Used directly by the CPU Lowest level language Every program step is ultimately a machine language instruction 10010110 11101010 00010010 10101010 10010110 11101010 11111111 01010101 10101101 2034 2035 2036 2037 2038 2039 2040 2041 2042 Address Contents

15 Chapter 1 15 Assembly Language Each CPU instruction is labeled with a mnemonic. Very-low level language – Almost 1 to 1 correspondence with machine language Translated to machine language by an assembler. MnemonicInstruction ADD10010011 MUL X,10 ADD X,Y STO Z,20 SUB X,Z Sample Program

16 Chapter 1 16 High-Level Languages Closer to natural language Each step maps to several machine language instructions Provides support for abstractions – Easier to state and solve problems

17 Chapter 1 17 Examples of High-Level Languages LanguagePrimary Uses PascalLearning to program C++General purpose FORTRANScientific programming PERLWeb programming, text processing JavaWeb programming, application programming COBOLBusiness

18 Chapter 1 18 Basic Programming Language Structures Sequence – Execute steps or statements in the language one after another. Statement …

19 Chapter 1 19 Basic Programming Language Structures Selection (AKA branch or decision) – Selectively execute statements based on some condition being true or false. – IF condition THEN statement1 ELSE statement2 Condition Statement1 Statement2 … True False

20 Chapter 1 20 Basic Programming Language Structures Loop (AKA repetition or iteration) – Repeat a statement several times until a specified condition is false. – WHILE condition DO statement1 Condition Statement1 False True …

21 Chapter 1 21 Basic Programming Language Structures Subprogram (AKA procedure, function, method, or subroutine) – A collection of the previous structures that accomplishes some smaller task. SUBPROGRAM1 Accomplishes some small part of a larger task. …


Download ppt "CS1044 – Intro. To Programming in C++ Dr. Craig A. Struble."

Similar presentations


Ads by Google