2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
|
|
- Kenneth Short
- 7 years ago
- Views:
Transcription
1 Chapter 2: Introduction to C Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program #include <iostream> using namespace std; int main() { } beginning of function named main beginning of block for main cout << "Hello, there!"; return 0; end of block for main comment preprocessor directive string literal send 0 to operating system which namespace to use output statement Comments: Explain about the program, can appear anywhere, and are ignored by the compiler Directives: commands to the preprocessor to set up your source code for the compiler. using name space: Specifies where the names of the variables, functions, and other entities are declared int main(): the beginning of the main function; The instructions are included within the pair of curly braces. It returns an integer. Note: C++ is case sensitive. Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-3 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-4
2 Special Characters Character Name Meaning // Double slash Beginning of a comment # Pound sign Beginning of preprocessor directive < > Open/close brackets Enclose filename in #include ( ) Open/close parentheses Used when naming a function { } Open/close brace Encloses a group of statements " " Open/close quotation marks Encloses string of characters ; Semicolon End of a programming statement 2.2 The cout Object Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-5 The cout Object The cout Object Represents the standard output stream, which is set to the console in most systems by default Displays output on the computer screen You use the stream insertion operator << to send output to cout: cout << "Programming is fun!"; Can be used to send more than one item to cout: cout << "Hello " << "there!"; Or: cout << "Hello "; cout << "there!"; Both produce the same output as: cout << "Hello there!"; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-7 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-8
3 The cout Object The endl Manipulator What if we need to display something in different lines? This produces one line of output: cout << "Programming is "; cout << "fun!"; cout does not start a new line unless told to do so You can use the endl manipulator to start a new line of output. This will produce two lines of output: cout << "Programming is" << endl; cout << "fun!"; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-9 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-10 The endl Manipulator The endl Manipulator cout << "Programming is" << endl; cout << "fun!"; You do NOT put quotation marks around endl Programming is fun! The last character in endl is a lowercase L, not the number 1. endl This is a lowercase L Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-11 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-12
4 The \n Escape Sequence The \n Escape Sequence You can also use the \n escape sequence to start a new line of output. This will produce two lines of output: cout << "Programming is\n"; cout << "fun!"; cout << "Programming is\n"; cout << "fun!"; Programming is fun! Notice that the \n is INSIDE the string. Do not use forward slash (/n). Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-13 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-14 Common Escape Sequences Escape Sequence Name Description \n Newline Moves the cursor to the beginning of the next line. \t Tab Moves the cursor to the next tab stop. \a Alarm Causes the computer to beep. \b Backspace Moves the cursor left one position. \r Return Moves the cursor to the beginning of current line. \\ Backslash Print a backslash. \ Single quote Print a single quotation mark. \ Double quote Print a double quotation mark. 2.3 The #include Directive Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-15
5 The #include Directive Inserts the contents of another file into the program. #include <iostream> inserts the iostream header file, which contains information about cout and is needed for the compilation of programs using cout object This is a preprocessor directive, not part of C++ language #include lines will not be seen by the compiler Do not place a semicolon at end of #include line 2.4 Variables and Literals Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-17 Variables and Literals The program uses variables to store data and literals to represent data Variable: a storage location in memory Variable Definition Has a name and a type of data it can hold Must be defined before it can be used: int item; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-19 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-20
6 Literals Literal: a value that is written into a program s code. "hello, there" (string literal) 12 (integer literal) "number" (string literal) "12" (string literal) 20 is an integer literal Note: integer 12 is different from string 12. Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-21 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-22 This is also a string literal This is a string literal Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-23 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-24
7 Literals What will the following program segment print out? number = 20; cout << "number = " << "number"; Is the following program segment correct? int grade; grade = "80"; 2.5 Identifiers Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-25 Identifiers C++ Key Words An identifier is a programmer-defined name for some element of a program: variables, functions, etc. You cannot use any of the C++ key words as an identifier. These words have reserved meaning. (total=74) Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-27 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-28
8 Variable Names Identifier Rules A variable name should represent the purpose of the variable. For example, instead of x, use: itemsordered The purpose of this variable is to hold the number of items ordered. The first character of an identifier must be an alphabetic character or an underscore ( _ ), After the first character you may use alphabetic characters, numbers, or underscore characters. Upper- and lowercase characters are distinct Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-29 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-30 Valid and Invalid Identifiers IDENTIFIER VALID? REASON IF INVALID totalsales total_sales total.sales 4thQtrSales totalsale$ Yes Yes No Cannot contain. No Cannot begin with a digit No Cannot contain $ 2.6 Integer Data Types Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-31
9 Integer Data Types Defining Variables There are many different types of data Integer variables can hold whole numbers such as 12, 7, and -99. Size of the integers are dependent on the hardware. For a 32-bit system, the above is true. Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-33 Variables of the same type can be defined - On separate lines: int length; int width; unsigned int area; - On the same line: int length, width; unsigned int area; Variables of different types must be in different definitions Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-34 Integer Literals This program has three variables: checking, miles, and days An integer literal is an integer value that does not contain a decimal point. For example: itemsordered = 15; In this code, 15 is an integer literal. Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-35 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-36
10 Integer Literals Integer Literals Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-37 Integer literals are stored in memory as ints by default To store an integer constant in a long memory location, put L or l at the end of the number: 1234L Constants that begin with 0 (zero) are base 8: 075 Constants that begin with 0x are base 16: 0x75A Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-38 The char Data Type 2.7 The char Data Type Used to hold characters or very small integer values Usually 1 byte of memory Numeric value of character from the character set is stored in memory: CODE: char letter; letter = 'C'; MEMORY: letter Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-40
11 Character Literals Character literals must be enclosed in single quote marks. Example: char ans; ans = 'Y'; ans = "Y"; // correct // wrong Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-41 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-42 Character Strings Character vs. String A series of characters in consecutive memory locations: "Hello" Stored with the null terminator, \0, at the end: 'A' is stored as "A" is stored as A A \0 Comprised of the characters between the " " H e l l o \0 char letter; letter = 'A'; letter = "A"; // This is OK // This will not work Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-43 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-44
12 The string Data Type The string Data Type Allows a sequence of characters to be stored in one memory location Actually a class and not a true data type built into the language Needs to include <string> header file #include <iostream> #include <string> using namespace std; int main() { string stname; stname = Steven Moore ; cout << Welcome << stname << endl; } return 0; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-45 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-46 Floating-Point Data Types 2.8 Floating-Point Data Types Used to define variables that hold real numbers The floating-point data types are: float double long double They can hold real numbers such as: Stored in a form similar to scientific notation: All floating-point numbers are signed Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-48
13 Floating-Point Data Types Floating-point Literals * Some compilers use 10 bytes for long double. Can be represented in two ways Fixed point (decimal) notation: E notation: E1 6.25e-5 Are double by default Can be forced to be float by appending F or f ( f) or long double ( L) Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-49 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The bool Data Type Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-51
14 The bool Data Type Represents binary values that are true or false bool variables are stored as small integers false is represented by 0, true by 1: bool alldone = true; bool finished = false; alldone finished 1 0 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-53 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-54 Determining the Size of a Data Type 2.10 Determining the Size of a Data Type The size of some data type may be different from machine to machine The sizeof operator gives the size of any data type or variable: double amount; cout << "A double is stored in " << sizeof(double) << "bytes\n"; cout << "Variable amount is stored in " << sizeof(amount) << "bytes\n"; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-56
15 Variable Assignments and Initialization 2.11 Variable Assignments and Initialization An assignment statement uses the assignment = operator to store a value in a variable. item = 12; This statement assigns the value 12 to the item variable. Can also assign other data types ans = 'A'; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-58 Assignment Variable Initialization The variable receiving the value must appear on the left side of the = operator. This will NOT work: // ERROR! 12 = item; A variable just defined can have any value To initialize a variable means to assign it a value when it is defined: int length = 12; Can initialize some or all variables: int length = 12, width = 5, area; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-59 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-60
16 Named Constants A named constant represents a value that cannot change while the program is running Declared with keyword const and capital letters Must be initialized when declared For example: const double PI = ; const int WIDTH; const int WIDTH = 10; // ERROR! Must // initializ Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-61 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-62 Scope 2.12 Scope The scope of a variable: the part of the program in which the variable can be used The rules are complex and will be introduced gradually A variable cannot be used before it is defined Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-64
17 2.13 Arithmetic Operators Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-65 Arithmetic Operators Binary Arithmetic Operators Used for performing numeric calculations C++ has unary, binary, and ternary operators: unary (1 operand) -5 binary (2 operands) 13-7 ternary (3 operands) exp1? exp2 : exp3 (Only one in C++, will be covered in Chapter 4) SYMBOL OPERATION EXAMPLE VALUE OF ans + addition ans = 7 + 3; 10 - subtraction ans = 7-3; 4 * multiplication ans = 7 * 3; 21 / division ans = 7 / 3; 2 % modulus ans = 7 % 3; 1 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-67 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-68
18 Assignment Statement A Closer Look at the / Operator Format: Variable = Expression; It evaluates the value of the expression and assign it to the variable int area, radius; radius = 100; area = 3.14 * radius * radius; cout << "Area of the circle is " << area << endl; When an expression is used with cout, its value will be evaluated and the result will be inserted into cout / (division) operator performs integer division if both operands are integers cout << 13 / 5; // displays 2 cout << 91 / 7; // displays 13 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-69 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-70 A Closer Look at the % Operator If either operand is floating point, the result is floating point cout << 13 / 5.0; // displays 2.6 cout << 91.0 / 7; // displays 13.0 % (modulus) operator computes the remainder resulting from integer division cout << 13 % 5; // displays 3 % requires integers for both operands cout << 13 % 5.0; // error Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Comments
19 Comments Single-Line Comments Used to document parts of the program Intended for persons reading the source code of the program: Indicate the purpose of the program Describe the use of variables Explain complex sections of code Are ignored by the compiler Begin with // through to the end of line: int length = 12; // length in inches int width = 15; // width in inches int area; // calculated area // calculate rectangle area area = length * width; Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-73 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-74 Multi-Line Comments Begin with /*, end with */ Can span multiple lines: /* This is the first line of the comment This is the last line of the comment */ 2.15 Programming Style Can begin and end on the same line: int area; /* calculated area */ Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-75
20 Programming Style Programming Style The visual organization of the source code Includes the use of spaces, tabs, and blank lines Does not affect the syntax of the program Affects the look and readability of the source code Common elements to improve readability: Braces { } aligned vertically Indentation and alignment of statements within a set of braces int main() { int number; // not indented number = 12; cout << "Number = " << number << endl; return 0; } // not aligned Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-77 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-78 Programming Style Blank lines between variable declaration and other statements Long statements wrapped over multiple lines with aligned operators int fahrenheit=98.7, celsius=37; cout << "The Fahrenheit temperature is " << fahrenheit << " and the Celsius temperature is " << celsius << endl; 2.17 A Programming Example Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-79
21 A Wage Problem The Programming Process The regular work hours per week is 40. Any hours worked over 40 are considered overtime. An employee earns $18.25 / hr. for regular hours, and $27.78 / hr. for overtime hours. The employee worked 50 hours this week. Write a program to calculate and display the employee s total wages for the week. 1. Understand the problem 2. Develop an algorithm for solving the problem 3. Translate the algorithm into a computer language 4. Type the code, save it and compile it 5. Correct any syntax errors found during compilation. Repeat steps 4 and 5 as many times as needed 6. Run the program and check the result with test data 7. Correct any runtime and logical errors found while running the program. Repeat steps 4~7 as many times as needed Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-81 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-82 Algorithm Pseudocode Algorithm An algorithm is a sequence of steps that shows how to solve a problem step by step. For example: Pseudocode algorithm 1. Get data: pay rates & work hours 2. Regular wages = base pay rate regular hours 3. Overtime wages = overtime pay rate overtime hours Driving direction 4. Total wages = regular wages + overtime wages Cooking recipe 5. Display the total wages Directions for installing a device The algorithm needs to be translated into C++ In the beginning of program, define a variable for each value used in the algorithm (How many?) Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-83 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-84
22 Flowchart Start Initialize rates & hours Calculate regular wage Calculate overtime wage Calculate total wage Display total wage Stop Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-85 Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-86
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 informationChapter 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 informationC++ 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 informationTopics. 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 informationSimple 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 informationChapter 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 informationPemrograman 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 informationIntroduction 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 informationJavaScript: 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 informationAppendix 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 informationBachelors 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 informationSources: 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 informationIntroduction 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 informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
More informationHandout 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 informationJavaScript: 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 informationJAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
More informationPROBLEM 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 informationInformatica 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 informationPROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE
PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
More informationMoving 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 informationComp151. 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 informationCSE 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 informationEmbedded 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 informationLab 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 informationJava Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
More informationComputer 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 informationC++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com
C++ Essentials Sharam Hekmat PragSoft Corporation www.pragsoft.com Contents Contents Preface 1. Preliminaries 1 A Simple C++ Program 2 Compiling a Simple C++ Program 3 How C++ Compilation Works 4 Variables
More informationPassing 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 informationC++ 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 informationC++ 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 informationNumber Representation
Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data
More informationPART-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 informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More informationAnswers to Review Questions Chapter 7
Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element
More informationIntroduction 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 informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationAppendix M: Introduction to Microsoft Visual C++ 2010 Express Edition
Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition This book may be ordered from Addison-Wesley in a value pack that includes Microsoft Visual C++ 2010 Express Edition. Visual C++ 2010
More informationC PROGRAMMING FOR MATHEMATICAL COMPUTING
UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions
More informationObjective-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- Hour 1 - Introducing Visual C++ 5
- Hour 1 - Introducing Visual C++ 5 Welcome to Hour 1 of Teach Yourself Visual C++ 5 in 24 Hours! Visual C++ is an exciting subject, and this first hour gets you right into the basic features of the new
More informationIntroduction 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 informationThe 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 informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationPL / 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 informationMoving from C++ to VBA
Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry
More informationVB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
More informationLecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
More informationAbout 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 informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationRetrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.
Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement
More informationLecture 1 Introduction to Java
Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First
More informationProgramming and Data Structures with Java and JUnit. Rick Mercer
Programming and Data Structures with Java and JUnit Rick Mercer ii Chapter Title 1 Program Development 2 Java Fundamentals 3 Objects and JUnit 4 Methods 5 Selection (if- else) 6 Repetition (while and for
More informationSo far we have considered only numeric processing, i.e. processing of numeric data represented
Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate
More informationVisual Logic Instructions and Assignments
Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.
More informationUIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
More informationThe 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 informationStorage 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 informationFirst 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 informationC++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
More informationChapter 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 informationC Language Tutorial. Version 0.042 March, 1999
C Language Tutorial Version 0.042 March, 1999 Original MS-DOS tutorial by Gordon Dodrill, Coronado Enterprises. Moved to Applix by Tim Ward Typed by Karen Ward C programs converted by Tim Ward and Mark
More informationSequential 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 informationCSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions
CSC45 AUTOMATA 2. Finite Automata: Examples and Definitions Finite Automata: Examples and Definitions A finite automaton is a simple type of computer. Itsoutputislimitedto yes to or no. It has very primitive
More informationC++ 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 informationRecognizing PL/SQL Lexical Units. Copyright 2007, Oracle. All rights reserved.
What Will I Learn? In this lesson, you will learn to: List and define the different types of lexical units available in PL/SQL Describe identifiers and identify valid and invalid identifiers in PL/SQL
More informationIntroduction 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 informationUbuntu. 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 informationVISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...
More informationProgramming in Java. 2013 Course Technology, a part of Cengage Learning.
C7934_chapter_java.qxd 12/20/11 12:31 PM Page 1 Programming in Java Online module to accompany Invitation to Computer Science, 6th Edition ISBN-10: 1133190820; ISBN-13: 9781133190820 (Cengage Learning,
More informationExercise 4 Learning Python language fundamentals
Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also
More informationOutline 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 informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Introduction to Electrical and Computer Engineering II Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat
More information9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements
9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending
More informationMultichoice 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 information3.GETTING STARTED WITH ORACLE8i
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
More informationVisual Studio 2008 Express Editions
Visual Studio 2008 Express Editions Visual Studio 2008 Installation Instructions Burning a Visual Studio 2008 Express Editions DVD Download (http://www.microsoft.com/express/download/) the Visual Studio
More informationCS 241 Data Organization Coding Standards
CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input
More informationChapter 3 Operators and Control Flow
Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or
More informationConditions & Boolean Expressions
Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In
More informationCSCE 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 informationPhys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions
Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment
More informationBeyond the Mouse A Short Course on Programming
1 / 22 Beyond the Mouse A Short Course on Programming 2. Fundamental Programming Principles I: Variables and Data Types Ronni Grapenthin Geophysical Institute, University of Alaska Fairbanks September
More informationPerl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl
First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End
More informationC / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu
C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro
More informationSelection Statements
Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:
More informationLecture 2 Notes: Flow of Control
6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The
More informationObject-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 informationChapter 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 informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationBase Conversion written by Cathy Saxton
Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,
More informationEcma/TC39/2013/NN. 4 th Draft ECMA-XXX. 1 st Edition / July 2013. The JSON Data Interchange Format. Reference number ECMA-123:2009
Ecma/TC39/2013/NN 4 th Draft ECMA-XXX 1 st Edition / July 2013 The JSON Data Interchange Format Reference number ECMA-123:2009 Ecma International 2009 COPYRIGHT PROTECTED DOCUMENT Ecma International 2013
More informationNumbering Systems. InThisAppendix...
G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal
More information