Starting to Program in C++ (Basics & I/O)
|
|
- Lucy Patrick
- 5 years ago
- Views:
Transcription
1 Copyright by Bruce A. Draper. 2017, All Rights Reserved. Starting to Program in C++ (Basics & I/O) On Tuesday of this week, we started learning C++ by example. We gave you both the Complex class code and the code for the programming assignment. That has given you a chance to look at a lot of C++, and hopefully to learn from it. But the problem with learning from examples is that you see things you don t understand, and then what? The answer is that you go and find out about those specific topics. We start that today by focusing on aspects of C++ that are different from Java and that you need for the first programming assignment: the compiler and I/O. What does the g++ command do? Two things, actually. First it compiles each source (.cpp) file from C++ to object code, which can be thought of as assembly code with symbolic addresses. The symbolic links point to addresses of methods defined in other files, and are necessary because every source file is compiled independently of every other source file. At this step, the g++ compiler creates an object (.o) file for every source (.cpp) file. Then g++ calls the linker to combine all the object files into a single executable file, resolving the symbolic links in the process. This produces the executable file. How do you compile a project from the command line? Well, for starters, you only compile your source (.cpp) files. Your header (.h) files are presumably included in one or more of your source files, or else they have no effect. To compile your source files, you could type: g++ *.cpp This would call the compiler on every source (.cpp) file in your directory, and then call the linker on the resulting object (.o) files to produce an executable file named a.out. It would then delete the object files. Unfortunately, this would almost certainly lead to a compiler error, as the compiler would not be able to find the files you told it to include. In particular, if you file has a line like: #include <foo.h> The compiler won t find it. It will generate an error because it can t find it, and then more errors because the rest of your file needed to classes or function in Foo. You could fix is by putting the filename in quotes (making it a string), but in my opinion this is poor style. Using a string filename tells the compiler to look in your local directory. This is fine for PA1, but will break as soon as you want to reuse code by including the same file in several projects. So it is better not to go down this path. Instead, it is better to tell the compiler where to look for your header files. In unix, the current directory is always called. (yes, that s a period with nothing else). The I flag tells the compiler to look in a directory for header files. Putting these two things together, we get: g++ -I. *.cpp Now your code should compile. (If it doesn t, there is probably a syntax problem with your code.) Note that you can use the I flag many times, if you want the compiler to look at multiple
2 directories. This is common for large projects. Also, the compiler automatically knows where the standard template library is, so you can write things like #include<vector> without worrying where the vector file is. A similar thing happens with external libraries: you have to tell the compiler which libraries to include. For example, if you want to compile a program that uses X11 commands, you need to tell it to use the X11 library. You can do this via: g++ -I. *.cpp lx11 X11 is a standard library, so the compiler knows where it is. The compiler just needs to know which library to link to. If you wanted to link to a non-standard library, you would use the L flag to tell the compiler where to find the non-standard library. For example, if you had a non-standard library called MyLib in the current directory, you would compile using g++ -I. L. lmylib *.cpp But we get ahead of ourselves. We are not using extra libraries yet So now you can compile your code, but it produces an executable called a.out. That s OK, you can always rename the executable file, but you would probably like the compiler to name the executable something else, like PA1 (for programming assignment 1). You can do this with the output flag, -o g++ -I. *.cpp o PA1 Two more flags you should get in the habit of using. Wall turns on all compiler warnings. Warnings are things in your code that aren t syntax errors, but are almost certainly semantic errors. For example, if you reach the end of a non-void function without returning a value, or if you declare a variable and never use it, possibly because of a misspelling. You should always include the Wall flag, and fix anything it warns you about. g preserves the symbol table as part of the executable. There is a very slight cost to this (it makes the executable file larger), but it is needed if you want to run the debugger or a profiler or many other development tools. Therefore, while your program is in development you should always get in the habit of using the g flag. Therefore a good command-line compilation command for programming assignment #1 is: g++ -Wall g I. *.cpp o PA1 There are still more compiler flags that we won t get into (the resources page of the class website has a link to the compiler documentation). This is already complex, however. Fortunately, we don t invoke the compiler from the command line very often. Instead, we use make files, as introduced in the recitation session. A good make file not only allows you to forget the compiler flags, it supports separate compilation. Let s look at a sample make file, of the type you might make for assignment #1. My make file begins with three lines: CC = g++ LFLAGS = -o PA1 CFLAGS = -g Wall I. -c
3 What do these lines do? They declare variables for the make system. The first line is mostly a convention. It declares the compiler (we use g++) as a variable named CC. This is useful in large projects where you may be targeting different platforms with different compilers. It allows you to change all the compile commands for all the files in the project by just changing the first line of the make file. We will not change compilers in this course, however, so I am just showing this to you to show the convention. The second line defines the flags I will use for the linker (hence LFLAGS ). At the moment, the only flags I need to send to the linker are the flags for renaming the output. I want the output to be called PA1, not a.out, and o PA1 renames the output file. More generally, however, if I were linking to other libraries, this is where I would put the l and L flags. The third line defines the flags for the compiler (hence CFLAGS ). As discussed above, the -g flag preserves information for the debugger and other tools, the Wall flag turns on warnings, and the I. flag tells the compiler to look in the current directory for include files. The c flag tells the compiler to compile but not link. Instead, produce a.o file with the same name as the source file (e.g. main.cpp becomes main.o). If I have just one class in Assignment #1 called histogram, then the rest of my make file might look like this: PA1:<tab>main.o histogram.o <tab>$(cc) main.o histogram.o $(LFLAGS) main.o:<tab>main.cpp histogram.h <tab>$(cc) main.o $(CFLAGS) histogram.o:<tab>histogram.cpp histogram.h <tab>$(cc) histogram.o $(CFLAGS) The first command tells the make system how to make the executable PA1 by linking together object files, namely main.o and histogram.o. The items on the first line are the target object to be made, in this case PA1, and the files it depends on, main.o and histogram.o. The idea is that when the user tells it to make PA1, it will first check if main.o and histogram.o are up to date. If they are, it calls the linker using the information in the second line. If they aren t, it recursively calls make to update the files it depends on, and then calls the linker. The second line is simply the linker command, with variables expanded (so that $(CC) becomes g++, etc.). A note about syntax. In the example above, I have used <tab> to mark the tab character. In an editor, this will look like a series of spaces (how many depends on the editor), but make is picky. Where I have marked <tab> it must be a tab character, not spaces, or make will throw a syntax error. The groups of lines after the first two compile source code into object code. The first one, for example, compiles main.cpp into main.o; the second one compiles histogram.c into histogram.o. The c flag in CFLAGS tells the compiler to compile but not link. As before, the files after the colon and the target (e.g. main.o) specify the files that the target depends on. If any of these files have been changed, then the target needs to be recompiled. Now, on to I/O. There are two basic I/O classes: ostream for output, and istream for input. You have to include them, because they are classes in a library, not language primitives. To do this, write
4 #include <iostream> (You don t need a space between include and <, but spaces are allowed) Warning: One of the things I dislike about your text is that it tends to omit the include statements in its examples. If you try one of their examples and it won t compile, think about what include statements you might need to add. How do we use streams? Output streams, in particular, are easy. There is a predefined output stream call std::cout. It is defined to be standard output, as is usually the terminal (unless it has been rerouted, for example by a unix pipe). If I have an integer a, and want to write its value to the terminal, then I just write: std::cout << a; << is called the insertion operator (because it inserts values into streams), and it will work for any primitive type. int, double, char, you name it. There are a couple of things to note. You can output many things in one line by daisy chaining the << symbol, for example: std::cout << a << b; The insertion operator only outputs what you tell it to, however, so if you want a space between two integers, you have to put it there, as in: std::cout << a << << b; Also, Booleans print as 0 or 1 (they are implemented as small constants). To write an end-of-line character (carriage return), insert std::endl into the stream. For example: std::cout << a << << b << std::endl; std::endl is actually more than just a carriage return. It also causes the system to flush the output buffer, i.e. it forces the system to immediately print the line, since otherwise I/O is buffered. This can matter if you are using print statements to debug your program. Still, in general, output is easy for primitives. To output instances of a class, you overload the insertion operator but we ll hold off on that until later. You can do the homework assignment by just outputting primitives. There is a second pre-defined output stream called std::cerr. It behaves like std::cout (both default to the terminal), but is separate. This stream is intended for errors, and allows shell scripts and users to separate the normal output to std::cout from the errors written to std::cerr. Input from the terminal is just about as easy. The input stream from the terminal is predefined as std::cin. To read an integer from an input stream, you could write the following: int a; std::cin >> a;
5 >> is called the extraction operator, because it extracts values from streams Quick question: between the lines above, what is the value of a? (answer: undefined) But what exactly does it read? The >> operator will: Skip initial whitespace Read as many non-whitespace characters as it can interpret to be the data type you asked for. For example, let s say the input stream contains the following characters: 14 5i This example is motivated by the Complex class presented earlier. If you read an integer from this stream using >>, it will skip the initial spaces, and then read 14 as an integer. The input stream now contains 5i. What if you do it again? The second time it will skip a space, and then read 5. It cannot interpret i as an integer, so it stops and returns the number 5. Note that no error occurred: you asked it to read an integer, and it did. Look back at the Complex number code I gave you on Monday, and look at the Read() method of the Complex number class. It does exactly this. The format of a complex number is 1+2i (or 3-2i). What if you read into a char (character) now? It will set the char to be i, and again the read will succeed. What if instead you read into an integer again? Then it fails i is not an integer. So what happens? First, the read fails, so the integer you are reading into is unchanged. The input stream does not throw an error. It has the same value it had before the read operation. (This value might be undefined, hence the question above.) Second, the input stream enters the fail state. I repeat that no error is thrown, however. So how do you know if a read succeeded? By checking the fail() method of the stream. If a read fails, then istr.fail() becomes true. So after every read, you should check for istr.fail(). Again, look at the Complex code for examples. So what happens if you keep going after a read has failed? Well, your code will continue to run, but once a stream has failed, every subsequent read from that stream will fail also. This can produce some real gibberish, not to mention infinite loops. So always check for failures. Why not throw an error? Because I might be testing the input of a stream. Can I read it as an int? If not, can I read it as something else? To do this, I can clear the fail state from the stream (istr.clear()) and try again. It can get annoying typing std:: all the time. The std:: is there because all the standard libraries are in the std namespace. To avoid all this typing, add
6 using std::cin; using std::cout; using std::endl; Right below the #include <iostream> statement at the top of the file. Now, istream and ostream are abstract streams classes. They do input and output in general, not to any particular file or device. std::cin and std::cout are instances of more specific derived classes that do input and output to standard streams Although you will often write your IO functions in terms of istream and ostream, you rarely instantiate them. Instead you instantiate one of 2 derived classes. In the case of input, the two most common derived classes are ifstream & istringstream (there is also ofstream and ostringstream for output, and all of these are in the std namespace). An ifstream is an input stream from a file. You will need this for the assignment. In particular, you will need to open an input string from the file named in argv[1]. For example, you will probably have a line that looks like: ifstream istr(argv[1]); Once you instantiate an ifstream, it works just like an istream in terms of the >> operator. Indeed, you may choose to pass it as an instance of istream (if you remember polymorphism from CS161). An istringstream is an input stream from a string. This might also be handy for the assignment, particularly if you want your error messages to contain line number. (This is not required, but it is a nice thing to do, and you may appreciate it down the road if you have I/O errors.) You need to use #include<fstream> to use ifstream, and you need to use #include<sstream> to use istringstream. Is there more to I/O? Of course. You can format things in various ways, detect the end-of-file condition (a subset of fail()), read a line of code at a time, etc. But this should get you started. Use your reference! One last comment about programming assignments in general. When you are programming, there is always a customer. You program for someone. In this case, I am the customer. If there are details I haven t specified, you need to ask about them. Why might I (the customer) leave things unspecified? One of two reasons: 1. I know what I want, I just forgot to say it (or thought it was obvious), or 2. I don t know what I want. Be sensitive to this distinction. You can t negotiate in case #1, but you might be able to influence the answer in case #2. For example, in a business setting you might point out that implementing X will take a month, but Y can be built in a week. Is Y just as good?
CS354 gdb Tutorial Written by Chris Feilbach
CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that
More informationLab: Supplying Inputs to Programs
Steven Zeil May 25, 2013 Contents 1 Running the Program 2 2 Supplying Standard Input 4 3 Command Line Parameters 4 1 In this lab, we will look at some of the different ways that basic I/O information can
More informationCSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationCS2141 Software Development using C/C++ Compiling a C++ Program
CS2141 Software Development using C/C++ Compiling a C++ Program g++ g++ is the GNU C++ compiler. A program in a file called hello.cpp: #include using namespace std; int main( ) { cout
More informationCMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019
CMSC162 Intro to Algorithmic Design II Blaheta Lab 10 28 March 2019 This week we ll take a brief break from the Set library and revisit a class we saw way back in Lab 4: Card, representing playing cards.
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 14 Makefiles and Compilation Management 1 Where we are Onto tools... Basics of make, particular the concepts Some fancier make features
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 informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationSeparate Compilation of Multi-File Programs
1 About Compiling What most people mean by the phrase "compiling a program" is actually two separate steps in the creation of that program. The rst step is proper compilation. Compilation is the translation
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationPIC 10A Objects/Classes
PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous
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 informationFall 2017 CISC/CMPE320 9/27/2017
Notices: CISC/CMPE320 Today File I/O Text, Random and Binary. Assignment 1 due next Friday at 7pm. The rest of the assignments will also be moved ahead a week. Teamwork: Let me know who the team leader
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationC++ Support Classes (Data and Variables)
C++ Support Classes (Data and Variables) School of Mathematics 2018 Today s lecture Topics: Computers and Programs; Syntax and Structure of a Program; Data and Variables; Aims: Understand the idea of programming
More informationCSE 333 Lecture 9 - intro to C++
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia & Agenda Main topic: Intro to C++ But first: Some hints on HW2 Labs: The
More informationCOMP Lecture Notes The Compiler
COMP 161 - Lecture Notes - 05 - The Compiler January 20, 2016 In these notes we talk about compiling our multi-file C++ program in order to check syntax errors, run unit-tests, or build the main executable.
More informationCSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O
CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O PA2: encoding/decoding ENCODING: 1.Scan text file to compute frequencies 2.Build Huffman Tree 3.Find code for every symbol (letter) 4.Create new
More informationUnderstanding main() function Input/Output Streams
Understanding main() function Input/Output Streams Structure of a program // my first program in C++ #include int main () { cout
More informationassembler Machine Code Object Files linker Executable File
CSCE A211 Programming Intro What is a Programming Language Assemblers, Compilers, Interpreters A compiler translates programs in high level languages into machine language that can be executed by the computer.
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationLab 1: First Steps in C++ - Eclipse
Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the
More informationCompilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors
First Program Compilation and Execution Simplifying Fractions Loops If Statements Variables Operations Using Functions Errors C++ programs consist of a series of instructions written in using the C++ syntax
More informationChapter 1 - What s in a program?
Chapter 1 - What s in a program? I. Student Learning Outcomes (SLOs) a. You should be able to use Input-Process-Output charts to define basic processes in a programming module. b. You should be able to
More informationSoftware Engineering /48
Software Engineering 1 /48 Topics 1. The Compilation Process and You 2. Polymorphism and Composition 3. Small Functions 4. Comments 2 /48 The Compilation Process and You 3 / 48 1. Intro - How do you turn
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 informationQUIZ. What is wrong with this code that uses default arguments?
QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code
More informationy
The Unfit tutorial By Dr Martin Buist Initial version: November 2013 Unfit version: 2 or later This tutorial will show you how to write your own cost function for Unfit using your own model and data. Here
More informationHello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3
Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running
More informationPracticum 5 Maps and Closures
Practicum 5 Maps and Closures Assignment Details Assigned: February 18 th 2014. Due: February 20 th, 2014 at midnight. Background One of the requirements of PA1 Part 2 using a data structure to hold function
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
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 informationObject Oriented Design
Object Oriented Design Lecture 2: Introduction to C++ Class and Object Objects are essentially reusable software components. There are date objects, time objects, audio objects, video objects, automobile
More informationThese are notes for the third lecture; if statements and loops.
These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern
More informationCS 220: Introduction to Parallel Computing. Arrays. Lecture 4
CS 220: Introduction to Parallel Computing Arrays Lecture 4 Note: Windows I updated the VM image on the website It now includes: Sublime text Gitkraken (a nice git GUI) And the git command line tools 1/30/18
More informationReviewing gcc, make, gdb, and Linux Editors 1
Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University
More informationCompiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7
Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7 Ziad Matni Dept. of Computer Science, UCSB Programming in Multiple Files The Magic of Makefiles!
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Dan Grossman Spring 2007 Lecture 19 Profiling (gprof); Linking and Libraries Dan Grossman CSE303 Spring 2007, Lecture 19 1 Where are we Already started
More informationCOSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14
COSC 2P91 Introduction Part Deux Week 1b Brock University Brock University (Week 1b) Introduction Part Deux 1 / 14 Source Files Like most other compiled languages, we ll be dealing with a few different
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationA couple of decent C++ web resources you might want to bookmark:
CS106X Handout 10 Autumn 2012 September 28 th, 2012 C++ and CS106 Library Reference Written by Julie Zelenski and revised by Jerry. A couple of decent C++ web resources you might want to bookmark: http://www.cppreference.com
More information5. Applicative Programming. 1. Juli 2011
1. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 41 Outline Recapitulation Computer architecture extended: Registers and caches Header files Global variables
More informationSaleae Device SDK Starting a Device SDK Project on Windows Starting a Device SDK Project on Linux... 7
Contents Starting a Device SDK Project on Windows... 2 Starting a Device SDK Project on Linux... 7 Debugging your Project with GDB... 9 Starting a Device SDK Project on Mac... 11 Build Script / Command
More informationC++ Basics. Lecture 2 COP 3014 Spring January 8, 2018
C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing
More informationCours de C++ Introduction
Cours de C++ Introduction Cécile Braunstein cecile.braunstein@lip6.fr Cours de C++ 1 / 20 Généralité Notes Interros cours 1/3 Contrôle TP 1/3 Mini-projet 1/3 Bonus (Note de Participation) jusqu à 2 points
More informationCSE 333 Interlude - make and build tools
CSE 333 Interlude - make and build tools Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington make make is a classic program for controlling what gets (re)compiled
More informationUsing Karel with Eclipse
Chris Piech Handout #3 CS 106A January 10, 2018 Using Karel with Eclipse Based on a handout by Eric Roberts and Nick Troccoli Once you have downloaded a copy of Eclipse as described on the course website,
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationCOSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26
COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.
More informationCSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch
CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed
More informationComputer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview
Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is
More informationCS Software Engineering for Scientific Computing. Lecture 5: More C++, more tools.
CS 294-73 Software Engineering for Scientific Computing Lecture 5: More C++, more tools. Let s go back to our build of mdarraymain.cpp clang++ -DDIM=2 -std=c++11 -g mdarraymain.cpp DBox.cpp -o mdarraytest.exe
More informationLecture 14: more class, C++ streams
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 14:
More informationWhy C++ is much more fun than C (C++ FAQ)?
From C to C++ Why C++ is much more fun than C (C++ FAQ)? 1. Classes & methods - OO design 2. Generic programming - Templates allow for code reuse 3. Stricter type system (e.g. function args) 4. Some run-time
More informationComputer Science II Lecture 2 Strings, Vectors and Recursion
1 Overview of Lecture 2 Computer Science II Lecture 2 Strings, Vectors and Recursion The following topics will be covered quickly strings vectors as smart arrays Basic recursion Mostly, these are assumed
More informationComputer Science II Lecture 1 Introduction and Background
Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,
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 informationProgrammazione. Prof. Marco Bertini
Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Hello world : a review Some differences between C and C++ Let s review some differences between C and C++ looking
More informationHow to approach a computational problem
How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to
More informationCSE 333 Lecture 6 - data structures
CSE 333 Lecture 6 - data structures Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia Exercises: - ex5 is out: clean up the code from section yesterday, split
More informationNotes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College
Preparing to Program You should take certain steps when you're solving a problem. First, you must define the problem. If you don't know what the problem is, you can't find a solution! Once you know what
More informationProject 1 Balanced binary
CMSC262 DS/Alg Applied Blaheta Project 1 Balanced binary Due: 7 September 2017 You saw basic binary search trees in 162, and may remember that their weakness is that in the worst case they behave like
More informationCS 220: Introduction to Parallel Computing. Beginning C. Lecture 2
CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
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 informationCS664 Compiler Theory and Design LIU 1 of 16 ANTLR. Christopher League* 17 February Figure 1: ANTLR plugin installer
CS664 Compiler Theory and Design LIU 1 of 16 ANTLR Christopher League* 17 February 2016 ANTLR is a parser generator. There are other similar tools, such as yacc, flex, bison, etc. We ll be using ANTLR
More informationInstalling and Using Dev-C++
Installing and Using Dev-C++ 1. Installing Dev-C++ Orwell Dev-C++ is a professional C++ IDE, but not as big and complex as Visual Studio. It runs only on Windows; both Windows 7 and Windows 8 are supported.
More informationChris' Makefile Tutorial
Chris' Makefile Tutorial Chris Serson University of Victoria June 26, 2007 Contents: Chapter Page Introduction 2 1 The most basic of Makefiles 3 2 Syntax so far 5 3 Making Makefiles Modular 7 4 Multi-file
More informationC++ For Science and Engineering Lecture 2
C++ For Science and Engineering Lecture 2 John Chrispell Tulane University Wednesday August 25, 2010 Basic Linux Commands Command ls pwd cd What it does. lists the files in the current directory prints
More informationCompilers Project 3: Semantic Analyzer
Compilers Project 3: Semantic Analyzer CSE 40243 Due April 11, 2006 Updated March 14, 2006 Overview Your compiler is halfway done. It now can both recognize individual elements of the language (scan) and
More informationChapter 1 Introduction to Computers and C++ Programming
Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20
More informationCS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer
CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this
More informationCMSC 201 Fall 2016 Lab 09 Advanced Debugging
CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working
More information1 of 8 3/28/2010 8:03 AM C++ Special Topics Home Class Info Links Lectures Newsgroup Assignmen This is a short review of special topics in C++ especially helpful for various assignments. These notes are
More informationC Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006
C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30
More informationCSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I
Review from Lecture 2 CSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I Vectors are dynamically-sized arrays Vectors, strings and other containers should be: passed by reference when they are to
More informationSchool of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15
Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL
More informationComputer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview
Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a
More informationC / C++ Coding Rules
C / C++ Coding Rules Luca Abeni luca.abeni@unitn.it March 3, 2008 Abstract This short document collects some simple and stupid coding rules for writing understandable C or C++ code, and has been written
More informationSpring CS Homework 12 p. 1. CS Homework 12
Spring 2018 - CS 111 - Homework 12 p. 1 Deadline 11:59 pm on Friday, May 4, 2018 Purpose CS 111 - Homework 12 To practice with sentinel- and question-controlled loops, file input and file output, and writing
More informationCS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our
More informationDiscussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;
More informationLinux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs
Linux Tutorial #1 Introduction The Linux operating system is now over 20 years old, and is widely used in industry and universities because it is fast, flexible and free. Because Linux is open source,
More informationLecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.
Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationG52CPP C++ Programming Lecture 17
G52CPP C++ Programming Lecture 17 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Exceptions How to throw (return) different error values as exceptions And catch the exceptions
More informationCS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style
CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming
More informationCS11 Intro C++ Spring 2018 Lecture 3
CS11 Intro C++ Spring 2018 Lecture 3 C++ File I/O We have already seen C++ stream I/O #include cout > name; cout
More informationThe Structure of a C++ Program
Steven Zeil May 25, 2013 Contents 1 Separate Compilation 3 1.1 Separate Compilation.......... 4 2 Pre-processing 7 2.1 #include.................. 9 2.2 Other Pre-processing Commands... 14 3 Declarations
More informationSeparate Compilation Model
Separate Compilation Model Recall: For a function call to compile, either the function s definition or declaration must appear previously in the same file. Goal: Compile only modules affected by recent
More informationOutline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O
Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references
More information6. Pointers, Structs, and Arrays. March 14 & 15, 2011
March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationStreams. Ali Malik
Streams Ali Malik malikali@stanford.edu Game Plan Recap Purpose of Streams Output Streams Input Streams Stringstream (maybe) Announcements Recap Recap - Hello, world! #include int main() { std::cout
More informationBasic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable
Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is
More information