CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1
|
|
- Norah Price
- 6 years ago
- Views:
Transcription
1 CS150 Intro to CS I Fall 2017 Fall 2017 CS150 - Intro to CS I 1
2 Character Arrays Reading: pp Fall 2017 CS150 - Intro to CS I 2
3 char Arrays Character arrays can be used as special arrays called C-strings A C-string is just a character array with a null (\0) character added at the end All string literals are stored as C-strings Fall 2017 CS150 - Intro to CS I 3
4 Example const int size = 11; char name[size] = "Jasmine"; J a s m i' n e \0 Fall 2017 CS150 - Intro to CS I 4
5 Example const int size = 21; char name[size]; cout << "enter a name:"; cin >> name; cout << name << endl; Fall 2017 CS150 - Intro to CS I 5
6 Library Functions There are many library functions for manipulating and testing C-strings: strlen strcmp strcpy And many others Fall 2017 CS150 - Intro to CS I 6
7 Example const int size = 21; char name[size]; int length; cout << "enter a name:"; cin >> name; cout << name << endl; length = strlen(name); cout << "Length is: " << length << endl; Fall 2017 CS150 - Intro to CS I 7
8 Using const as Array Parameters Page 412 Arrays are by default passed-by-reference Sometimes though, you don t want a function to modify the contents of the array Solution: Pass the array as a constant Fall 2017 CS150 - Intro to CS I 8
9 Example void showvalues(const int nums[], int size) { for (int i = 0; i < size; i++) { cout << nums[i] << endl; } cout << endl; } Fall 2017 CS150 - Intro to CS I 9
10 Passing File Objects to Functions Pages File stream objects must always be passed to functions by reference bool openfile(ifstream &infile, string name) Fall 2017 CS150 - Intro to CS I 10
11 Practice Write a program that will ask the user for a file name and open that file. The program then needs to a word from the file and then return the number of vowels in that word. The program must use the functions on the following slide. Fall 2017 CS150 - Intro to CS I 11
12 Example bool openfile(ifstream &infile, string name); void getword(ifstream &infile, char word[]); int countvowels(const char word[]); Fall 2017 CS150 - Intro to CS I 12
13 Working With Characters Special functions exist for working with characters Remember, cin >> ch; reads a single character into ch skipping any whitespace What is whitespace again? Fall 2017 CS150 - Intro to CS I 13
14 cin.get () Sometime we want to read the whitespace! The cin object has a function called get that gets a single character (including whitespace) from the keyboard char ch; cout << "Enter a character: "; cin.get (ch); cout << "Character is: " << ch << endl; Fall 2017 CS150 - Intro to CS I 14
15 cin.get () The following three program segments are equivalent for inputting a single character char ch; // segment #1 cout << "Enter a character: "; cin.get (ch); cout << "Character is: " << ch << endl; char ch; // segment #2 cout << "Enter a character: "; ch = cin.get (); cout << "Character is: " << ch << endl; char ch; // segment #3 cout << "Enter a character: "; // NOT REALLY EQUIVALENT cin >> ch; // IGNORES WHITESPACE cout << "Character is: " << ch << endl; Fall 2017 CS150 - Intro to CS I 15
16 Practice What is output for each of the segments below assuming A B C (not ABC)is entered from the keyboard. char ch1, ch2; // segment #1 cout << "Enter: "; cin.get (ch1); cin.get (ch2); cout << "Characters: " << ch1 << ch2 << endl; char ch1, ch2; // segment #2 cout << "Enter: "; cin >> ch1 >> ch2; cout << "Characters: " << ch1 << ch2 << endl; Fall 2017 CS150 - Intro to CS I 16
17 Processing a Line of Text We can use cin.get() to process an entire line of text including whitespace. What happens if is entered followed by a return? char ch; int count = 0; cout << "Enter a line of text: "; cin.get (ch); while ('\n'!= ch) { ++count; cin.get (ch); } cout << "Number of characters is: " << count << endl; Fall 2017 CS150 - Intro to CS I 17
18 cin.peek() char peek(); Look at the next available character but don t remove that character from the stream char nextchar; int intvalue = -1; string textstring = "text"; nextchar = cin.peek(); if (isdigit(nextchar) ) { // you read a digit! cin >> intvalue; } else { cin >> textstring; } cout << intvalue << endl; cout << textstring << endl; Fall 2017 CS150 - Intro to CS I 18
19 Reading characters from files Remember, an ifstream object works similarly to cin; // attempt to read character readchar = inputfile.get (); // make sure we read a character while (!inputfile.eof ()) { // process character cout << ">" << readchar << "<"; Note:.eof() is only true after we tried and failed to read from the file! } // attempt to read character again. readchar = inputfile.get (); Fall 2017 CS150 - Intro to CS I 19
20 Practice Remember, an ifstream object works similarly to cin; Write a C++ program segment to print the number of lines in the file paragraph.txt Fall 2017 CS150 - Intro to CS I 20
More File Operations. Lecture 17 COP 3014 Spring april 18, 2018
More File Operations Lecture 17 COP 3014 Spring 2018 april 18, 2018 eof() member function A useful member function of the input stream classes is eof() Stands for end of file Returns a bool value, answering
More informationStrings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationCharacters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++
Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and
More informationwhile for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)
Week 7: Advanced Loops while Loops in C++ (review) while (expression) may be a compound (a block: {s) Gaddis: 5.7-12 CS 1428 Fall 2015 Jill Seaman 1 for if expression is true, is executed, repeat equivalent
More informationThe C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.
The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++
More informationClass 14. Input File Streams. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)
Class 14 Input File Streams A program that reads 10 integers from a file int main() { string filename; // the name of the file to be opened ifstream fin; // the input file stream int array[10]; // an array
More informationSoftware Design & Programming I
Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction
More informationFile I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents
File I/O 1 File Names and Types A file name should reflect its contents Payroll.dat Students.txt Grades.txt A file s extension indicates the kind of data the file holds.dat,.txt general program input or
More informationCPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)
Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow
More informationCPE Summer 2015 Exam I (150 pts) June 18, 2015
Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one
More informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More information3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity
Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More information1 Pointer Concepts. 1.1 Pointer Examples
1 1 Pointer Concepts What are pointers? How are they used? Point to a memory location. Call by reference is based on pointers. Operators: & Address operator * Dereferencing operator Machine/compiler dependencies
More informationCh 6-8. C-Strings. April 30, Prof. Young-Tak Kim
2014-1 Ch 6-8. C-Strings April 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742
More informationEngineering Problem Solving with C++, Etter
Engineering Problem Solving with C++, Etter Chapter 6 Strings 11-30-12 1 One Dimensional Arrays Character Strings The string Class. 2 C style strings functions defined in cstring CHARACTER STRINGS 3 C
More informationI/O Streams and Standard I/O Devices (cont d.)
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 from the standard input device Learn how to use predefined
More informationWeek 3: File I/O and Formatting 3.7 Formatting Output
Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits
More informationCSc Introduc/on to Compu/ng. Lecture 17 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 17 Edgardo Molina Fall 2011 City College of New York 22 NOTE ABOUT BOOK Some example show function prototypes inside of the main() function THIS IS WRONG; DON
More informationNote 11/13/2014. They are like those i s, j s, and temp s that appear and disappear when the function starts and finishes...
CISC 2000 Computer Science II Fall, 2014 Note 11/13/2014 1 Review of operator overloading (a) Lab class: take-away ############################ # Pass-by-value parameters # ############################
More informationString Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings
String Class in C++ The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard
More informationChapter 3 - Notes Input/Output
Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:
More informationToday in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1
Today in CS162 External Files What is an external file? How do we save data in a file? CS162 External Data Files 1 External Files So far, all of our programs have used main memory to temporarily store
More informationName. CPTR246 Spring '17 (100 total points) Exam 2
Name CPTR246 Spring '17 (100 total points) Exam 2 1. Pointer parameters (the old C way) In the following program, make all of the changes to convert the call-by-reference parameters in the function computeoptions
More informationCopyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Slide 7-1 Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Type Conversation / Casting Name Constant - const, #define X When You Mix Apples and Oranges: Type Conversion Operations
More informationC++ For Science and Engineering Lecture 12
C++ For Science and Engineering Lecture 12 John Chrispell Tulane University Monday September 20, 2010 Comparing C-Style strings Note the following listing dosn t do what you probably think it does (assuming
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationCS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1
CS150 Intro to CS I Fall 2017 Fall 2017 CS150 - Intro to CS I 1 Chapter 4 Making Decisions Reading: Chapter 3 (3.5 pp. 101), Chapter 4 (4.4 pp. 166-168; 4.5 pp. 169-175; 4.6 pp.176-181; 4.8 pp. 182-189;
More informationC++ Input/Output: Streams
C++ Input/Output: Streams Basic I/O 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:
More informationC++ Final Exam 2017/2018
1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationStructured Types. 8. Arrays. collection of components whose organization is characterized by method used to access individual components.
Structured Types 1 Structured data type: collection of components whose organization is characterized by method used to access individual components. Examples of structured types in C++ array struct union
More informationCS 103 Lab - Party Like A Char Star
1 Introduction In this lab you will implement a "hangman" game where the user is shown blanks representing letter of a word and then tries to guess and fill in the letters with a limited number of guesses.
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationText File I/O. #include <iostream> #include <fstream> using namespace std; int main() {
Text File I/O We can use essentially the same techniques we ve been using to input from the keyboard and output to the screen and just apply them to files instead. If you want to prepare input data ahead,
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationOverview of Lecture. 1 Overloading I/O Operators. 2 Overloading << and >> for Fractions. 3 Formatted vs Unformatted Input
Overview of Lecture 1 Overloading I/O Operators 2 Overloading > for Fractions 3 Formatted vs Unformatted Input 4 Setting the State of a Stream 5 Questions PIC 10B Streams, Part II April 20, 2016
More informationProgramming Abstractions
Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics ADTs Stack Example: Reverse-Polish Notation calculator Queue Example: Mouse Events Stacks New ADT: Stack stack.h template
More informationBuilt-in Functions for NTCAs.
Built-in Functions for NTCAs strlen char array[10] = Hello ; int length = strlen(array); cout
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationIn this chapter, you will learn about: An Array Type for Strings. The Standard string Class. Vectors. Introduction Computer Science 1 CS 23021
Chapter 8 In this chapter, you will learn about: An Array Type for Strings The Standard string Class Vectors The C Language Representation of Strings (C-Strings) The C-String Variable: Array of Characters
More informationCS 115 Exam 3, Spring 2010
Your name: Rules You must briefly explain your answers to receive partial credit. When a snippet of code is given to you, you can assume o that the code is enclosed within some function, even if no function
More informationReading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary
Reading from and Writing to Files Section 3.12 & 13.1 & 13.5 11/3/08 CS150 Introduction to Computer Science 1 1 Files (3.12) Data stored in variables is temporary We will learn how to write programs that
More informationEE 355 Lab 4 - Party Like A Char Star
1 Introduction In this lab you will implement a "hangman" game where the user is shown blanks representing letter of a word and then tries to guess and fill in the letters with a limited number of guesses
More informationAbstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles
Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationOutline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.
Outline Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples. 1 Arrays I Array One type of data structures. Consecutive group of memory locations
More informationToday in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable
Today in CS161 Lecture #12 Arrays Learning about arrays Being able to store more than one item using a variable Examples Tic Tac Toe board as an array Graphical User interaction for the tic tac toe program
More informationPiyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class
C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams
More informationTEST 1 CS 1410 Intro. To Computer Science Name KEY. October 13, 2010 Fall 2010
TEST 1 CS 1410 Intro. To Computer Science Name KEY October 13, 2010 Fall 2010 Part I: Circle one answer only. (2 points each) 1. The decimal representation of binary number 11011 2 is a) 19 10 b) 29 10
More information! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated
More informationCS 103 Lab 6 - Party Like A Char Star
1 Introduction In this lab you will implement a "hangman" game where the user is shown blanks representing letter of a word and then tries to guess and fill in the letters with a limited number of guesses.
More informationName Section: M/W T/TH Number Definition Matching (8 Points)
Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step
More informationChap 0: Overview. Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used. EECS 268 Programming II 1
Chap 0: Overview Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used EECS 268 Programming II 1 Basics - 1 Comments single line: // multi-line: /* */
More informationCS 247: Software Engineering Principles. ADT Design
CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data
More informationLecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR
1 Statements: A statement in a computer carries out some action. There are three types of statements used in C++; they are expression statement, compound statement and control statement. Expression statement
More informationName Section: M/W T/TH Number Definition Matching (6 Points)
Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control
More informationName. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called
Name CPTR246 Spring '17 (100 total points) Exam 1 Classes and Objects 1. We re going to develop a class to help out Café 1812. Below is the definition for a class called Beverage. The public and private
More informationCh 6. Functions. Example: function calls function
Ch 6. Functions Part 2 CS 1428 Fall 2011 Jill Seaman Lecture 21 1 Example: function calls function void deeper() { cout
More informationCSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array
Lesson Outcomes At the end of this chapter, student should be able to: Define array Understand requirement of array Know how to access elements of an array Write program using array Know how to pass array
More informationBefore we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.
Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172 The lab will be on pointers In compensation, no class on Friday, Jan. 31. 1 Consider the bubble function one more
More informationBITG 1113: Array (Part 2) LECTURE 9
BITG 1113: Array (Part 2) LECTURE 9 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of C-strings (character arrays) 2. Use C-string functions 3. Use
More informationArrays. Week 4. Assylbek Jumagaliyev
Arrays Week 4 Assylbek Jumagaliyev a.jumagaliyev@iitu.kz Introduction Arrays Structures of related data items Static entity (same size throughout program) A few types Pointer-based arrays (C-like) Arrays
More informationModule C++ I/O System Basics
1 Module - 36 C++ I/O System Basics Table of Contents 1. Introduction 2. Stream classes of C++ 3. Predefined Standard Input/Output Streams 4. Functions of class 5. Functions of class
More informationStreams. Rupesh Nasre.
Streams Rupesh Nasre. OOAIA January 2018 I/O Input stream istream cin Defaults to keyboard / stdin Output stream ostream cout std::string name; std::cout > name; std::cout
More informationCMSC 202 Midterm Exam 1 Fall 2015
1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.
More informationTHE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)
THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in
More informationIntroduction to Programming EC-105. Lecture 2
Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically
More informationDefinition Matching (10 Points)
Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 9. Strings. 國立雲林科技大學資訊工程研究所張傳育 (Chuan Yu Chang ) 博士
Chapter 9 Strings 國立雲林科技大學資訊工程研究所張傳育 (Chuan Yu Chang ) 博士 Office: EB 212 TEL: 05 5342601 ext. 4337 E mail: chuanyu@yuntech.edu.tw HTTP://MIPL.yuntech.edu.tw Copyright 2008 Pearson Addison Wesley. All rights
More informationKingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS
Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 1 ARRAYS Arrays 2 Arrays Structures of related data items Static entity (same size
More informationType Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works
Type Aliases A name may be defined as a synonym for an existing type name. Traditionally, typedef is used for this purpose. In the new standard, an alias declaration can also be used C++11.Thetwoformsareequivalent.
More informationC strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C
C strings (Reek, Ch. 9) 1 Review of strings Sequence of zero or more characters, terminated by NUL (literally, the integer value 0) NUL terminates a string, but isn t part of it important for strlen()
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format
More information120++: a C++ Subset Corresponding to A Project-Based Introduction to C++
120++: a C++ Subset Corresponding to A Project-Based Introduction to C++ Terence Soule and Clinton Jeffery University of Idaho 2 Contents i ii Chapter 1 Reference 1.1 Variables and Types Computer programs
More informationStudy Guide for Test 2
Study Guide for Test 2 Topics: decisions, loops, arrays, c-strings, linux Material Selected from: Chapters 4, 5, 6, 7, 10.1, 10.2, 10.3, 10.4 Examples 14 33 Assignments 4 8 Any syntax errors are unintentional
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More informationCSCI 6610: Intermediate Programming / C Chapter 12 Strings
... 1/26 CSCI 6610: Intermediate Programming / C Chapter 12 Alice E. Fischer February 10, 2016 ... 2/26 Outline The C String Library String Processing in C Compare and Search in C C++ String Functions
More informationCSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100
CSC 126 FINAL EXAMINATION Spring 2011 Version A Name (Last, First) Your Instructor Question # Total Possible 1. 10 Total Received 2. 15 3. 15 4. 10 5. 10 6. 10 7. 10 8. 20 TOTAL 100 Name: Sp 11 Page 2
More informationIntroduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation
Introduction to Algorithms and Data Structures Lecture 6 - Stringing Along - Character and String Manipulation What are Strings? Character data is stored as a numeric code that represents that particular
More informationGetting started with C++ (Part 2)
Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output
More informationCHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad
CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad Outline 1. The if Selection Structure 2. The if/else Selection Structure 3. The switch Multiple-Selection Structure 1. The if Selection
More informationCS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.
CS 31 Discussion 1A, Week 8 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m. Today s focus Pointer Structure Clarifications Pointer A pointer is the memory address of a variable.
More informationDo not turn to the next page until the start of the exam.
Introduction to Programming, PIC10A E. Ryu Fall 2017 Midterm Exam Friday, November 3, 2017 50 minutes, 11 questions, 100 points, 8 pages While we don t expect you will need more space than provided, you
More informationToday in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)
Today in CS161 Week #3 Learn about Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program See example demo programs CS161 Week #3 1 Data Types
More information13 4 Understanding Character Strings
World Headquarters Jones and Bartlett Publishers Jones and Bartlett Publishers Jones and Bartlett Publishers 40 Tall Pine Drive Canada International Sudbury, MA01776 2406 Nikanna Road Barb House, Barb
More informationENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;
Midterm Practice Problems TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 ENJOY! Problem 1 True False Variable names can begin with an alphabet or a digit. True False
More informationCSCE 121 ENGR 112 List of Topics for Exam 1
List of Topics for Exam 1 If statements o How is an if statement constructed? o Does every if need an else? Looping o While loop! What does a while loop look like?! How do you ensure you will not have
More information! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.
Week 1: Introduction to C++ Gaddis: Chapter 2 (excluding 2.1, 2.11, 2.14) CS 1428 Fall 2014 Jill Seaman Literals A literal represents a constant value used in a program statement. Numbers: 0, 34, 3.14159,
More informationCh 8. Searching and Sorting Arrays Part 1. Definitions of Search and Sort
Ch 8. Searching and Sorting Arrays Part 1 CS 2308 Fall 2011 Jill Seaman Lecture 1 1 Definitions of Search and Sort! Search: find an item in an array, return the index to the item, or -1 if not found.!
More informationI/O streams
I/O streams 1-24-2013 I/O streams file I/O end-of-file eof reading in strings Browse the following libraries at cplusplus.com String Library STL: Standard Template Library (vector) IOStream Library HW#2
More informationCOL 100. Minor 2 Exam - Practice
COL 100. Minor 2 Exam - Practice Name: Entry Number: Group: Notes: Total number of questions: 4. Max Marks: 20 All answers should be written on the question paper itself. The last two sheets in the question
More informationCopyright 2003 Pearson Education, Inc. Slide 1
Copyright 2003 Pearson Education, Inc. Slide 1 Chapter 11 Strings and Vectors Created by David Mann, North Idaho College Copyright 2003 Pearson Education, Inc. Slide 2 Overview An Array Type for Strings
More informationcout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];
1 C++ Dynamic Allocation Memory needs were determined before program execution by defining the variables needed. Sometime memory needs of a program can only be determined during runtime, or the memory
More informationChapter 7. Additional Control Structures
Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter
More informationDiscussion 1E. Jie(Jay) Wang Week 10 Dec.2
Discussion 1E Jie(Jay) Wang Week 10 Dec.2 Outline Dynamic memory allocation Class Final Review Dynamic Allocation of Memory Recall int len = 100; double arr[len]; // error! What if I need to compute the
More informationUnit 2: The string class
: class Programming 2 2015-2016 Index 1 characters in C 2 Input / output 3 Conversion between arrays of characters and strings 4 Comparison with arrays of characters 5 characters in C characters in C have
More informationLECTURE 15. String I/O and cstring library
LECTURE 15 String I/O and cstring library RECAP Recall that a C-style string is a character array that ends with the null character. Character literals in single quotes: 'a', '\n', '$ String literals in
More informationChapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:
Chapter 8 Arrays and Strings Objectives In this chapter, you will: Learn about arrays Declare and manipulate data into arrays Learn about array index out of bounds Learn about the restrictions on array
More informationObject Oriented Programming COP3330 / CGS5409
Object Oriented Programming COP3330 / CGS5409 Dynamic Allocation in Classes Review of CStrings Allocate dynamic space with operator new, which returns address of the allocated item. Store in a pointer:
More information