Download presentation
Presentation is loading. Please wait.
1
C++ Testing and Classes
G Carl Evans
2
Catch2 Catch is a testing framework for C++ it is used in many places including in the CS225. The tutorial is here
3
How hard was forth code review assignment?
Easy Moderate Challenging Unreasonable
4
How long did fourth assignment take?
Less than 3 hours 3 to 6 hours 6 to 9 hours 9 to 12 hours More than 12 hours
5
Things start doing Get C++ (Xcode/Visual Studio/gcc)
Make a helloworld.cpp program and build it.
6
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
7
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
8
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 }
9
Gradebook class
10
What System do you use for this class?
Windows Macintosh Linux More than one of the above
11
What development environment did you set up for C++?
Visual Studio Xcode Editors and command line Other (Eclipse/Clion/???) What is a development environment?
12
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
13
Operators that can be overloaded in C++
Operator Category Operators Arithmetic + - * / % ++ -- Bitwise & | ^ ~ >> << Relational < <= > >= == != Logical ! && || Assignment = += -= *= /= %= ˆ= &= |= >>= <<= <= >= Other () [] -> , ->
14
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;
15
Student Record
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.