Lecture 1B Introduction Richard Gesick

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

The Java Programming Language
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
Chapter 2: Introduction to C++.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Introduction to C Programming
Chapter 1 Introduction.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Chapter 1 Introduction.
A First Program Using C#
HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java Language and SW Dev’t
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Chapter 1 Introduction 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
The Java Programming Language
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Introduction to Java Java Translation Program Structure
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
C++ First Steps.
Working with Java.
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
CSC201: Computer Programming
Lecture 1 Introduction Richard Gesick.
CSCI-235 Micro-Computer Applications
Creating Objects & String Class
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
TRANSLATORS AND IDEs Key Revision Points.
Chapter 1: Introduction to Computers and Programming
Designing and Debugging Batch and Interactive COBOL Programs
2.1 Parts of a C++ Program.
Unit 1: Introduction Lesson 1: PArts of a java program
Chapter 1: Computer Systems
Introduction to C++ Programming
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Chapter 2: Introduction to C++.
Chap 2. Identifiers, Keywords, and Types
Introduction to C Programming
Instructor: Alexander Stoytchev
Presentation transcript:

Lecture 1B Introduction Richard Gesick Figures from Lewis, “C# Software Solutions”, Addison Wesley

Agenda Overview of Programming Languages Basics of C++ and the IDE Errors Intro to Objects and Classes

Programming Languages A programming language specifies the words and symbols that we can use to write a program A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements

Programming Languages Machine language Assembly language High-level languages

Machine & Assembly Languages Machine language Written in binary or hex Written using CPU instruction set Difficult to write, and not portable Assembly language Written using mnemonics for instructions and symbolic names for variables Assembler converts code to machine language Easier to write, but still not portable 1-5

High-Level Languages Examples: Fortran, Perl, COBOL, C++, Java Highly symbolic Portable among CPU architectures Languages can be designed for specific uses: Perl: Internet applications Fortran: scientific applications COBOL: business applications

High-Level Languages Compiled Interpreted Compiler converts source code (instructions and data) into machine language, then program is executed Interpreted Interpreter converts instructions into machine language at run time as instructions are executed Usually executes more slowly than compiled program

Building a Program

1-9

Programming Basics Programming is translating a problem into ordered steps consisting of operations a computer can perform: Input Calculations Comparisons of values Moving data Output The order of execution of instructions is called flow of control

Four Types of Flow of Control Sequential Processing Execute instructions in order Function Call Jump to code in method, then return Selection Choose code to execute based on data value Looping or Iteration Repeat operations for multiple data values

Program Development The mechanics of developing a program include several activities writing the program in a specific programming language translating the program into a form that the computer can execute investigating and fixing various types of errors that can occur Software tools can be used to help with all parts of this process

Problem Solving The purpose of writing a program is to solve a problem Solving a problem consists of multiple activities: Understand the problem Design a solution Consider alternatives and refine the solution Implement the solution Test the solution These activities are not purely linear – they overlap and interact

Problem Solving The key to designing a solution is breaking it down into manageable pieces When writing software, we design separate pieces that are responsible for certain parts of the solution An object-oriented approach lends itself to this kind of solution decomposition We will dissect our solutions into pieces called objects and classes

Program Skeleton #include "stdafx.h" #include <string> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout<<"hello world\n"; cout<<"enter your name"; string name; getline(cin,name); cout<<"Hello "<<name<<endl; return 0; }

Preprocessor directives #include <iostream> // Required for cout, endl. #include <cmath> // Required for sqrt() #include <string> //Required for strings Give instructions to the preprocessor before the program is compiled. Begin with # #include directives ‘add’ or ‘insert’ the named files (and the functionality defined in the files)into the program

Using directives using namespace std; Tell the compiler to use the library names declared in the namespace. The ‘std’, or standard namespace contains C++ language-defined components.

Main function header int _tmain(int argc, _TCHAR* argv[]) Defines the starting point (i.e. entry point) for a C++ program The keyword ‘int’ indicates that the function will return an integer value to the system when the function completes

Code blocks are zero or more C++ declarations or statements enclosed by curly brackets { } The code that defines what a function does (in this case, the main function of the program) is often defined in a code block following the header.

Identifiers Words in programs Categories: We make up Others make up Reserved in the language

C++ Identifiers Must begin with an alphabetic character or the underscore character ‘_’ Alphabetic characters may be either upper or lower case. C++ is CASE SENSITIVE, so ‘a’ != ‘A’, etc… May contain digits, but not in as the first character. May be of any length, but the first 31 characters must be unique. May NOT be C++ keywords.

C++ Identifiers Should be carefully chosen to reflect the contents of the object. The name should also reflect the units of measurements when applicable. Must be declared (and therefore typed) before they may be used. C++ is a strongly typed programming language.

C++ Keywords

Initial Values C++ does not provide initial values for variables. Thus using the value of a variable before it is initialized may result in ‘garbage’.

White Space Spaces, blank lines, and tabs are called white space White space is used to separate words and symbols in a program Extra white space is ignored A valid C++ program can be formatted many ways Programs should be formatted to enhance readability, using consistent indentation

Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works C++ comments can take two forms: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */

Syntax and Semantics The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do

Errors A program can have four types of errors The compiler will find syntax errors and other basic problems (compile-time errors) Mistakes with the language. Always reported by the compiler If compile-time errors exist, an executable version of the program is not created

Errors Linking Errors Missing pieces prevent the final assembly of an executable program A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)

Logic Errors A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) Can be difficult to find. It is important to carefully check the output of your programs for errors. Even programs that appear to work correctly may have bugs!

Expect Errors Process of eliminating logic errors (i.e. bugs) from programs. User-friendly programming environments such as Microsoft Visual C++ integrate the compiler with text processors and code editors special tools to help find bugs in programs (debugger) testing tools and much more…

Program Structure In the C++ programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements These terms will be explored in detail throughout the course An application always contains a method called Main

C++ Classes Class Objects tool for encapsulating data and operations (methods) into one package defines a template or model for creating and manipulating objects Objects data created using the class and its methods an object is an instance of the class creating an object is instantiation

Multiple objects from the same class

Class Declarations Specify a programmer-defined type/object. Begin with keyword ‘class’ followed by the name (i.e. identifier) of the type. Class definition is made in a code block. Class members may include data (attributes) and methods (functions). Visibilities of public, protected, and private are used to control access to class members A semicolon must follow the closing bracket }; Copyright © 2012 Pearson Education, Inc.

Class Methods Define the operations that can be performed on class objects. A constructor is a special method that is executed when objects of the class type are created (instantiated). Constructors must have the same name as the class. A class may define multiple constructors to allow greater flexibility in creating objects. The default constructor is the one that has no parameters. Parameterized constructors provide initial values of data members. Copyright © 2012 Pearson Education, Inc.

Class Definitions Often declared in two parts: The class declaration is typically written in a file named ‘className.h’ Defines the class including data members and the headers of the class methods. The implementation of class methods is typically written in a file named ‘className.cpp’ #include “className.h” Provides implementations for all class methods. Copyright © 2012 Pearson Education, Inc.

Class Syntax Copyright © 2012 Pearson Education, Inc.

Using a Class Once a class is defined, you may use the class as a type specifier. You must include the class definition (i.e. header file) Copyright © 2012 Pearson Education, Inc.

Objects An object has: state - descriptive characteristics behaviors - what it can do (or what can be done to it) The state of a bank account includes its current balance The behaviors associated with a bank account include the ability to make deposits and withdrawals Note that the behavior of an object might change its state

Objects and Classes A class An object (the concept) (the realization) Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class

Class and Object Example How would you describe or define these pictures? What are the differences? What are the similarities? Are you describing a single entity or an entire group of entities?