Jeff West - Quiz Section 4

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1 Overview 8.1 An Array Type for Strings 8.2 The Standard string.
Advertisements

1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Computer Science 1620 Other Data Types. Quick Review: checklist for performing user input: 1) Be sure variable is declared 2) Prompt the user for input.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Software Engineering 1 (Chap. 1) Object-Centered Design.
1 Today’s Objectives  Announcements Turn in Homework #1 Homework #2 is posted and it is due on 21-Jun  Review Quiz #1  Pointers and C-style strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
CSE 232: C++ Input/Output Manipulation Built-In and Simple User Defined Types in C++ int, long, short, char (signed, integer division) –unsigned versions.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan Snd Term Nouf Aljaffan (C) CSC 1201 Course at KSU1.
C++ Loop Statements Repetition Revisited. Problem Using OCD, design and implement a function that, given a menu, its first valid choice, and its last.
1 CS161 Introduction to Computer Science Topic #3.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
C++ Programming, Namiq Sultan1 Chapter 3 Expressions and Interactivity Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
 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.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 15 Strings as Character Arrays
String as Arrays, Array Sorting C++ Programming Technologies.
11 Introduction to Object Oriented Programming (Continued) Cats.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Bill Tucker Austin Community College COSC 1315
Jeff West - Quiz Section 2
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
The setw Manipulator The setw manipulator causes the number (or string) that follows it in the stream to be printed within a field n characters wide, where.
Command Line Arguments
Chapter 2 Assignment and Interactive Input
Introduction to C++ October 2, 2017.
Multi-dimensional Array
Copyright © 2003 Pearson Education, Inc.
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Random Number Generation
One-Dimensional Array Introduction Lesson xx
Learning Objectives String Class.
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.
TIPS: How to Be Successful
Strings A collection of characters taken as a set:
Starting Out with C++: From Control Structures through Objects
Code::Block vs Visual C++
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Class Examples.
Wednesday 09/23/13.
Chapter 3 Input output.
Computing Fundamentals
Control Structures Part 1
Jeff West - Quiz Section 6
Let’s all Repeat Together
Fundamental Programming
Reading from and Writing to Files
Jeff West - Quiz Section 16
Using string type variables
(Dreaded) Quiz 2 Next Monday.
Strings …again.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
CS31 Discussion 1D Winter19: week 4
Programming Strings.
Dr. Khizar Hayat Associate Prof. of Computer Science
Reading from and Writing to Files
CSE Module 1 A Programming Primer
Programming Fundamental
Jeff West - Quiz Section 3
Presentation transcript:

Jeff West - Quiz Section 4 CSE 143 Section AD Quiz Section 4 6/26/2001 Jeff West - Quiz Section 4

Jeff West - Quiz Section 4 Homework 1 string vs. char[] – C++ strings are a lot easier to use but character arrays (C strings) seem to have a much larger library of functions to use for separating strings, etc. Whenever you make a loop in a program think about how the INITIAL and FINAL cases will operate – many people had loops that were guaranteed to run at least once when certain data might require they never be entered at all. 6/26/2001 Jeff West - Quiz Section 4

Example of a Looping Program Take five minutes to create a function that will prompt a user for their name and a number of times they would like to be greeted, after which it will greet them that many times. Stop as soon as the user inputs “Cindy” as their name and 1 as the number of times they wish to be greeted. NOTE: After Cindy has asked to be greeted 1 time you should NOT greet her, you should just end the function! 6/26/2001 Jeff West - Quiz Section 4

Notes About This Program The user should be prompted for information before the loop decides whether or not it should enter the first time. What should the loop require to be entered? To end? 6/26/2001 Jeff West - Quiz Section 4

A Sample Solution #include <iostream> #include <string> using namespace std; int main() { string currentName; // stores name of current user int numTimes; // stores number of times // current user wishes to be // greeted // prompt user for information cout << "What is your name? "; cin >> currentName;

cout << "How many times should I greet you? "; cin >> numTimes; while(currentName != "Cindy" || numTimes != 1) { for(int i = 0; i < numTimes; i++) cout << "Hello, " << currentName << endl; // prompt user for information cout << "What is your name? "; cin >> currentName; } cout << "Thanks for using The Greeter version 1.0."; return 0;

Jeff West - Quiz Section 4 Classes Classes give us a chance to create our own datatypes that do really neat things! Think of classes as nouns which describe “categories.” Examples might include: * Person * Book * Fraction * Animal * Beverage 6/26/2001 Jeff West - Quiz Section 4

Jeff West - Quiz Section 4 Class Members The way classes do “totally cool things” is by storing and manipulating their own data! As an example, what member functions might a book class have? What data members might it have? * Which members do you think should be private? Which members should be public? * How should the data be initialized? What constructor(s) might you wish to provide? 6/26/2001 Jeff West - Quiz Section 4