C++ Testing and Classes

Slides:



Advertisements
Similar presentations
Chapter 11 Operator Overloading; String and Array Objects Chapter 11 Operator Overloading; String and Array Objects Part I.
Advertisements

Constructors and Destructors. Constructor Constructor—what’s this? Constructor—what’s this? method used for initializing objects (of certain class) method.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
March 25, 2014CS410 – Software Engineering Lecture #12: Advanced C++ I 1 Alumni Party The Alumni Party will take place on Tuesday, May 13 It would be great.
A C LOSER L OOK AT C LASSES 1. A SSIGNING O BJECTS One object can be assigned to another provided that both objects are of the same type. It is not sufficient.
Operator Overloading Fundamentals
What is a copy constructor? A copy constructor is a special constructor for a class/struct that is used to make a copy of an existing instance during initialization.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 14: Overloading and Templates
Chapter 15: Operator Overloading
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
Operator OverloadingCS-2303, C-Term Operator Overloading CS-2303 System Programming Concepts (Slides include materials from The C Programming Language,
Review of C++ Programming Part II Sheng-Fang Huang.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
1 Operator Overloading in C++ Copyright Kip Irvine, All rights reserved. Only students enrolled in COP 4338 at Florida International University may.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Chapter 9 Defining New Types. Objectives Explore the use of member functions when creating a struct. Introduce some of the concepts behind object-oriented.
CSC 215 : Procedural Programming with C C Compilers.
Defining New Types Lecture 21 Hartmut Kaiser
CHAPTER 13 CLASSES AND DATA ABSTRACTION. In this chapter, you will:  Learn about classes  Learn about private, protected, and public members of a class.
Operator Overloading Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
ECE122 Feb. 22, Any question on Vehicle sample code?
 2008 Pearson Education, Inc. All rights reserved Operator Overloading.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Chapter 13: Overloading and Templates. Objectives In this chapter, you will – Learn about overloading – Become familiar with the restrictions on operator.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Learning Objectives Fundamentals of Operator Overloading. Restrictions of Operator Overloading. Global and member Operator. Overloading Stream-Insertion.
Constructor It is a special member of a class that has the following characteristic 1)It has the same name as of its class. 2)It don’t have an explicit.
1 Introduction to Object Oriented Programming Chapter 10.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
 CSC 215 : Procedural Programming with C C Compilers.
1 Ugly Realities The Dark Side of C++ Chapter 12.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Operator Overloading.
Chapter 13: Overloading and Templates
Completing the Problem-Solving Process
Programming with ANSI C ++
Haidong Xue Summer 2011, at GSU
Java Primer 1: Types, Classes and Operators
PVS-Studio static analyzer: advanced features
Chapter 15: Overloading and Templates
CS212: Object Oriented Analysis and Design
Anatomy of a class Part II
This pointer, Dynamic memory allocation, Constructors and Destructor
The dirty secrets of objects
Constructor & Destructor
3.3 Abstract Classes, Assignment, and Casting in a Hierarchy
Use of Mathematics using Technology (Maltlab)
Operator Overloading.
Name: Rubaisha Rajpoot
Andy Wang Object Oriented Programming in C++ COP 3330
CSC 270 – Survey of Programming Languages
C++ File Structure and Intro to the STL
C++ Testing and Classes
Operator Overloading.
A programming language
C++ File Structure and Intro to the STL
Operator Overloading; String and Array Objects
Andy Wang Object Oriented Programming in C++ COP 3330
STL and Example.
Anatomy of a class Part II
Separating Interface from Implementation
More on C++ G Carl Evans.
Object Oriented Programming
More on C++ G Carl Evans.
Presentation transcript:

C++ Testing and Classes G Carl Evans

Catch2 Catch is a testing framework for C++ it is used in many places including in the CS225. The tutorial is here https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md#top

How hard was Adventure 2 code review assignment? Easy Moderate Challenging Unreasonable

How long did Adventure 2 assignment take? Less than 3 hours 3 to 6 hours 6 to 9 hours 9 to 12 hours More than 12 hours

Things you should doing allready Get C++ (Xcode/Visual Studio/gcc) Make a helloworld.cpp program and build it.

Classes in C++ File layout .h .cpp Declare structure of the object including member variables Declare member functions (methods) .cpp Define functions of the class

Constructors Run when an object is created before the object is available to make the object exist in a coherent state. Automatic Default Constructor Automatic Default: created by the compiler Default: takes no arguments Initializes member objects using their default constructor Non-object values undefined Only generated if no constructors written

Constructors User Defined Functions with the same name as the class define constructors Initialization Lists Comma separated list member_variable_(expression) Run before the body of the constructor Default Arguments Provide values for missing agruments explicit StudentRecord(std::string name, int grade = 0); StudentRecord::StudentRecord(std::string name, int grade) : name_(name), grade_(grade) { //body }

Gradebook class

What System do you use for this class? Windows Macintosh Linux More than one of the above

What development environment are you setting up for C++? Visual Studio Xcode Editors and command line Visual Studio Code and Clang or gcc Other (Eclipse/Clion/???) What is a development environment?

Operator Overloading Make code more readable and intuitive by allowing more natural expression Change the behavior of many of the standard operators based on the types that are being used. We have seen the overload of [] with map and vector We have seen the overload of -> and * with the iterator in map

Operators that can be overloaded in C++ Operator Category Operators Arithmetic + - * / % ++ -- Bitwise & | ^ ~ >> << Relational < <= > >= == != Logical ! && || Assignment = += -= *= /= %= ˆ= &= |= >>= <<= <= >= Other () [] -> , ->

Stream extraction and insertion std::ostream& operator<<(std::ostream& os, const T& obj){ // write obj to stream return os; } std::istream& operator>>(std::istream& is, T& obj){ // read obj from stream if( /* T could not be constructed */ ) is.setstate(std::ios::failbit); return is;

Student Record