COSC 120 Computer Programming

Slides:



Advertisements
Similar presentations
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Advertisements

Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
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,
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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.
Programming Logic and Design Fourth Edition, Introductory
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CS102 Introduction to Computer Programming
Tools make jobs easier to do -A computer is a tool used by many professions A computer can do many different jobs because they are programmable - Machine.
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.
Introduction to Programming. Our Book in CS Why Program? Lets watch a video
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Overview of Programming and Problem Solving Textbook Chapter 1 1.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Introduction عزيزتي الطالبة : يهدف هذا المبحث من تمكينك من التعرف الى مفهوم لغات البرمجة وتعلم أسياسيات لغة البرمجة من خلال دراسة أجزاء من لغة C++ وكتابة.
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 © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming Dr. Halla Abdel Hameed.
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Introduction to Computers and Computing.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Hello world !!! ASCII representation of hello.c.
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.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
CHAPTER 1 OVERVIEW OF COMPUTER AND PROGRAMMING 1.1 Electronic Computer Then and Now 1.2 Computer Hardware 1.3 Computer Software 1.4 The Software Development.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: An Overview of Computers and Programming Languages
Engineering Problem Solving With C An Object Based Approach
Chapter 1: Introduction to computers and C++ Programming
Microsoft Imagine All KU students currently enrolled in a CS class are eligible to receive Microsoft software, including Operating Systems development.
Completing the Problem-Solving Process
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1. Introduction to Computers and Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1: Introduction to Computers and Programming
Chapter 1: Introduction to Computers and Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

COSC 120 Computer Programming Instructor: Dr. Enyue (Annie) Lu Office hours: click here Office room: HS114 Email: ealu@salisbury.edu Course information: Website: http://faculty.salisbury.edu/~ealu/COSC120/COSC120.html. Course schedule: Dates and topics are subject to change as required by class progress

Course overview Optional topics Introduction to class Pointers Introduction to Programming Introduction to C++ Data types Control structures Functions Scope, overloading functions, files Arrays Searching & Sorting Arrays Characters, Strings, and the string Class Structured Data Introduction to class Pointers Operator overloading Optional topics

Chapter 1 Introduction to Computers and Programming

Contents Why Program? Computer Systems: Hardware and Software Programs and Programming Languages What Is a Program Made of? Input, Processing, and Output The Programming Process Procedural and Object-Oriented Programming

Why Program: Program: a set of instructions to a computer to perform a task Computer can do many different jobs because of its programmability. Programmer->software->computer

Elements of a Computer System Hardware CPU (central processing unit): CU, ALU Fetch/decode/execute Main Memory: RAM Byte, bits Memory address volatile Secondary storage Programs are stored in secondary memory and loaded into main memory Hard disks, floppy disks, Zip disks and CD Input/Output devices Software

Software – Programs That Run on a Computer Categories of software: Operating system: programs that manage the computer hardware and the programs that run on them. Ex: Windows, UNIX, Linux - Single tasking, multitasking - Single user, multiuser Application software: programs that provide services to the user. Ex: word processing, games, programs to solve specific problems All computer systems consist of similar hardware devices and software components:

Programs and Programming Languages Program: a set of instructions to a computer to perform a task Programming Language: a language used to write programs

Programs and Programming Languages Types of languages: Low-level (machine): used for communication with computer hardware directly. Often written in binary machine code (0’s/1’s) directly. High-level: closer to human language A compiler or interpreter are programs that make the translations from high-level to low-level languages.

Table 1-1

From a High-level Program to an Executable File connect hardware-specific code (library routines) to machine instructions, producing an executable file convert source file directives to source code program statements Object Code Source Code Linker Preprocessor convert source program statements into machine language instructions a) Code the program with a text editor or using an IDE. (IDE(p11): integrated development environments (eg: Microsoft Visual C++ 6.0 IDE) b) Run preprocessor to convert source file directives to source code program statements. c) Run compiler to convert source program statements into machine language instructions. d) Run linker to connect hardware-specific code to machine instructions, producing an executable file. Steps b–d are often performed by a single command or button click. Errors detected at any step will prevent execution of following steps. Modified Source Code Executable Code Compiler

What Is a Program Made Of? Common elements in programming languages: Key Words Programmer-Defined Symbols Operators Punctuation Syntax

Language Elements, Table 1-2 AKA: also known as

Example Program #include <iostream> #include <string> using namespace std; int main() { string name; cout << "What is your name? "; cin >> name; cout << "Hello there, " << name; return 0; } (#: pound sign) Key words: using, namespace, int, main Programmer-Defined Symbols: ( Identifiers ):name, hours, rate, calcPay()

Program 1-1 // This program calculates gross pay. #include <iostream> using namespace std; int main() { float hours, rate, pay; cout << “How many hours did you work? ”; cin >> hours; cout << “How much do you get paid per hour? ”; cin >> rate; pay = hours * rate; cout << “You have earned $” << pay << endl; return 0; }

Key Words Also known as reserved words Have a special meaning in C++ Can not be used for another purpose Examples in program: using, namespace, int, main

Programmer-Defined Symbols ( Identifiers ) Names made up by the programmer Not part of the C++ language Used to represent various things: variables (memory locations), functions, etc. Example in program: name, hours, rate, calcPay()

Operators Used to perform operations on data Many types of operators: Arithmetic: +, -, *, / Assignment: = Examples in program: << stream insertion operator >> stream extraction operator

Punctuation Characters that mark the end of a statement, or that separate items in a list Examples in program: ; (),} Semi-colon Parentheses Braces

Syntax The rules of grammar that must be followed when writing a program Controls the use of: key words operators programmer-defined symbols punctuation Class 1

Lines and Statements cout << "How many hours did you work? "; There are 2 statements above. The first statement uses one line the second statement spans two lines the semicolon ( ; ) is the statement terminator The contents of a program are thought of in term of lines and statements

Variable Definitions float hours, rate, pay; Two types of information: numbers and characters Numbers may be integers or floating-point The statement below creates three variables in memory named hours, rate, and pay that each can store a floating-point number float hours, rate, pay;

Input, Processing, and Output Three steps many programs perform: Gather input data: from keyboard from files on disk drives Process the input data Generate output: send it to the screen write it to a file

Input, Processing, and Output cout << "Enter your hours and rate " << "separated by a space: "; Input: cin >> hours; cin >> rate; Processing: pay = hours * rate; cout << “You have earned $” << pay;

Program Output How many hours did you work? 10 How much do you get paid per hour? 15 You have earned $150

The Programming Process The programming process consists of several steps, which include: Design Code Test Debug Document

The Programming Process Clearly define what the program is to do. Purpose, Inputs /Outputs, Process Visualize the program running on the computer Design using a Hierarchy chart, flowchart or pseudocode. Desk check for logical errors. Enter/Edit the code and compile it. Correct any errors found during compilation. Compile-time error (syntax/grammatical error) Repeat steps 5 and 6 as many times as necessary Run the program with test data for input Correct any errors found while running the program Run-time errors Repeat steps 5 through 8 as many times as necessary. Validate the results of the program. Use the Example in page 18

Procedural and Object-Oriented Programming Procedural programming: focus is on the process. Procedures/functions are written to process data. Object-Oriented programming: focus is on objects, which contain data and the means to manipulate the data. Messages are sent to objects to perform operations.

Class Review Program Why computer can do lots of job A set of instructions to a computer to perform a task Why computer can do lots of job Programmability Elements of computer system Hardware (CPU, main memory, second storage, I/O), software Software categories OS, application software Programming languages Low-level, high-level Transfer a high-level program to an executable file Preprocess, compile, link Common elements in programming languages Keyword, programmer-defined symbols, operators, punctuation, syntax Which 3 steps most programs perform Gather input data, process data, generate output