Lab 4 Agenda
Topics: type casts, static data, operator overloading, pre/post ++/--
Getting started:
- point browser to https://skatgame.net/mburo/courses/350
- click on B4 in the schedule
- use id/pw listed on eclass to get access if asked
- this should bring up this page
Part 1 (14:00)
- Lab exercise 3 solution
- Assignment 1 solution
Part 2 (~14:30)
- Prep problems (see below)
Part 3 (15:20)
Part 4 (15:30)
Prep Problem 1
For class
struct Point
{
int x, y;
};
in p1.cpp implement global operators << and >>
that allow you read and write points from stdin/stdout like so:
Point p;
cin >> p;
cout << p << endl;
For this to work you need to include iostream.
Prep Problem 2
In file p2.cpp implement the following class operators for class Point above:
== > >=
which work componentwise. I.e., two points are equal if their x
components match and their y components match. For >
and >= use the lexicographic ordering with x being the
higher-valued component.
Prep Problem 3
In file p3.cpp implement pre++, post++, pre--, post-- for class Point
above. Their effect is to increment or decrement a point's x
component, respectively. Also test your implementation.
Prep Problem 4
Suppose you want to count how many Point instances have been
constructed at any given time when your program runs. Write code in p4.cpp that
gives you access to this information. Can your solution be compromised by a
teammate working on a different project file? If so, try to improve your
design.
Prep Solutions
Lab Exercise
Secrets