Chapter 1 Introduction to Computer and C++ Programming.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
COSC 120 Computer Programming
Chapter 1 Introduction to Computers and C++ Programming.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
C programming Language and Data Structure For DIT Students.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
Introduction to Programming Dr Masitah Ghazali Programming Techniques I SCJ1013.
COMPUTER SCIENCE I C++ INTRODUCTION
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CISC105 General Computer Science Class 1 – 6/5/2006.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Mohamed Iqbal Pallipurath Slide 1. Mohamed Iqbal Pallipurath Slide 2 Basics Introduction to Computers and C++ Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
CS CS CS IA: Procedural Programming CS IB: Object-Oriented Programming.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
CS Computer Science I. BCPL was developed in 1967 as a language for writing operating systems and software compilers In 1970, the creators of the.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
BASIC PROGRAMMING C SCP1103 (02)
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Engineering Problem Solving With C An Object Based Approach
Chapter 1: An Overview of Computers and Programming Languages
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1: Introduction to Computers and Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
CS IA: Procedural Programming CS IB: Object-Oriented Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Chapter 1 Introduction to Computer and C++ Programming

Computer Systems There are 3 classes of computers: –Personal Computers (PCs) –Workstations –Mainframes Network: –Consists of a number of computers connected to share resources and information. –Including server and client computers.

Computer Hardware Input devices: –Allowing users to communicate information to computers. –Ex: keyboard, mouse, scanner… Output devices: –Allowing computer to communicate information to users. –Ex: monitor, printer

Computer Hardware (cont.) Central Processing Unit (CPU). –Is the Control unit (cerebellum) of all operations of a computer –Containing Arithmetic and Logical Unit (ALU)

Computer Hardware (cont.) Main memory: –Temporary storage for data –Very fast to access –Random access memory (RAM) –Locations: a number to present the memory address –Units: Bit: the smallest unit, containing binary values (0 or 1) Byte: equals to 8 bits (standard unit of memory) Word: equals to 2 bytes (most computers)

Computer Hardware (cont.) Secondary memory: –Permanent storage –Slower to access –Removable –Information stored a files (execution, data…) –Ex: floppy drive, hard drive, thumb drive, CDs...

Main Components of Computers Input Device(s) Output Device(s) Main Memory Secondary Memory CPU

Computer Software Operating System (OS) –The SW to: Control behaviors of a computer. Control communications to memories and devices Manage resources –Ex: DOS, UNIX, Linux, Windows, Android, Mac …

Computer Software (cont.) Program –Is a set of instructions for a computer to follow. –Usually known as application Data –Inputs to a program

Computer Languages Machine language: –low level - On or Off - series of 0’s and 1’s. –Difficult for humans to read and debug. Very fast for computer to process. –Specific to a particular machine. –Example: (16-bit) (32-bit)

Computer Languages (cont.) Assembly language –consists of a command and one or two storage locations which have been assigned letter names. –Computer must interpret into machine language using an assembler –Example: Add R2, R4, R1

Computer Languages (cont.) Higher level languages –like English. Easy to read and understand. –Portable to many machines and has a language standard. Slower to process. Commands are written and saved in a source file. –A compiler program translates into machine language object or binary file and a linker connects it to other programs (such as to printer), loads in memory and executes. If there are any language (SYNTAX) errors the compiler cannot compile and the compilation stops. –Example: R1 = R2 + R4;

Programming and Problem Solving Programming is Problem Solving!!!!!

Algorithm A sequence of precise instructions that lead to a solution or step-by-step set of instructions to solve a problem. Three requirements: 1.There must be a finite number of steps. 2.Each step must be well defined. 3.Must accomplish the task.

Program Design –Precise Definition of the problem (WHAT’s) What will the output of your program be? What information is needed? What formulas are needed –Algorithm Design (HOW’s) Define how to solve the problem –Testing Check if the problem solved.

Algorithm Design (example) Determine how many times a name occurs in a list of names. 1.Get the list of names. 2.Get the name being checked. 3.Set a counter to 0. 4.For each name in the list, do the followings: Compare the name with the targeted name. If the names are the same, increase the counter. 5.Announce the answer is the number indicated by the counter.

Object Oriented Programming (OOP) A new approach where we model objects in the real world developed in the 1990’s. Used first for simulations, data programs, it has now become the industry standard. Objects are defined by code called classes.

OOP Characteristics Encapsulation: Combining the data of the object with its behavior and hiding the implementation from the user. Inheritance: Allowing one object to reuse code of another object. Polymorphism: Giving different meanings to the same name.

Software Development Cycle 1.Analysis and specification of the task (Problem definition). 2.Design the software (Object and algorithm design) 3.Implementation (Coding) 4.Testing 5.Maintenance and Enhancement Who programs first, finishes last!

Example of SW Design Compute the miles per gallon for a trip of a certain distance in miles

Example of SW Design (cont.) Analysis: (WHAT’s) –Distance (miles) –Gas amount (gallons) –MPG (miles per gallon) IdentifierTypeI/ODescription milesDoubleinputmiles > 0.0 gallonsDoubleinputgallons > 0.0 MPGDoubleoutputMiles per gallon Data Dictionary

Example of SW Design (cont.) Initial Design: (HOW’s) –Read in distance –Read in gas amount –Calculate MPG –Print out result

Example of SW Design (cont.) Refined Design: (HOW’s) 1.Read in distance (miles) Check if distance <= 0.0, then go back to 1 2.Read in gas amount (gallons) Check if gallons <= 0.0, then go back to 2 3.Calculate MPG = miles/gallons 4.Print out result

Example of SW Design (cont.) Structure chart: –(Top Down Design: Divide and Conquer - Break down the main problem into subproblems and the data flow between them. –Minimum of 3 subtasks: Input, Process, Output

Example of SW Design (cont.)

YES NO Get distance Start Distance > 0? Get gallons Calculate MPG Output result End Gallons > 0? FLOW CHART

Introduction to C++ 1.BCPL - Binary Coded Programming Language - System language, supported integers only - Martin Richard 2.B -evolved from BCPL as a general purpose language, however allows only native (machine dependent) data types- Ken Thompson 3. C - separated data types from machine dependency - Dennis Ritchie in 1970’s. More portable, simpler. Became popular with influx of PC’s. –UNIX - first operating system written in higher level language and thus portable –C allows access to machine addresses and is sometimes considered a mid or hybrid language. Dangerous because it allows user to alter operating system. 4.C ++ developed in 1980’s by Bjarne Stroustrup is an extension of C with the inclusion of object-oriented programming. C++ overlaps C.

Sample C++ Program //Sample Program #include using namespace std; int main () { int number_of pods, peas_per_pod, total_peas; cout << “Press return after entering a number.\n”; cout << “Enter the number of pods:\n”; cin >> number_of_pods; cout “Enter the number of peas in a pod:\n”; cin >> peas_per_pods; total_peas = number_of_pods * peas_per_pod; cout << “If you have ”; cout << numer_of_pods; cout << “ pea pods\n”; cout << “ and ” << peas_per_pods; cout << “ peas in each pod, then\n”; cout << “you have” << total_peas; cout << “ peas in all the pods.\n”; return 0; }

Sample C++ Program (cont.) //Sample Program #include using namespace std; int main () { int number_of pods, peas_per_pod, total_peas; cout << “Press return after entering a number.\n”; cout << “Enter the number of pods:\n”; cin >> number_of_pods; cout “Enter the number of peas in a pod:\n”; cin >> peas_per_pods; total_peas = number_of_pods * peas_per_pod; cout << “If you have ”; cout << numer_of_pods; cout << “ pea pods\n”; cout << “ and ” << peas_per_pods; cout << “ peas in each pod, then\n”; cout << “you have” << total_peas; cout << “ peas in all the pods.\n”; return 0; } Comment: Anything after // is not concerned by the compiler. Include directive: #include: a preprocessing directive to link this library to this program prior to execution. The <> says look in directory where the compiler is stored first. Later, you will write your own libraries and store them on your disk. Then you will use “file.h” which tells the compiler to look in the current directory first (where your program is stored). iostream: This is a library containing standard I/O functions. C++ is a very powerful language that can do many things. To facilitate the programmer’s job, C++ contains code to do common tasks (such as graphics, input/output, math functions, etc.) and groups these functions in libraries. C++ divides names into namespaces. The standard language names are in the standard (std) namespace. We need to use this line to use the standard libraries.

Sample C++ Program (cont.) //Sample Program #include using namespace std; int main () { int number_of pods, peas_per_pod, total_peas; cout << “Press return after entering a number.\n”; cout << “Enter the number of pods:\n”; cin >> number_of_pods; cout “Enter the number of peas in a pod:\n”; cin >> peas_per_pods; total_peas = number_of_pods * peas_per_pod; cout << “If you have ”; cout << numer_of_pods; cout << “ pea pods\n”; cout << “ and ” << peas_per_pods; cout << “ peas in each pod, then\n”; cout << “you have” << total_peas; cout << “ peas in all the pods.\n”; return 0; } Return statement: returns the value computed by the function and control back to the operating system. int main () A C++ program is a function that may call other functions to accomplish subtasks main: is the main program function—it is always used. {} is used to group together the code inside a function. begin-end. semicolons denote the end of each line in C++. Variable Declarations (Storing data): sets up storage spaces in the memory to store information and attaches the name (area). The word int tells the computer it will need enough storage space to store an integer number and to use that format. Output statement: sends output to the standard output device (screen) String constants (in double quotes) are to be printed as is, without the quotes. In example above, “Enter... “ is called a prompt. All user input must be preceded by a prompt to tell the user what is expected. \n advances the cursor to the start of the next line rather than to the next space. Backslash is the escape symbol. It means ignore the usual meaning of the next symbol and go for the alternate. Variables are displayed when named in cout. cout<<total_peas; Input statement: cin>> variable; stores value typed from standard input device (keyboard) into variable.

Compiling and Running a C++ Program Source code: The file you type in with the editor. Compile and Build: Translates your code into machine language-object code and adds system libraries to your code. –Compile detects syntax errors. –Build detects linking errors Run: Links your code to the standard routines and executes.

Testing and Debugging Syntax errors: improper use of the language. Caught by the compiler. Fatal Runtime errors: violations in execution (divide by zero, negative square root) Fatal—program terminates Logic errors: mistake in algorithm: non fatal - time consuming Warnings: you are doing something that can be done but is usually ill-advised. DEBUGGER: a tool to watch a program during execution. Used for runtime and logic errors.