Chapter 1 C++ Basics

Size: px
Start display at page:

Download "Chapter 1 C++ Basics"

Transcription

1 Chapter 1 C++ Basics 1 Learning Objectives Introduction to C++ Variables, Expressions, and Assignment Statements Console Input/Output Program Style Libraries and Namespaces 2

2 Introduction to C++ Origins of the C++ language Object-oriented programming The character of C++ C++ Terminology A sample C++ Program 3 Introduction to C++ Origins of the C++ language 1970, Dennis M. Ritchie, AT&T Bell Labs Dennis Ritchie Bell Labs, Rm 2C Mountain Ave. Murray Hill, New Jersey , USA dmr@bell-labs.com (office), (fax) AT&T Bell Telephony Labs. Bell Labs Lucent Used for writing and maintaining Unix O.S. A general purpose Language Major Drawbacks of C language: Not easy to understand and coding Poor code reusability Lack of exception handling mechanism 4

3 Introduction to C++ Origins of the C++ language(con t) History of C++ C++ was written by Bjarne Sroustrup at Bell Labs during C++ is an extension of C. C++ combines object-oriented features with the power and efficiency of C. The term C++ was first used in C++ was released in Introduction to C++ Object-oriented programming OOP (Object Oriented Programming) Objects and Classes Encapsulation Inheritance Polymorphism 6

4 Objects Introduction to C++ Object-oriented programming(con t) Hidden data that is accessed and manipulated through a well-defined interface Behaviours (s) things an object can do like procedures and functions in other languages Attributes (fields) information an object knows (has-a) like data and variables in other languages (records) 7 Class Introduction to C++ Object-oriented programming(con t) A template for creating objects. Defines the attributes and behaviors for one kind of object. No data is allocated until an object is created from the class. The creation (construction) of an object is called instantiation. The created object is often called an instance (or an instance of class X) 8

5 Introduction to C++ Object-oriented programming(con t) Interface Internal/private/helper s only available within the class. Attributes (Fields of the class) Defined by the class. Filled by the object. 9 Introduction to C++ Object-oriented programming(con t) Encapsulation Abstraction Information Hiding Security Attributes (Fields of the class) 10

6 Introduction to C++ Object-oriented programming(con t) Inheritance A new class created by modification of an existing class The inheriting class contains all the attributes and behaviors of the class it inherited from plus any attributes and behaviors it defines The inheriting class can override the definition of existing s by providing its own implementation The code of the inheriting class consists only of the changes and additions to the base class 11 Introduction to C++ Object-oriented programming(con t) Interface override Fields of The Object Additional Fields 12

7 Introduction to C++ Object-oriented programming(con t) Advantages of inheritance Modular coding less code, easier to understand Code reuse don t break what is already working easier updates May not have access to modify the original source code Polymorphism 13 Introduction to C++ Object-oriented programming(con t) Inheritance Terminology Class one above Parent class, Super class Class one below Child class Class one or more above Ancestor class, Base class Class one or more below Descendent class vehicle Truck Van Sedan SUV 14

8 Introduction to C++ Object-oriented programming(con t) Polymorphism to hide many implementations behind the same interface DrawRect(p1,p2) DrawHexagon(p1,p2,p3,p4,p5,p6) DrawChart DrawEllipse(p1, p2, r1, r2) DrawTriangle(p1,p2,p3) DrawCircle(p, r) DrawPentagon(p1,p2,p3,p4,p5) 15 Introduction to C++ The character of C++ Class A class is a user-defined data type Object A object is a variable of a class type Message Interacting between objects Functions/Operators overloading int print( char *s ); // Print a string. int print( double dvalue ); // Print a double. int print( double dvalue, int prec ); // Print a double with a given precision. 16

9 Template Introduction to C++ The character of C++(con t) implementation of algorithm abstraction // min for ints int min( int a, int b ) return ( a < b )? a : b; // min for longs long min( long a, long b ) return ( a < b )? a : b; template <class T> T min( T a, T b ) return ( a < b )? a : b; // min for chars char min( char a, char b ) return ( a < b )? a : b; Templates can significantly reduce source code size and increase code flexibility without reducing type safety. 17 Namespace Introduction to C++ The character of C++(con t) to accommodate more reuse of class and function names // one.h char func(char); class String {... }; // two.h class String {... }; {... String();// Which one?... } // one.h namespace one { char func(char); class String {... }; } // two.h namespace two { class String {... }; } one::string() and two::string() 18

10 Introduction to C++ The character of C++(con t) Exception handling try { buf = new char[512]; if( buf == 0 ) throw "Memory allocation failure!"; } catch( char * str ) { cout << "Exception raised: " << str << '\n'; } Memory management // Allocate on the heap char* mychararray = new char[buff_size]; int* myintarray = new int[buff_size];... delete [] mychararray; delete [] myintarray; 19 Introduction to C++ C++ Terminology Functions Procedures Methods Functions Subprograms C++ Program main() function Others the same as most other programming languages 20

11 Introduction to C++ A Sample C++ Program Program #include <iostream> using namespace std; int main( ) { int numberoflanguages; cout << "Hello reader.\n" << "Welcome to C++.\n"; console Input/Output namespace std main() int void main() numberoflanguages console cout << "How many programming languages have you used? "; cin >> numberoflanguages; if (numberoflanguages < 1) cout << "Read the preface. You may prefer\n" << "a more elementary book by the same author.\n"; else cout << "Enjoy the book.\n"; If else return 0; } 0 21 Results Introduction to C++ A Sample C++ Program(con t) 22

12 Introduction to C++ A Sample C++ Program(con t) 23 Session Summary Origins of the C++ language Object-oriented programming The character of C++ C++ Terminology A sample C++ Program 24

13 Variables, Expressions, and Assignment Statements Identifiers Variables Assignment Statements More Assignment Statements Assignment Compatibility Literals Escape Sequences Naming Constants 25 Variables, Expressions, and Arithmetic Operators and Expressions Integer and Floating-Point Division Type Casting Increment and Decrement Operators 26

14 Variables, Expressions, and Identifier The name of a variable (or other item you may define in a program) Starts with a letter or a underscore The rest of the characters must be letters, digits, or underscore symbol. Letter Underscore 27 Letter Underscore Digit Variables, Expressions, and Valid Identifiers x x1 x_1 _abc ABC123z7 sum RATE count data2 bigbonus Invalid Identifiers 12 3X %change data-1 myfirst.c PROG.CPP Case Sensitive rate RATE Rate 28

15 Variables, Expressions, and Comments for Identifiers System Identifiers Standard Libraries W1 W2 W3 lowercase lowercase lowercase uppercase uppercase topspeed, bankrate1, bankrate2, timeofarrival The length of an Identifier depends on compiler 29 Variables, Expressions, and Keywords (Appendix I) and Reserved Words 30

16 Variables, Expressions, and Variables Must be declared before it can be used It s better to declared variables at just before they are used or start of a block { Declaration examples int numberofbeans; double oneweight, totalweight; Name Any legal Identifiers 31 Variables, Expressions, and Simple Data Types (Display 1.2) Type Storage Speed Precision unsigned char, short, int, long String Pointer, Array, Classes will be discussed later. 32?

17 Variables, Expressions, and 33 Variables, Expressions, and Use meaningful names x = y * z; distance = speed * time; 34

18 Variables, Expressions, and Assignment Statements to change the value of a variable Lvalue Rvalue 35 Variables, Expressions, and Assignment statements can be used as an expression n=(m=2); The sub-expression (m=2) changes the value of m to 2 and returns the value 2. n=(m=2); equals to n=m=2; Not to use assignment statement as an subexpression to avoid mistakes as follows n=m=2; n=m+2; 36

19 Variables, Expressions, and Uninitialized variable uninitialized desirednumber = minimumnumber + 10; Variable Initialization Garbage value inside Before variables are used In declarations int minimumnumber = 3; double rate = 0.07, time, balance=0.00; double rate(0.07), time, balance(0.00); 37 Variables, Expressions, and 38

20 Variables, Expressions, and More Assignment Statements Variable Operator= Expression; Variable = Variable Operator (Expression); 39 Variables, Expressions, and Assignment Compatibility double to int int intvariable; intvariable = 2.99; double int type mismatch The result depends on compiler Some will issue an error Some will give intvariable the int value 2 40

21 Variables, Expressions, and int to double double doublevariable; doublevariable = 2; int doublevariable=2.0; 41 Variables, Expressions, and char to int int to char char is treated as small integer 42

22 Variables, Expressions, and int intvariable; bool boolvariable; integer to bool boolvariable=intvariable; if intvariable 0 then boolvariable is true else boolvariable is false intvariable=boolvariable if boolvariable is true then intvariable is 1 else intvariable is 0; 43 Variables, Expressions, and Comment Do not place a value of one type in a variable of another type. 44

23 Literals Variables, Expressions, and Considered constants : can t change in program Literal constant int 2, 3, 156 Literal constant double floating-point notation: 2.99, 3.45 Scientific notation: 3.67e17, 2.34E5, 3.49e e17= E5= e-2= Variables, Expressions, and Literal constant char char symbol = Z Literal constant string cout << How many programming language... ; Literal constant bool true false 46

24 Example for retrieving DOS Parameters #include <iostream> using namespace std; int main(int argc, char **argv) { int i; if (argc>0) { cout << "Number of Parameters = " << argc << "\n"; } for (i=0;i<argc;i++) { cout << "Parameter["<< i <<"]=" << argv[i] << "\n"; } } return(0); 47 Example for retrieving DOS Parameters 48

25 Example for retrieving DOS Parameters useful functions int atoi(char *string) float atof(char* string) 49 Variables, Expressions, and Escape Sequences 50

26 Example for escape sequences 51 Example for escape sequences 52

27 Variables, Expressions, and Naming constants Naming your constants Literal constants are OK, but provide little meaning e.g.:seeing 10 in a program, tells nothing about what it represents int BRANCH_COUNT = 10; int WINDOW_COUNT = 10; To avoid values of such variables are changed const int BRANCH_COUNT = 10; const int WINDOW_COUNT = 10; const int BRANCH_COUNT = 10, WINDOW_COUNT = 10; is often called a modifier 53 declared constant Variables, Expressions, and 54

28 Variables, Expressions, and 55 Variables, Expressions, and Arithemetic Operators and Expressions Precedence rules x+y*z=? 56

29 Variables, Expressions, and 57 Variables, Expressions, and 58

30 Variables, Expressions, and Integer and floating-point division Integer division 10/3 = 3 5/2=2 10%3=1 cout << 17 divided by 5 is << (17/5) << \n ; cout << with a remainder of << (17%5) << \n ; output 17 divided by 5 is 3 with a remainder of 2 negative values? 59 Variables, Expressions, and int totalprice1, totalprice2; totalprice1 = 5000 * (feet/5280.0); totalprice2 = 5000 * (feet/5280); if feet=10000; totalprice1=? totalprice2=? 60

31 Variables, Expressions, and totalprice1=5000* /5280.0=9469; totalprice2=10000*10000/5280=10000; 61 Variables, Expressions, and Type Casting totalprice1 = 5000 * (feet/5280.0); double totalprice2 = 5000 * (feet/5280); int Casting for Variables Can add.0 to literals to force precision arithmetic, but what about variables? 62

32 Variables, Expressions, and Static cast double ans = n/static_cast<double>(m); static_cast<double> is like a function that returns an equivalent value of type double static_cast<int>(2.9) is 2 63 Variables, Expressions, and Four kinds of type cast static_cast<type>(expression) Expression const_cast<type>(expression) const dynamic_cast<type>(expression) reinterpret_cast <Type>(Expression) depends on compiler 64

33 Variables, Expressions, and Type coercion ( ) double d = 5; double d=5.0; 65 Variables, Expressions, and Increment and decrement operators Example1 int n=1, m=7; n++; cout << The value of n is changed to << n << \n m--; cout << The value of m is changed to << m << \n ; Output The value of n is changed to 2 The value of m is changed to 6 66

34 Variables, Expressions, and Example2 int n=2; int valueproduced = 2*(n++); cout << valueproduced << \n cout << n << \n ; Output Variables, Expressions, and Example3 int n=2; int valueproduced = 2*(++n); cout << valueproduced << \n cout << n << \n ; Output

35 Variables, Expressions, and Example4 int n=8; int valueproduced = n--; cout << valueproduced << \n cout << n << \n ; Output Variables, Expressions, and Example5 int n=8; int valueproduced = --n; cout << valueproduced << \n cout << n << \n ; Output

36 Variables, Expressions, and Example6 int n=2; int valueproduced = n+ (++n); cout << valueproduced << \n cout << n << \n ; depends on compiler 71 Session Summary Identifiers Variables Assignment Statements More Assignment Statements Assignment Compatibility Literals Escape Sequences Naming Constants 72

37 Session Summary(con t) Arithmetic Operators and Expressions Integer and Floating-Point Division Type Casting Increment and Decrement Operators 73 Console Input/Output Output using cout New lines in output Formatting for numbers with a decimal point Output with cerr Input using cin 74

38 Console Input/Output(con t) I/O objects cin, cout, cerr Defined in the C++ library called <iostream> Must have these lines (called pre-processor directives) near start of file: #include <iostream> using namespace std; Tells C++ to use appropriate library so we can use the I/O objects cin, cout, cerr 75 Console Input/Output(con t) Output using cout What can be outputted? Any data can be outputted to display screen Variables Constants Literals Expressions (which can include all of above) cout << numberofgames << games played. ; 2 values are outputted: value of variable numberofgames, literal string games played. Cascading: multiple values in one cout << is called insertion operation 76

39 Console Input/Output(con t) Example 1 cout << Hello reader.\n << Welcome to C++.\n ; Example 2 cout << numberofgames << games played. ; Example 3 cout << numberofgames; cout << hames played. ; 77 Console Input/Output(con t) Example 4 cout << The total cost is $ << (price + tax); Example 5 cout << firstnumber << << secondnumber; 78

40 Console Input/Output(con t) New Lines in Output New lines in output \n is escape sequence for the char newline A second : endl Examples: cout << Fuel efficiency is << mpg << miles per gallon\n ; cout << you entered << number << endl; End each program with \n or endl 79 Console Input/Output(con t) Formatting Output Formatting numeric values for output Values may not display as you d expect! cout << The price is $ << price << endl; If price (declared double) has value 78.5, you might get: The price is $ or: The price is $78.5 We must explicitly tell C++ how to output numbers in our programs! 80

41 Console Input/Output(con t) Magic Formula to force decimal sizes: cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); These statements force all future cout ed values: To have exactly two digits after the decimal place Example: cout << The price is $ << price << endl; Now results in the following: The price is $ Console Input/Output(con t) Output with cerr cerr works same as cout Provides mechanism for distinguishing between regular output and error output Re-direct output streams Most systems allow cout and cerr to be redirected to other devices e.g.: line printer, output file, error console, etc. 82

42 Console Input/Output(con t) Input using cin cin for input, cout for output Differences: >> (extraction operator) points opposite Think of it as pointing toward where the data goes Object name cin used instead of cout No literals allowed for cin Must input to a variable you can read in integers, floating-point numbers, or characters 83 Console Input/Output(con t) cin >> num; Waits on-screen for keyboard entry Value entered at keyboard is assigned to num Prompting for Input cout << Enter the number of dragons\n << followed by the number of trolls.\n ; cin >> dragons >> trolls; cin >> dragons >> trolls; 84

43 Console Input/Output(con t) Line breaks in I/O cout << Enter the cost per person : $ ; cin >> costperperson; output Enter the cost per person : $ Enter the cost per person : $ Session Summary Output using cout New lines in output Formatting for numbers with a decimal point Output with cerr Input using cin 86

44 Program Style Bottom-line: Make programs easy to read and modify Comments, two s: // Two slashes indicate entire line is to be ignored /*Delimiters indicates everything between is ignored*/ Both s commonly used Identifier naming ALL_CAPS for constants lowertoupper for variables Most important: MEANINGFUL NAMES! 87 Libraries and Namespaces Libraries and include Directives C++ Standard Libraries #include <Library_Name> Directive to add contents of library file to your program Called preprocessor directive Executes before compiler, and simply copies library file into your program file C++ has many libraries Input/output, math, strings, etc. Some libraries functions are listed in Appendix 4 88

45 Libraries and Namespaces(con t) Namespaces Namespaces defined: Collection of name definitions For now: interested in namespace std Has all standard library definitions we need Examples: #include <iostream> using namespace std; Includes entire standard library of name definitions 89 Libraries and Namespaces(con t) #include <iostream> using std::cin; using std::cout; using std:endl; Can specify just the objects we want 90

46 Chapter Summary C++ is case-sensitive Use meaningful names For variables and constants Variables must be declared before use Should also be initialized Use care in numeric manipulation Precision, parentheses, order of operations #include C++ libraries as needed 91 Chapter Summary(con t) Object cout Used for console output Object cin Used for console input Object cerr Used for error messages Use comments to aid understanding of your program Do not overcomment 92

47 !:op1 Input * p op1 op2 Output cin cout Due date: 2005/3/29 93 r:op1 p:op1 op2

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++ Ubuntu You will develop your course projects in C++ under Ubuntu Linux. If your home computer or laptop is running under Windows, an easy and painless way of installing Ubuntu is Wubi: http://www.ubuntu.com/download/desktop/windowsinstaller

More information

Sequential Program Execution

Sequential Program Execution Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

More information

Computer Programming C++ Classes and Objects 15 th Lecture

Computer Programming C++ Classes and Objects 15 th Lecture Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

Syllabus OBJECT ORIENTED PROGRAMMING C++

Syllabus OBJECT ORIENTED PROGRAMMING C++ 1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

More information

Objective-C Tutorial

Objective-C Tutorial Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

A brief introduction to C++ and Interfacing with Excel

A brief introduction to C++ and Interfacing with Excel A brief introduction to C++ and Interfacing with Excel ANDREW L. HAZEL School of Mathematics, The University of Manchester Oxford Road, Manchester, M13 9PL, UK CONTENTS 1 Contents 1 Introduction 3 1.1

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Introduction to Visual C++.NET Programming. Using.NET Environment

Introduction to Visual C++.NET Programming. Using.NET Environment ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start

More information

Ch 7-1. Object-Oriented Programming and Classes

Ch 7-1. Object-Oriented Programming and Classes 2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

More information

Curriculum Map. Discipline: Computer Science Course: C++

Curriculum Map. Discipline: Computer Science Course: C++ Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

Formatting Numbers with C++ Output Streams

Formatting Numbers with C++ Output Streams Formatting Numbers with C++ Output Streams David Kieras, EECS Dept., Univ. of Michigan Revised for EECS 381, Winter 2004. Using the output operator with C++ streams is generally easy as pie, with the only

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

Lesson Name: Introduction of OOP

Lesson Name: Introduction of OOP Paper Code: Lesson no: 1 Author: Pooja Chawla Paper Name: OOP with C++ Lesson Name: Introduction of OOP Vetter: Prof. Dharminder Kumar Unit Structure: 1.1 Software crisis 1.2 Software Evaluation 1.3 POP

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

Syllabus for CS 134 Java Programming

Syllabus for CS 134 Java Programming - Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

Basic Programming and PC Skills: Basic Programming and PC Skills:

Basic Programming and PC Skills: Basic Programming and PC Skills: Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of

More information

1992-2010 by Pearson Education, Inc. All Rights Reserved.

1992-2010 by Pearson Education, Inc. All Rights Reserved. Key benefit of object-oriented programming is that the software is more understandable better organized and easier to maintain, modify and debug Significant because perhaps as much as 80 percent of software

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,

More information

Some Scanner Class Methods

Some Scanner Class Methods Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Specialized Programme on Web Application Development using Open Source Tools

Specialized Programme on Web Application Development using Open Source Tools Specialized Programme on Web Application Development using Open Source Tools Objective: At the end of the course, Students will be able to: Understand various open source tools(programming tools and databases)

More information

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Course notes Standard C++ programming

Course notes Standard C++ programming Department of Cybernetics The University of Reading SE2B2 Further Computer Systems Course notes Standard C++ programming by Dr Virginie F. Ruiz November, 03 CREATING AND USING A COPY CONSTRUCTOR... 27

More information

Subject Name: Object Oriented Programming in C++ Subject Code: 2140705

Subject Name: Object Oriented Programming in C++ Subject Code: 2140705 Faculties: L.J. Institute of Engineering & Technology Semester: IV (2016) Subject Name: Object Oriented Programming in C++ Subject Code: 21405 Sr No UNIT - 1 : CONCEPTS OF OOCP Topics -Introduction OOCP,

More information

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11. The C++11 CORBA Implementation CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

More information

CSC230 Getting Starting in C. Tyler Bletsch

CSC230 Getting Starting in C. Tyler Bletsch CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly

More information

Logging. Working with the POCO logging framework.

Logging. Working with the POCO logging framework. Logging Working with the POCO logging framework. Overview > Messages, Loggers and Channels > Formatting > Performance Considerations Logging Architecture Message Logger Channel Log File Logging Architecture

More information

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output CSCE 110 Programming Basics of Python: Variables, Expressions, and nput/output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Python Python was developed

More information

Outline Basic concepts of Python language

Outline Basic concepts of Python language Data structures: lists, tuples, sets, dictionaries Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string" Conversion between types int(-2.8)

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):

More information

CS 103 Lab Linux and Virtual Machines

CS 103 Lab Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) (Revised from http://msdn.microsoft.com/en-us/library/bb384842.aspx) * Keep this information to

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science I. Basic Course Information RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE CISY 105 Foundations of Computer Science A. Course Number and Title: CISY-105, Foundations of Computer Science B. New

More information

Accelerated C++ Practical Programming by Example

Accelerated C++ Practical Programming by Example Accelerated C++ Practical Programming by Example by Andrew Koenig and Barbara E. Moo Addison-Wesley, 2000 ISBN 0-201-70353-X Pages 336 Second Printing Table of Contents Contents Chapter 0 Getting started

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Brent A. Perdue. July 15, 2009

Brent A. Perdue. July 15, 2009 Title Page Object-Oriented Programming, Writing Classes, and Creating Libraries and Applications Brent A. Perdue ROOT @ TUNL July 15, 2009 B. A. Perdue (TUNL) OOP, Classes, Libraries, Applications July

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Project 2: Bejeweled

Project 2: Bejeweled Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information