COMP 117 Ping Demonstration Programs & Makefile / C++ Hints
|
|
- Eustacia Parker
- 5 years ago
- Views:
Transcription
1 COMP 150-IDS: Internet Scale Distributed Systems (Spring 2018) COMP 117 Ping Demonstration Programs & Makefile / C++ Hints Noah Mendelsohn Tufts University noah@cs.tufts.edu Web: Copyright 2012, 2013, 2015, 2017 & 2018 Noah Mendelsohn
2 What you should get from today s session A quick look at some details you ll need to do our programming assignment, including: The framework we re using C++ Exceptions A tiny bit about inheritance Makefiles C/C++ tips and tricks 2
3 Working through the Demo Client 3
4 Preamble Include Framework and Debug code #include "c150dgmsocket.h" #include "c150debug.h" #include <fstream> using namespace std; using namespace C150NETWORK; // for C++ std library 4
5 Preamble #include "c150dgmsocket.h" #include "c150debug.h" #include <fstream> IMPORTANT! Needed for COMP150IDS Framework! using namespace std; using namespace C150NETWORK; // for C++ std library 5
6 Main pingclient Logic 6
7 Client logic try { C150DgmSocket *sock = new C150DgmSocket(); sock -> setservername(argv[serverarg]); This is not an ordinary socket it s a smart wrapper around a socket Establishes us as a client and identifies the server ports set based on login id sock -> write(argv[msgarg], strlen(argv[msgarg])+1); readlen = sock -> read(incomingmessage, sizeof(incomingmessage)); checkandprintmessage(readlen, incomingmessage, sizeof(incomingmessage)); catch (C150NetworkException e) { cerr << argv[0] << ": caught C150NetworkException: " << e.formattedexplanation() << endl; 7
8 Client logic try { Clients write, then read C150DgmSocket *sock = new C150DgmSocket(); sock -> setservername(argv[serverarg]); sock -> write(argv[msgarg], strlen(argv[msgarg])+1); readlen = sock -> read(incomingmessage, sizeof(incomingmessage)); checkandprintmessage(readlen, incomingmessage, sizeof(incomingmessage)); catch (C150NetworkException e) { cerr << argv[0] << ": caught C150NetworkException: " << e.formattedexplanation() << endl; 8
9 Demo Server 9
10 Server logic Nasty versions of interfaces introduce errors! nastiness = atoi(argv[1]); // convert command line string to integer try { C150DgmSocket *sock = new C150NastyDgmSocket(nastiness); c150debug->printf(c150application,"ready to accept messages"); while(1) { readlen = sock -> read(incomingmessage, sizeof(incomingmessage)-1); // WORK WITH MESSAGE HERE string response = SOME RESPONSE HERE ; sock -> write(response.c_str(), response.length()+1); catch (C150NetworkException e) { c150debug->printf(c150alwayslog,"caught C150NetworkException: %s\n", e.formattedexplanation().c_str()); 10
11 Server logic Servers read, then write nastiness = atoi(argv[1]); // convert command line string to integer try { C150DgmSocket *sock = new C150NastyDgmSocket(nastiness); c150debug->printf(c150application,"ready to accept messages"); while(1) { readlen = sock -> read(incomingmessage, sizeof(incomingmessage)-1); // WORK WITH MESSAGE HERE string response = SOME RESPONSE HERE ; sock -> write(response.c_str(), response.length()+1); catch (C150NetworkException e) { c150debug->printf(c150alwayslog,"caught C150NetworkException: %s\n", e.formattedexplanation().c_str()); 11
12 Server logic nastiness = atoi(argv[1]); try { // convert command line string to integer C150DgmSocket *sock = new C150NastyDgmSocket(nastiness); c150debug->printf(c150application,"ready to accept messages"); while(1) { readlen = sock -> read(incomingmessage, sizeof(incomingmessage)-1); // WORK WITH MESSAGE HERE string response = SOME RESPONSE HERE ; sock -> write(response.c_str(), response.length()+1); catch (C150NetworkException e) { c150debug->printf(c150alwayslog,"caught C150NetworkException: %s\n", e.formattedexplanation().c_str()); Framework assumes responses go to server/port from which we read 12
13 Inferring who is a server and who is a client nastiness = atoi(argv[1]); try { // convert command line string to integer C150DgmSocket *sock = new C150NastyDgmSocket(nastiness); c150debug->printf(c150application,"ready to accept messages"); while(1) { NOTE: The socket class imposes a simple notion of client/server on UDP It decides whether you re a server or client based on which methods you call first readlen = sock -> read(incomingmessage, sizeof(incomingmessage)-1); // WORK WITH MESSAGE HERE string response = SOME RESPONSE HERE ; 1) client calls setserver name then writes sock -> write(response.c_str(), response.length()+1); 2) server starts by doing a read. Not a very robust approach for production code, but handy for these simple programs. catch (C150NetworkException e) { c150debug->printf(c150alwayslog,"caught C150NetworkException: %s\n", e.formattedexplanation().c_str()); 13
14 C++ Inheritance 14
15 A super-simple look at C++ Inheritance class Shape { private: Point position; public: Point getposition(); virtual void draw() = 0; ; Base class Shape has draw() method with no implementation (=0) 15
16 A super-simple look at C++ Inheritance class Shape { private: Point position; public: Point getposition(); virtual void draw() = 0; ; Class Circle : public Shape { public: virtual void draw(); ; Each subclass provides its own implementation of draw() Class Square : public Shape { public: virtual void draw(); ; 16
17 A super-simple look at C++ Inheritance Class shape { private: Point position; public: Point getposition(); virtual void draw() = 0; ; Shape *shapearray[2]; int i; Both classes inherit postion() method from parent Class Circle : public Shape { public: virtual void draw(); ; Class Square : public Shape { public: virtual void draw(); ; shapearray[0] = new Circle(); shapearray[1] = new Square(); for(i=0; i<2; i++) { cout << shapearray[i] -> position; shapearray[i] -> draw(); 17
18 A super-simple look at C++ Inheritance Class shape { private: Point position; public: Point getposition(); virtual void draw() = 0; ; Shape *shapearray[2]; int i; First time calls Circle::draw, second time calls Square::draw Class Circle : public Shape { public: virtual void draw(); ; Class Square : public Shape { public: virtual void draw(); ; shapearray[0] = new Circle(); shapearray[1] = new Square(); for(i=0; i<2; i++) { cout << shapearray[i] -> position; shapearray[i] -> draw(); 18
19 Inheritance and nasty sockets logic The C150NastyDgmSocket class inherits from try { C150DgmSocket *sock = new C150NastyDgmSocket(nastiness); c150debug->printf(c150application,"ready to accept messages"); while(1) { readlen = sock -> read(incomingmessage, sizeof(incomingmessage)-1); // WORK WITH MESSAGE HERE string response = SOME RESPONSE HERE ; sock -> write(response.c_str(), response.length()+1); catch (C150NetworkException e) { C150DgmSocket. You can use either type here, unless you want to call methods specific to the nasty class. c150debug->printf(c150alwayslog,"caught C150NetworkException: %s\n", e.formattedexplanation().c_str()); 19
20 C++ Exceptions 20
21 C++ Exceptions try { C++ has try/catch/throw for Exceptions try clause runs first C150DgmSocket *sock = new C150DgmSocket(); sock -> setservername(argv[serverarg]); sock -> write(argv[msgarg], strlen(argv[msgarg])+1); Any network exception in try block or methods called by try block takes us here readlen = sock -> read(incomingmessage, sizeof(incomingmessage)); checkandprintmessage(readlen, incomingmessage, sizeof(incomingmessage)); catch (C150NetworkException e) { e is of whatever type was thrown cerr << argv[0] << ": caught C150NetworkException: " << e.formattedexplanation() << endl; 21
22 C++ Exceptions Exceptions are particularly useful for network code no need to percolate return codes through layers of method calls Standard COMP 150IDS Exception Class: throw throw C150NetworkException("Client received message that was not null terminated"); When an error occurs, throw an Exception (same as raise in other langs): throw C150NetworkException (or other class) Exception classes form a hierarchy based on class inheritance (no need for you to worry about that if you don t know C++ inheritance) 22
23 Makefiles Dependency based Command Execution 23
24 Makefile variables # Do all C++ compies with g++ CPP = g++ CPPFLAGS = -g -Wall -Werror -I$(C150LIB) # Where the COMP 150 shared utilities live, including c150ids.a and userports.csv # Note that environment variable COMP150IDS must be set for this to work! Variables defined this way or from environment (this is one reason you setenv COMP117 /comp/117) C150LIB = $(COMP117)/files/c150Utils/ [ several lines skipped ] pingclient: pingclient.o $(C150AR) $(INCLUDES) $(CPP) -o pingclient pingclient.o used this way 24
25 Targets and dependencies # Do all C++ compies with g++ CPP = g++ CPPFLAGS = -g -Wall -Werror -I$(C150LIB) # Where the COMP 150 shared utilities live, including c150ids.a and userports.csv # Note that environment variable COMP150IDS must be set for this to work! The pingclient target depends on pingclient.o (and include files, etc.) C150LIB = $(COMP117)/files/c150Utils/ [ several lines skipped ] pingclient: pingclient.o $(C150AR) $(INCLUDES) $(CPP) -o pingclient pingclient.o 25
26 What gets run # Do all C++ compies with g++ CPP = g++ CPPFLAGS = -g -Wall -Werror -I$(C150LIB) When pingclient is older than pingclient.o, etc. # Where the COMP 150 shared utilities live, including c150ids.a and userports.csv # Note that environment variable COMP150IDS must be set for this to work! C150LIB = $(COMP150IDS)/files/c150Utils/ [ several lines skipped ] pingclient: pingclient.o $(C150AR) $(INCLUDES) $(CPP) -o pingclient pingclient.o..use g++ to relink it 26
27 Fancier dependencies Each xxx.o file depends on xxx.cpp %.o:%.cpp $(INCLUDES) $(CPP) -c $(CPPFLAGS) $< and is compiled from that.cpp file 27
28 C cs. C++ Strings 28
29 C vs C++ Strings we use both! C++ provides automatic allocation and useful concatenation operations C char[] arrays needed for formatting message packets File and socket APIs defined in terms of C byte arrays Also preference For some purposes, printf/scanf are handier than C++ << Etc. 29
30 Some hints on strings Won t try a full tutorial here but, remember that you can convert: char cstring[4] = abc ; // remember the null! string newstring(cstring); // initialize C++ string // from C string char *fromcplusplus = newstring.c_str(); // IMPORTANT: fromcplusplus // is stable ONLY until // next change to newstring Our focus is on the distributed system design performance matters some, but do what s easy and clean 30
31 Stringstreams: useful for formatting and conversions C++ strings do not support <<, but stringstreams do include <sstream> include <iostream> // for stringstream // for cout stringstream ss; int answer = 25; // empty stringstream ss << The answer is << answer << pounds << endl; cout << ss.str(); // get string from stringstream 31
32 What I Do (mostly) I mostly use C++ strings: automatic allocation I use or convert to char[] if I m using APIs that need them I use either printf or stringstreams for formatting or concatenate strings with + (slower, and edge cases where it doesn t work) Not all the framework code makes good choices internally you ll find some stuff that probably should be cleaned up (e.g. excess conversions) 32
COMP 117 Ping Demonstration Programs & Makefile / C++ Hints
COMP 150-IDS: Internet Scale Distributed Systems (Spring 2017) COMP 117 Ping Demonstration Programs & Makefile / C++ Hints Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah
More informationWritten by John Bell for CS 342, Spring 2018
Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors
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 informationA Quick Look at C for C++ Programmers
COMP 40: Machine Structure and Assembly Language Programming (Fall 2017) A Quick Look at C for C++ Programmers Noah Mendelsohn (with updates by Mark Sheldon) Tufts University Email: noah@cs.tufts.edu Web:
More informationC++_ MARKS 40 MIN
C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float
More informationCSE 333 Midterm Exam 7/25/16. Name UW ID#
Name UW ID# There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationExceptions, Case Study-Exception handling in C++.
PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case
More informationCS 103 Unit 14 - Streams
CS 103 Unit 14 - Streams 1 2 I/O Streams '>>' operator reads from a stream (and convert to the desired type) Always skips leading whitespace ('\n', ' ', '\t') and stops at first trailing whitespace '
More informationStarting to Program in C++ (Basics & I/O)
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
More informationLecture 14: more class, C++ streams
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 14:
More informationAssumptions. History
Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand
More information21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;
- 147 - Advanced Concepts: 21. Exceptions Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.
More informationUse the template below and fill in the areas in Red to complete it.
C++ with Inheritance Pproblem involving inheritance. You have to finish completing code that creates a class called shape, from which 3 classes are derived that are called square and triangle. I am giving
More informationPolymorphism Part 1 1
Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 19 November 7, 2018 CPSC 427, Lecture 19, November 7, 2018 1/18 Exceptions Thowing an Exception Catching an Exception CPSC 427, Lecture
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 Midterm Exam 7/25/16 Sample Solution. Question 1. (10 points) Preprocessor. Suppose we have the following two files:
Question 1. (10 points) Preprocessor. Suppose we have the following two files: defs.h: #define DIV(a,b) a / b #define INCDIV(c,d) DIV(c + 1, d + 1) main.c: #include #include "defs.h" int main()
More informationProgramming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor
Programming C++ Lecture 3 Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Inheritance S Software reuse inherit a class s data and behaviors and enhance with new capabilities.
More informationLab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.
Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs
More informationCS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE
CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
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 informationECE 462 Fall 2011, Third Exam
ECE 462 Fall 2011, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 12 pages total (including this cover sheet). Please let Prof.
More informationCSE 303, Spring 2006, Final Examination 6 June Please do not turn the page until everyone is ready.
CSE 303, Spring 2006, Final Examination 6 June 2006 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for two 8.5x11in pieces of paper (both sides).
More informationCOM S 213 PRELIM EXAMINATION #2 April 26, 2001
COM S 213 PRELIM EXAMINATION #2 April 26, 2001 Name: Student ID: Please answer all questions in the space(s) provided. Each question is worth 4 points. You may leave when you are finished with the exam.
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationCSE au Midterm Exam Nov. 2, 2018 Sample Solution
Question 1. (16 points) Build tools and make. We re building a C++ software back-end prototype for a new food web site. So far, we ve got the following source files with the code for two main programs
More informationDue Date: See Blackboard
Source File: ~/2305/lab06.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 2 Extend the IntegerSet class from Lab 04 to provide the following
More informationG52CPP C++ Programming Lecture 16
G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How
More informationExceptions. Why Exception Handling?
Exceptions An exception is an object that stores information transmitted outside the normal return sequence. It is propagated back through calling stack until some function catches it. If no calling function
More informationCh. 12: Operator Overloading
Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42
More informationCSE 333 Final Exam June 6, 2017 Sample Solution
Question 1. (24 points) Some C and POSIX I/O programming. Given an int file descriptor returned by open(), write a C function ReadFile that reads the entire file designated by that file descriptor and
More informationDue Date: See Blackboard
Source File: ~/2315/04/lab04.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 3 In this assignment create an IntegerSet class that will provide
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 informationPointers and References
Steven Zeil October 2, 2013 Contents 1 References 2 2 Pointers 8 21 Working with Pointers 8 211 Memory and C++ Programs 11 212 Allocating Data 15 22 Pointers Can Be Dangerous 17 3 The Secret World of Pointers
More informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, AUTUMN SEMESTER 2009-2010 C/C++ for Java Programmers Time allowed TWO hours Candidates may complete the front cover of their answer
More informationC++ Lab 02 - Command Line Arguments and Strings
C++ Lab 02 - Command Line Arguments and Strings 2.680 Unmanned Marine Vehicle Autonomy, Sensing and Communications Spring 2015 Michael Benjamin, mikerb@mit.edu Department of Mechanical Engineering Computer
More informationException with arguments
Exception Handling Introduction : Fundamental Syntax for Exception Handling code : try catch throw Multiple exceptions Exception with arguments Introduction Exception: An abnormal condition that arises
More informationCS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM
CS 103: Introduction to Programming Fall 2017 - Written Final Exam 12/11/16, 4:30PM 6:30PM Name: USC Email Address: Lecture (Circle One): Redekopp 2:00 TTh Goodney: 2 MW 9:30 TTh 11:00 TTh Complete the
More informationCS 240 Data Structure Spring 2018 Exam I 03/01/2018
CS 240 Data Structure Spring 2018 Exam I 03/01/2018 This exam contains three section A) Code: (basic data type, pointer, ADT) a. Reading: Trace the code to predict the output of the code b. Filling: Fill
More informationVII. POLYMORPHISM AND VIRTUAL FUNCTIONS
VII. POLYMORPHISM AND VIRTUAL FUNCTIONS VII.1 Early binding and late binding The concept of polymorphism enables different types of objects (in the same hierarchy) to use their own realization of the same
More informationCS 61B Discussion 5: Inheritance II Fall 2014
CS 61B Discussion 5: Inheritance II Fall 2014 1 WeirdList Below is a partial solution to the WeirdList problem from homework 3 showing only the most important lines. Part A. Complete the implementation
More informationC++ Namespaces, Exceptions
C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/namespaces/ http://www.cplusplus.com/doc/tutorial/exceptions/ http://www.cplusplus.com/doc/tutorial/typecasting/
More informationUnit 14. Passing Arrays & C++ Strings
1 Unit 14 Passing Arrays & C++ Strings PASSING ARRAYS 2 3 Passing Arrays As Arguments Can we pass an array to another function? YES!! Syntax: Step 1: In the prototype/signature: Put empty square brackets
More informationGet Unique study materials from
Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code
More informationLab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables
Lab#5 Due Wednesday, February 25, at the start of class Purpose: To develop familiarity with C++ pointer variables Introduction: In this lab, you will learn by experimentation the answers to some questions
More informationStack memory - "scratch pad" memory that is used by automatic variables.
Dynamic Memory Allocation In C and C++ three types of memory are used by programs: Static memory - where global and static variables live Stack memory - "scratch pad" memory that is used by automatic variables.
More informationG52CPP C++ Programming Lecture 3. Dr Jason Atkin
G52CPP C++ Programming Lecture 3 Dr Jason Atkin E-Mail: jaa@cs.nott.ac.uk 1 Revision so far C/C++ designed for speed, Java for catching errors Java hides a lot of the details (so can C++) Much of C, C++
More informationNon-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.
, ean, arithmetic s s on acters Comp Sci 1570 Introduction to C++ Outline s s on acters 1 2 3 4 s s on acters Outline s s on acters 1 2 3 4 s s on acters ASCII s s on acters ASCII s s on acters Type: acter
More informationNaming System Design Tradeoffs
COMP 117: Internet Scale Distributed Systems (Spring 2018) Naming System Design Tradeoffs Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah Copyright: 2012, 2013,
More informationCS103L SPRING 2018 UNIT 7: FILE I/O
CS103L SPRING 2018 UNIT 7: FILE I/O I/O STREAMS IN C++ I/O: short for input/ouput Older term from mainframe days for getting data into and out of your program C++ offers object oriented abstractions to
More informationANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013
ANSI C Data Analysis in Geophysics Demián D. Gómez November 2013 ANSI C Standards published by the American National Standards Institute (1983-1989). Initially developed by Dennis Ritchie between 1969
More informationC++ basics Getting started with, and Data Types.
C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding
More informationC++ Primer for CS175
C++ Primer for CS175 Yuanchen Zhu September 10, 2014 This primer is pretty long and might scare you. Don t worry! To do the assignments you don t need to understand every point made here. However this
More informationCS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms
CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()
More information1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!
//Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new
More informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More information15: Polymorphism & Virtual Functions
15: Polymorphism & Virtual Functions 김동원 2003.02.19 Overview virtual function & constructors Destructors and virtual destructors Operator overloading Downcasting Thinking in C++ Page 1 virtual functions
More informationCSE 333 Midterm Exam 7/27/15 Sample Solution
Question 1. (24 points) C programming. In this problem we want to implement a set of strings in C. A set is represented as a linked list of strings with no duplicate values. The nodes in the list are defined
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 informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED
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 informationCSE 333 Midterm Exam July 24, Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More information05-01 Discussion Notes
05-01 Discussion Notes PIC 10B Spring 2018 1 Exceptions 1.1 Introduction Exceptions are used to signify that a function is being used incorrectly. Once an exception is thrown, it is up to the programmer
More informationCS31 Discussion. Jie(Jay) Wang Week6 Nov.4
CS31 Discussion Jie(Jay) Wang Week6 Nov.4 Outline Project 4 Array C Strings Project 4 DDL: Monday, November 7 Read the spec & FAQ carefully Incremental development You can call your function in other functions
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
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 informationC++ Lab 03 - C++ Functions
C++ Lab 03 - C++ Functions 2.680 Unmanned Marine Vehicle Autonomy, Sensing and Communications Spring 2018 Michael Benjamin, mikerb@mit.edu Department of Mechanical Engineering Computer Science and Artificial
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More information2. The object-oriented paradigm
2. The object-oriented paradigm Plan for this section: Look at things we have to be able to do with a programming language Look at Java and how it is done there Note: I will make a lot of use of the fact
More informationC++ for Java Programmers
Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even
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 informationCOSC 320 Exam 2 Key Spring Part 1: Hash Functions
COSC 320 Exam 2 Key Spring 2011 Part 1: Hash s 1. (5 Points) Create the templated function object lessthan, you may assume that the templated data type T has overloaded the < operator. template
More informationHomework 6. Reading. Problems. Handout 7 CS242: Autumn November
Homework 6 Due 14 November, 5PM Handout 7 CS242: Autumn 2012 7 November Reading 1. Chapter 10, section 10.2.3 2. Chapter 11, sections 11.3.2, and 11.7 3. Chapter 12, section 12.4 4. Chapter 13, section
More informationComp215: Thinking Generically
Comp215: Thinking Generically Dan S. Wallach (Rice University) Copyright 2015, Dan S. Wallach. All rights reserved. Functional APIs On Wednesday, we built a list of Objects. This works. But it sucks. class
More informationModern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi
Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Classes Polymorphism I/O Stringstreams CMake find_package 2 Polymorphism From Greek polys, "many, much" and morphē, "form,
More informationCOMSW Introduction to Computer Programming in C
OMSW 1003-1 Introduction to omputer Programming in Lecture 23 Spring 2011 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw1003-1.html 1 Today Trees (from PP hapter 17) ++ and object
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 informationSuperior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1
Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.1 Introduction of Compiler, Comments, Program Structure, Input Output, Data Types and Arithmetic Operators
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 informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
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 informationCMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am
CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103
More informationLAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS.
LAB #8 Each lab will begin with a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs will in the demo. It is
More informationWhat can go wrong in a Java program while running?
Exception Handling See https://docs.oracle.com/javase/tutorial/ essential/exceptions/runtime.html See also other resources available on the module webpage This lecture Summary on polymorphism, multiple
More informationHomework Assignment #2 (revised)
CISC 2000 Computer Science II Fall, 2018 1 Recall the following functions and operators: Homework Assignment #2 (revised) sizeof function: returns the size of a variable (i.e., the number of bytes used
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 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 informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy
CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only
More informationThere are, of course, many other possible solutions and, if done correctly, those received full credit.
Question 1. (20 points) STL. Complete the function ChangeWords below. This function has as inputs a vector of strings, and a map of key-value pairs. The function should return a new vector
More informationJava. Representing Data. Representing data. Primitive data types
Computer Science Representing Data Java 02/23/2010 CPSC 449 161 Unless otherwise noted, all artwork and illustrations by either Rob Kremer or Jörg Denzinger (course instructors) Representing data Manipulating
More informationProgramming in C/C Lecture 3
Programming in C/C++ 2005- Lecture 3 http://few.vu.nl/~nsilvis/c++/ Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam Object Oriented Programming in C++ about object oriented
More informationCOMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C
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 information4 Strings and Streams. Testing.
Strings and Streams. Testing. 21 4 Strings and Streams. Testing. Objective: to practice using the standard library string and stream classes. Read: Book: strings, streams, function templates, exceptions.
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 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 information