Programming in C/C
|
|
- Myron Wilcox
- 5 years ago
- Views:
Transcription
1 Programming in C/C Natalia Silvis-Cividjian Topics about C++ language about this course C++ basics self test exercises (10 min) (10 min) (40 min) (30 min) vrije Universiteit amsterdam 2 About C/C++ language C/C++ vs. Java First there was B. C is developed together with Unix by Kernighan and Ritchie 1970 s First C reference book 1978 (K&R 78) Standard ANSI C (89) C++ is a C descendant, developed by Stroustrup (86) C++ standard by ANSI/ISO (1997 ) C vs. C++ : Any C program is a legal C++ program. C legacy C is a language designed 30 ago for systems programming Advantage: economy of expression, compact code => FAST while (*p++ = *q++) ; ; Disadvantage: too concise for human understanding, lack of runtime checks Java appeared later, in a time of increasing processor speeds and decreasing memory costs. Advantage: SAFE Conclusion: C++ = efficiency of execution vs. Java = safety 3 4 C++ programming methodologies About this course procedural programming (input => processing =>output) object oriented programming (encapsulate data and functions in one class) Cat is a class. Tom, Felix are objects of type Cat Tom.Age = 4 ; generic programming (make functions and classes for any type of the arguments) Example. T max (T left, T right) where T can be any type. The place of this course in the curriculum : Why C++? It is fast and widely used in companies What can we learn during this course? read and process data files create and manipulate dynamic data structures (lists and queues) learn to work with classes learn and experiment with C++ specific features like template libraries 5 6 1
2 About this course How much time we should spend on this course? (2 ECTS = 2 x 28 = 56 hours) Lecture 1. Procedural programming 1 (C/C++ basics) (2 hours) Lecture 2 Procedural programming 2 (pointers and linked lists) (2 hours) Lecture 3 Object oriented programming (2 hours) Lecture 4 Generic programming (2 hours) Total : 8 hours lectures Assignment 1. Bank (8 hours) Assignment 2 AEX (16 hours) Assignment 3 Company (16 hours) Assignment 4 Templates (8hours) Total : 48 hours practicals About this course BOOKS: ** Leen Ammeraal, Basiscursus C++, Academic service,1999 * W. Savitch, Problem solving with C++, Addison Wesley,2005 T. Budd, C++ for Java Programmers, Addison Wesley,1999 S. Lipmann, J. Lajoie, C++ Primer, ATE&T 1998 Liberty Jones, Teach yourself C++ in 21 days, SAMS, 2005 How do we get our 2 ECTS? It is of course useful to attend the lectures. But really important to get your credit points is to deliver in time the 4 assignments. The assignments are found on the course website. 7 8 Procedural programming 1 A simple C++ program //example1.cpp /*Reads 3 numbers from the keyboard, sums the numbers and writes the sum on the screen*/ Explanation comments also comments a simple C++ program C++ data types flow control functions arrays strings input and output #include <iostream> include directive using namespace std; standard namespace int main() main() function int a,b,c ; declaration of variables a,b,c cout << Give 3 integer numbers: "; write to the screen (cout) cin >> a >> b >> c; read from the keyboard (cin) int sum = a + b + c; declare and assign variable sum cout << The sum is : " << sum << endl; return 0; endl inserts a blank line end program here 9 10 How to test a C++ program? How to test a C++ program? Under Unix:g++ is the GNU C/C++ compiler under Unix. Compile : g++ example1.cpp Run: a.out The default executable is named a.out Compile and specify another name for the executable : g++ example1.cpp o example.exe Run: example.exe Under Windows: C++ Visual : Compile - Build - Execute Details in the practical guide on the course website
3 I L L C++ Data types!" #"$ % "!& '"(! )*)+ +!,.- $/ "$((! $ +(!2 - " & :; 67$8 98<+= 3!4 >$ 9?? 6?< *+ + " 3 " " "( 3& + + / > + A +! = 2 B) =(C5$ 0! "$( 3+ " D = (C+ +$E 3@ + F G = 5" " " " "/ & + " "+ 0 3 " "2 struct Date int month; int day; int year ; struct PersonInfo double height ; int age ; Date birthday ; Flow control If - else Switch - break While Do-while For loop goto see book Ammeraal Arrays " " + D + 4?< J/ + 3 +!" + " 0! 0K " #"2 ( D M < +$ 4 N< - " A" + D $ 3 4 6< OE 7@?@ M6 FPJ QSRT UVW XX!YZ [U\]RU^ ^ R^Z _Z ]` U az \ RbTR_^ c] Y U)d - 3'3 #" "& $D +$ e4 6<)J - 3' #" "& " & + (" " "$( +"! = + $D"33/ + 4 6< 2 J " f" & + ( " " "( + = + O" " " "( Array parameters " " ( (" " 3" = + " array parameters are not quite a call by reference During call the function gets the address of the first element but not the array length. Another parameter to tell the length is always required. B'"(! $D #+ 3 g" " / "4 A$2 E +=$hhi B) $i)hh A!h$hi =(& i D j i 2 J +$/ $O>;Jh! A;J $ 2!kk!"4 < J F = + " D g" " / + $@?2)J C-Strings C++ strings #include <cstring> C- string is an array of characters terminated in \0 char name [10] = "abcd" ; char name[] = "abcd" ; z$ =3!h k " S $ " "( vj "( $/ i "&i 2 J "( Oi "& i J j j$ 1! O 15 = = ( (& = + D 4 <5) " 3 0 ( " / 2 5"$( 4 = +$ " 3 ' l m$nm)osp$m$q r o stvuw xu y y M 7 M h 7 3/ M
4 Functions Functions:pluging in arguments C++ has 2 mechanisms for pluging in arguments: Call by value : int max (int i, int j) ; only the value is passed Call by reference : void do_stuff (int& a, int& b) ; the address is also passed Call by ref: arguments are changed by the functions and remain changed also after the function call Call-by-value vs call-by- reference When to use call by reference? #include <iostream> using namespace std; void do_stuff(int par_value, int& par_ref) // par_value is called by value, par_ref by reference int main() int a,b ; a=1; b=2; do_stuff (a,b); cout << "a after call"<< a << endl ; cout << "b after call" << b << endl ; return 0 ; void do_stuff (int par_value, int&par_ref) Par_value = 111; Cout << "par_value in function call is"<< par_value << endl ; Par_ref = 222; Cout << "par_ref in function call is"<< par_ref << endl ; Par_value in function call is 111 Par_ref in function call is 222 a after function call is 1 b after function call is If you want the arguments to remain changed also after the function call If you want your function to return more than one value If the argument you want to pass to the function is a large structure 22 Input and output (I/O) The C standard I/O library C++ stream I/O library File streams C standard I/O library <stdio> #include <stdio> Standard I/O library inherited from original C Read/write a character: c = getchar(); putchar ( x ) ; Read/write a C-string: gets and puts Formatted output printf uses conversion characters: %d integer decimal %f floating point %s C-string : int i = 5 ; int j = 7 ; double d = i / (double) j ; printf ("the value of %d over %d is %f", i,j,d);
5 C++ stream I/O Cin, cout, #include <iostream> Stream = flow of characters (~river). Stream is a C++ object with member functions: open(), close(),fail(),get(),put() Libraries: #include <iostream> for cin, cout #include <fstream> for file I/O (types: ifstream = input file stream and ofstream =output file stream) cin is an input stream standard connected to the keyboard. No need to declare cin >> number ; // cin reads next non-white character cout is an output stream standard connected to the screen. No need to declare cout << the number is << number ; Formatted output: use setf member function to set flags cout.setf(ios::fixed) cout.setf(ios::showpoint) cout.precision(2) cout.width (7) or cout << setw(7) << number ; File I/O #include <fstream> File I/O using streams. Example Steps to read from a file infile.dat and write to a file outfile.dat: -Place the #include <fstream> directive -Declare input and output streams -Connect each stream to a file = open files -Get input from the file -Send output to the output file -Disconnect the streams = close files #include <fstream> using namespace std ifstream in_stream ; ofstream out_stream ; in_stream.open( infile.dat ); out_stream.open( outfile.dat ); in_stream >> some_variable; out_stream << somevariable << endl; in_stream.close() ; out_stream.close(); 27 #include <fstream> //reads 3 numbers from the file infile.dat and sends the sum to the output file outfile.dat using namespace std; int main() int first, second, third; ifstream in_stream ; ofstream out_stream ; in_stream.open ("infile.dat"); out_stream.open ("outfile.dat"); in_stream >> first >> second >> third ; out_stream << "The sum of the first 3 \n" << "numbers in the infile.dat file\n" << "is " << (first + second + third) << endl ; in_stream.close(); out_stream.close(); return 0 ; 28 File I/O: useful functions How to read characters? cin.get (char_variable). Reads any next character. How to write characters? cout.put (char_expression) How to read C++ strings? getline (cin, line) reads a string until end of line \n or getline (cin, line, ch) reads a string until ch. How to read C-strings? cin.getline (name,20); Note: instead of cin can be any other input stream and instead of cout can be any other output stream. File I/O: useful functions How to check for file opening succes? Use fail(). #include <cstdlib>.. if (in_stream.fail()) cout << input file opening failed. \n ; exit (1) ; \\end program here
6 File I/O : useful functions Self test exercises How to test the end of the file? Each stream has a member function eof() which becomes true when the program tries to read a character beyond the end of the file. in_stream.get (next) ; while (! in_stream.eof()) do_stuff (next) ; in_stream.get(next) ; Example: ab c program reads: a b eof() false false \n false c false End of file marker true => stop What is the output of the following program lines, when embedded in a correct program that declares all variables to be of type char? a = b ; b = c ; c = a ; cout << a << b << c << c ; 2. What is the output of the following program lines, when embedded in a correct program that declares x to be of type int? x = 10 ; while (x >0) cout << x << endl ; x = x - 3; 32 Self test exercises 3. What is the output of the following program lines, when embedded in a correct program that declares x to be of type int? x = - 42 ; do cout << x << endl ; x = x 3 ; while (x>0) ; 4. Write a complete C++ program to output the even numbers from 0 to 20 one per line. The program does nothing else. 5. Write a function to swap two doubles. Use this function in a program to determine and print the maximum element of an array. 33 6
Programming in C/C
Programming in C/C++ 2006 http://few.vu.nl/~nsilvis/c++/2006 Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam Topics about C++ (10 min) about this course (5 min) C++ basics:data
More informationProgramming in C/C
Programming in C/C++ 2006 C/C++ vs. Java C Designed in 1970 Java 1995 http://few.vu.nl/~nsilvis/c++/2006 For Advantage system programming economy of expression, compact code Example: This sequence copies
More informationWhat we will learn about this week:
What we will learn about this week: Streams Basic file I/O Tools for Stream I/O Manipulators Character I/O Get and Put EOF function Pre-defined character functions Objects 1 I/O Streams as an Introduction
More informationChapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams and Basic File I/O I/O Streams I/O
More informationFile I/O CS 16: Solving Problems with Computers I Lecture #9
File I/O CS 16: Solving Problems with Computers I Lecture #9 Ziad Matni Dept. of Computer Science, UCSB I/O Data Streams and File I/O Lecture Outline An introduction to Objects and Member Functions Handling
More informationChapter 12. Streams and File I/O
Chapter 12 Streams and File I/O Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag settings Introduction Streams Special objects Deliver
More informationChapter Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects
Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Copyright 2008 Pearson Addison-Wesley. All rights reserved.
More informationStreams and Basic File I/O Tools for Stream I/O Character I/O Inheritance
Chapter 6 In this chapter, you will learn about: Streams and Basic File I/O Tools for Stream I/O Character I/O Inheritance Streams and Basic File I/O I refers to the program Input O refers to program Output:
More informationFile Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9
File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Midterm Exam grades out! Announcements If you want to see your exams, visit
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 informationSimple File I/O.
Simple File I/O from Chapter 6 http://www.cplusplus.com/reference/fstream/ifstream/ l / /f /if / http://www.cplusplus.com/reference/fstream/ofstream/ I/O Streams I/O refers to a program s input and output
More informationChapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved
Chapter 12 Streams and File I/O Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output,
More informationProgramming in C/C Lecture 2
Programming in C/C++ 2005-2006 Lecture 2 http://few.vu.nl/~nsilvis/c++/2006 Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam News Check announcements on the C/C++ website
More informationChapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved.
Chapter 12 Streams and File I/O Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag
More informationFile Input/Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #10
File Input/Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #9 due today Homework #10 is out Midterm #2 is on
More informationCS2141 Software Development using C/C++ Stream I/O
CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make
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 informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationStreams. Parsing Input Data. Associating a File Stream with a File. Conceptual Model of a Stream. Parsing. Parsing
Input Data 1 Streams 2 Streams Conceptual Model of a Stream Associating a File Stream with a File Basic Stream Input Basic Stream Output Reading Single Characters: get() Skipping and Discarding Characters:
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 informationWhat will happen if the user presses <enter> after every input? Will all work like below? Enter the values of x, y, z: Result: The sum is 17.
(LN 2-1) Review-exercises Exercise 1. FUNCTION CALLING void x1() cout
More informationC++ for Python Programmers
C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers
More information[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University
[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7 Seungkyu Lee Assistant Professor, Dept. of Computer Engineering Kyung Hee University Input entities Keyboard, files Output entities Monitor, files Standard
More informationChapter 15 - C++ As A "Better C"
Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference
More informationFile I/O Christian Schumacher, Info1 D-MAVT 2013
File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential
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 informationWARM UP LESSONS BARE BASICS
WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions
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 informationConvenient way to deal large quantities of data. Store data permanently (until file is deleted).
FILE HANDLING Why to use Files: Convenient way to deal large quantities of data. Store data permanently (until file is deleted). Avoid typing data into program multiple times. Share data between programs.
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
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 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 informationIntroduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts
Introduction to C++ 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 informationC++ does not, as a part of the language, define how data are sent out and read into the program
Input and Output C++ does not, as a part of the language, define how data are sent out and read into the program I/O implementation is hardware dependent The input and output (I/O) are handled by the standard
More informationUEE1303(1070) S 12 Object-Oriented Programming in C++
Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 06: Streams and File Input/Output I/O stream istream and ostream member
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationcs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.
cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure
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 informationCSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program
More informationWriting a Good Program. 7. Stream I/O
Writing a Good Program 1 Input and Output I/O implementation is hardware dependent C++ does not, as a part of the language, define how data are sent out and read into the program The input and output (I/O)
More informationA SHORT COURSE ON C++
Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction
More informationWe will exclusively use streams for input and output of data. Intro Programming in C++
C++ Input/Output: Streams 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: 1 istream
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 informationCMPS 221 Sample Final
Name: 1 CMPS 221 Sample Final 1. What is the purpose of having the parameter const int a[] as opposed to int a[] in a function declaration and definition? 2. What is the difference between cin.getline(str,
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 informationProgramming in C/C++ Lecture 1
Prgramming in C/C++ Lecture 1 http://few.vu.nl/~nsilvis/c++/2007 Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam Outline Abut C/C++ language Abut this curse Getting started
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 informationPartha Sarathi Mandal
MA 253: Data Structures Lab with OOP Tutorial 1 http://www.iitg.ernet.in/psm/indexing_ma253/y13/index.html Partha Sarathi Mandal psm@iitg.ernet.in Dept. of Mathematics, IIT Guwahati Reference Books Cormen,
More informationFile Operations. Lecture 16 COP 3014 Spring April 18, 2018
File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and
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 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 informationObjects and streams and files CS427: Elements of Software Engineering
Objects and streams and files CS427: Elements of Software Engineering Lecture 6.2 (C++) 10am, 13 Feb 2012 CS427 Objects and streams and files 1/18 Today s topics 1 Recall...... Dynamic Memory Allocation...
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 informationCOMP322 - Introduction to C++ Lecture 01 - Introduction
COMP322 - Introduction to C++ Lecture 01 - Introduction Robert D. Vincent School of Computer Science 6 January 2010 What this course is Crash course in C++ Only 14 lectures Single-credit course What this
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 informationMore on File I/O Strings in C++ CS 16: Solving Problems with Computers I Lecture #10
More on File I/O Strings in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Announcements Heads- Up: Midterm #2 is on Tuesday 11/14 Found evidence that
More informationFile I/O and String Manipula3ons CS 16: Solving Problems with Computers I Lecture #11
File I/O and String Manipula3ons CS 16: Solving Problems with Computers I Lecture #11 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #10 due today Homework #11 is out Midterm #2 is on
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 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 information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationTopics. bool and string types input/output library functions comments memory allocation templates classes
C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers
More informationC++ Input/Output Chapter 4 Topics
Chapter 4 Topics Chapter 4 Program Input and the Software Design Process Input Statements to Read Values into a Program using >>, and functions get, ignore, getline Prompting for Interactive Input/Output
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,
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 informationLecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-
Lecture 3 Input and Output Review from last week Variable - place to store data in memory identified by a name should be meaningful Has a type- int double char bool Has a value may be garbage change value
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 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 informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More informationCSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.
Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 1 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers,
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 informationProgramming II with C++ (CSNB244) Lab 10. Topics: Files and Stream
Topics: Files and Stream In this lab session, you will learn very basic and most common I/O operations required for C++ programming. The second part of this tutorial will teach you how to read and write
More informationPreview 8/28/2018. Review for COSC 120 (File Processing: Reading Data From a File)
Preview Relational operator If, if--if, nested if statement Logical operators Validating Inputs Compare two c-string Switch Statement Increment decrement operator While, Do-While, For Loop Break, Continue
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 informationCh 6-2. File Input / Output
2014-1 Ch 6-2. File Input / Output March 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax
More informationCS201 - Introduction to Programming FAQs By
CS201 - Introduction to Programming FAQs By What are pointers? Answer: A pointer is a variable that represents/stores location of a data item, such as a variable or array element What s the difference
More informationC++ Programming Fundamentals
C++ Programming Fundamentals 269 Elvis C. Foster Lecture 11: Templates One of the contemporary sophistries of C++ programming is defining and manipulating templates. This lecture focuses on this topic.
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 informationCOMP322 - Introduction to C++
COMP322 - Introduction to C++ Lecture 05 - I/O using the standard library, stl containers, stl algorithms Dan Pomerantz School of Computer Science 5 February 2013 Basic I/O in C++ Recall that in C, we
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
More informationMore 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 informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationOutline. 1 About the course
Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1
More informationC++ Programming for Non-C Programmers. Supplement
C++ Programming for Non-C Programmers Supplement C++ Programming for Non-C Programmers C++ Programming for Non-C Programmers Published by ITCourseware, 7245 S. Havana St, Suite 100, Centennial, CO 80112
More informationPhysics 6720 I/O Methods October 30, C++ and Unix I/O Streams
Physics 6720 I/O Methods October 30, 2002 We have been using cin and cout to handle input from the keyboard and output to the screen. In these notes we discuss further useful capabilities of these standard
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 informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More informationChapter void Test( int, int, int ); // Function prototype int main() // Function heading { int h; // Local variable
EXERCISE ANSWERS Chapter 7 Exam Preparation Exercises 1 Function call The mechanism that transfers control to the body of a function Argument list A mechanism by which functions communicate with each other;
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationObject Oriented Programming
Object Oriented Programming Course Title: Object Oriented Programming Full Marks: 60 20 20 Course No: CSC161 Pass Marks: 24 8 8 Nature of Course: Theory Lab Credit Hrs: 3 Semester: II Course Description:
More informationSummary of basic C++-commands
Summary of basic C++-commands K. Vollmayr-Lee, O. Ippisch April 13, 2010 1 Compiling To compile a C++-program, you can use either g++ or c++. g++ -o executable_filename.out sourcefilename.cc c++ -o executable_filename.out
More informationC++ Quick Guide. Advertisements
C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and
More informationIntroduction to C ++
Introduction to C ++ Thomas Branch tcb06@ic.ac.uk Imperial College Software Society October 18, 2012 1 / 48 Buy Software Soc. s Free Membership at https://www.imperialcollegeunion.org/shop/ club-society-project-products/software-products/436/
More informationIntroduction to C++ Introduction to C++ 1
1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference
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 informationC++ Programming for Non-C Programmers. Supplement
C++ Programming for Non-C Programmers Supplement ii C++ Programming for Non-C Programmers C++ Programming for Non-C Programmers Published by itcourseware, 10333 E. Dry Creek Rd., Suite 150, Englewood,
More informationC++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
C++ 프로그래밍실습 Visual Studio 2015 Contents Namespaces I/O Stream Exercise Practice1 -Namespaces Practice 1 : Namespaces Name conflict problem Occurs when an application tries to use more than two libraries
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationSU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)
SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) 1 Problem A 1.1 Specification Write an ANSI-C program that reads input from the
More information