
Multi-Paradigm Programming in C++ State and Operations at Washington University
Explore the concept of state in programming and how it affects various operations in C++. Delve into examples of iteration and manipulation of state in a multi-paradigm programming environment. Studio practice activities for enhancing coding skills are also discussed.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
E81 CSE 428S: Multi-Paradigm Programming in C++ State and Operations on it Department of Computer Science & Engineering Washington University, St. Louis MO Chris Gill cdgill@wustl.edu 1
What do we mean by State? Values of variables in a program Especially those affecting flow of control in the program Combinations of values like member variables in an object or even in multiple interacting objects E.g., players hands and tricks taken in a card game The status of library objects, etc. E.g., whether an ofstream is open for writing to a file Things external to the program itself E.g., the contents of a file CSE 428S Multi-Paradigm Programming in C++ 2
Examples of Operations on State Iteration over a range of values E.g., moving a pointer to different positions in an array E.g., increasing or decreasing an integer variable s value E.g., moving a variable through a set of enumerated values Transforming states of multiple objects at once E.g., taking a trick in a card game where players must follow the suit of the first card that was led that round (if they can) Successful open of an ofstream object Object s is_open() method then returns true if so Modifying a file via an open ofstream object Using the object s <<(a.k.a. shift ) operator CSE 428S Multi-Paradigm Programming in C++ 3
Iteration Example: Weekdays ++w; Weekday::mon Weekday::wed ++w; ++w; ++w; --w;--w; --w;--w; Weekday::tue Weekday::sun Weekday::thu --w; --w; ++w; --w; Weekday::sat ++w; ++w; Weekday::fri enum class Weekday {sun, mon, tue, wed, thu, fri, sat, sun}; Weekday w = Weekday::sun; operator++(Weekday&); operator--(Weekday&); CSE 428S Multi-Paradigm Programming in C++ 4
Iteration Example: Pressure --p; --p; Pressure::lo Pressure::pop ++p; ++p; --p; Pressure::med ++p; ++p; --p; Pressure::hi enum class Pressure {lo, med, hi, pop}; Pressure p = Pressure::lo; operator++(Pressure&); operator--(Pressure&); CSE 428S Multi-Paradigm Programming in C++ 5
Studio 2 Practice declaring enum class style enumerations Declare and define different operators over them Consider different semantics for those operators Builds up example code and techniques that may be useful for your implementation of Lab 0 Studios 0 through 11 are due 11:59pm Monday October 16th (the night before Exam 0) Submit as soon as each is done so you get feedback and can resubmit any that may be marked incomplete CSE 428S Multi-Paradigm Programming in C++ 6