(Dreaded) Quiz 2 Next Monday.

Slides:



Advertisements
Similar presentations
Computer Science 1620 Loops.
Advertisements

Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Functions Parameters & Variable Scope Chapter 6. 2 Overview  Using Function Arguments and Parameters  Differences between Value Parameters and Reference.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Semester Review. As we have discussed, Friday we will have in class time for you to work on a program, this program will come with instructions and you.
Fundamental Programming: Fundamental Programming Introduction to C++
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
Quiz 2 Results. What Is Wrong? #include using namespace std int Main() { // Say Hello 4 times for(i == 0; i < 3; i++) { cout >> "Hello World!"
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
(Dreaded) Quiz 2 Next Monday.
The Ohio State University
Introduction to Computer Programming
ifstreams and ofstreams
LESSON 2 Basic of C++.
#define #include<iostream> using namespace std; #define GO
while Repetition Structure
Computing and Statistical Data Analysis Lecture 2
Problems With Character Arrays
Introduction to C++ October 2, 2017.
Copyright © 2003 Pearson Education, Inc.
לולאות קרן כליף.
Quiz Next Monday.
مبانی برنامه‌سازی با C++ جلسه دوم
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Intro to Programming Week # 4 Control Structure Lecture # 8
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Announcements General rules about homeworks
Announcements General rules about homeworks
TIPS: How to Be Successful
Strings A collection of characters taken as a set:
Starting Out with C++: From Control Structures through Objects
Know for Quiz Everything through Last Week and Lab 7
File Review Declare the File Stream Object Name
The for Loop Syntax: Same as: for (expression1;condition; expression2)
Summary Two basic concepts: variables and assignments Basic types:
If Statements.
Chapter 4: Control Structures I (Selection)
Control Structures Part 1
Announcements Homework 1 will be assigned this week,
Jeff West - Quiz Section 4
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Arithmetic Operations
CHAPTER 4 File Processing.
Life is Full of Alternatives
Announcements General rules about homeworks
Using string type variables
ifstreams and ofstreams
Today’s Objectives 28-Jun-2006 Announcements
Programming Strings.
CS31 Discussion 1D Fall18: week 2
Programming Fundamental
Presentation transcript:

(Dreaded) Quiz 2 Next Monday

Strings Revisited string Is a Type in C++ Library <string> May Initialize or Assign with Double Quoted Values May Compare using Equality Operators Can Access Single Characters using Square Bracket Operator ([ ]) Can Use length() Object Function Can Add to String

#include <iostream> #include <string> using namespace std; int main() { string lastname, firstname; cout << "Enter last name: "; cin >> lastname; cout << "Enter first name: "; cin >> firstname; cout << "Your name is " << firstname << " " << lastname << endl; return(0); }

#include <iostream> #include <string> using namespace std; int main() { string lastname, firstname; bool instructor; cout << "Enter last name: "; cin >> lastname; cout << "Enter Firstname: "; cin >> firstname; if (lastname == "hanrath") instructor = true; else instructor = false; return(0); }

#include <iostream> #include <string> using namespace std; int main() { string word = "start"; cout << word << endl; word[0] = 'h'; word[1] = 'e'; return(0); }

#include <iostream> #include <string> using namespace std; int main() { string word = "start"; cout << word << endl; word[0] = 'h'; word[1] = 'e'; cout << "String length is: " << word.length() << endl; return(0); }

#include <iostream> #include <string> using namespace std; int main() { string word = "start"; cout << word << endl; word[0] = 'h'; word[1] = 'e'; cout << "String length is: " << word.length() << endl; word = word + " " + "healthy" + " " + word; return(0); }

More on Input Input Failure Common *MUST* Be Part of Test Plan cin Used for Input If User Enters Bad Type of Data, cin Left in failed state Must Use cin.clear() function to Start Over Must Use cin.ignore() function to Get Beyond Bad Input May Use cin as Condition in if Statement Pages 111-113, 175 in Malik

Input Failure Example #include <iostream> #include <string> using namespace std; int main() { int numEmployees; bool done = false; string garbage; while (!done) cout << "Enter number of employees: "; cin >> numEmployees; if (!cin) //if input stream in failed state cout << "Bad input, try again." << endl; cin.clear(); // changes input state to ok cin.ignore(200,'\n'); // gets beyond bad input characters } else done = true; return(0);

Know for Quiz 2 Everything through Exam 1 while, for, and do-while Loops New string Features Input Failure