I Know What I Want to Do – Now What??

Slides:



Advertisements
Similar presentations
True or false A variable of type char can hold the value 301. ( F )
Advertisements

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
The If/Else Statement, Boolean Flags, and Menus Page 180
Basic Elements of C++ Chapter 2.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Instructor - C. BoyleFall Semester
CONTROLLING PROGRAM FLOW
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
C++ Programming: Basic Elements of C++.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
Chapter 3: Assignment, Formatting, and Interactive Input.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
C/C++ Programming Basics
Programming Fundamentals. Summary of Previous Lectures Phases of C++ Environment Data Types cin and cout.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Bill Tucker Austin Community College COSC 1315
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 3 Selection Statements
Chapter 2: Basic Elements of C++
Introduction to C++ (Extensions to C)
C++ Basic Input and Output (I/O)
Chapter Topics The Basics of a C++ Program Data Types
Basic Elements of C++.
Chapter 2 Assignment and Interactive Input
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Basic Elements of C++ Chapter 2.
CS 2308 Exam I Review.
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Review for Midterm Exam
Chapter 3: Input/Output
Chapter 3 Input output.
Chapter 6: Repetition Statements
Review for Midterm Exam
If Statements.
Chapter 3: Expressions and Interactivity
Review for Midterm Exam
Review for Midterm Exam
Review for Midterm Exam
CS150 Introduction to Computer Science 1
Understanding Conditions
Fundamental Programming
Fundamental Programming
An Introduction to Programming with C++ Fifth Edition
Decisions, decisions, decisions
C++ Programming Basics
COMS 261 Computer Science I
C++ for Engineers and Scientists Second Edition
Programming Fundamental-1
Presentation transcript:

I Know What I Want to Do – Now What?? Ed Brunjes

Data Types

Strings Class as opposed to a data type Collections of characters (as opposed to a single value) Has associated member functions (or methods) for special operations Requires the inclusion of the string header file Example #include <string>

Identifiers- Variables and Constants Syntax – Data_type identifier; Examples – C-syntax Camel style Initialization or assignment – Use of assignment operator (=) – read “gets” Example - int counter = 0; Constants – Use of const type modifier Example - const int max_lines = 25; ________________________________

Interactive Input Standard Output and Input objects Insertion and extraction operators << - Insertion operator >> - Extraction operator Use of member functions (methods) .get() Use of getline() Syntax – getline(cin, string_object)

Data Conversion – newer syntax Often it is necessary to convert data from one type to another type – strings to numbers Look for “to” as a part of the utility name Examples – int stoi(string) double stod(string) string to_string(num_val) string val1 = “123”; string val2 = “10”; cout << stod(val1)*stoi(val2);

Older Conversion Syntax With older compilers conversion was a 2-step process because of the use of standard C utilities – 1. Convert the string into a character array 2. Convert the character array into its number equivalent Example: string val1 = “123”; string val2 = “10”; cout << atof(val1.data()) * atoi(val2.data());

How to Make a Boolean Value Boolean values – no input or output; initialization - they can only be used There are only two values and both require the use of “Boolean operators” to create Relational operators Logical operators (sometimes called logical connectors) The expression is termed an assertion 4. Example: “four is greater than 5”. True of False??

Use of Booleans Initialization – Boolean expression – bool flag = FALSE; int val = 10; Boolean expression – flag = val == 10; flag = val < 10; Use of Boolean values – if(val < 10) cout << “val is less than 10” << endl; else cout << “val is not less than 10” << endl;

Multiple (nested) Decisions Decision within a decision occurs if an outcome is based on the value of two or more variables. Diagram looks something like – if(condition1) if(condition2) statement1; else statement2; statement3; statement4;

Arithmetic Operators

Accumulators vs. Counters Counters add the same value each execution Example - ctr = ctr +1; Accumulators can add different values each execution Example- total = total + number;

Incrementors and Decrementors Post-fixed operators - Prefixed operators -

Manipulating (formatting) input and output Use of iomanip #include <iomanip> Includes definitions for – setprecision(), setw(), fixed Example – cout << setw(35) << "Expected Pay for the Period: " << fixed << setprecision(2) << tot_pay << endl;