diff --git a/Lectures/L27_SpecViaUML/DataSet/Makefile b/Lectures/L27_SpecViaUML/DataSet/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSet/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L27_SpecViaUML/DataSet/bin/.gitkeep b/Lectures/L27_SpecViaUML/DataSet/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L27_SpecViaUML/DataSet/bin/experiment b/Lectures/L27_SpecViaUML/DataSet/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..0d59df813474bbcda943bcd3eeac9395c83bd62f Binary files /dev/null and b/Lectures/L27_SpecViaUML/DataSet/bin/experiment differ diff --git a/Lectures/L27_SpecViaUML/DataSet/experimentation/main.cpp b/Lectures/L27_SpecViaUML/DataSet/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..205661e09ee57ff9b04a4aebbb2d121d940b5fcd --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSet/experimentation/main.cpp @@ -0,0 +1,18 @@ +#include "DataSet.h" + +#include <iostream> +using namespace std; + +int main() { + + DataSet ds; + ds.add(0.0); + ds.add(5.0); + ds.add(25.0); + ds.add(13.0); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L27_SpecViaUML/DataSet/include/DataSet.h b/Lectures/L27_SpecViaUML/DataSet/include/DataSet.h new file mode 100644 index 0000000000000000000000000000000000000000..60823d93f1b84767eba18e6259a7571c7e22bdec --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSet/include/DataSet.h @@ -0,0 +1,22 @@ +#ifndef DATASET_H +#define DATASET_H + +class DataSet +{ + private: + double sum; + double maximum; + int count; + + public: + DataSet(); + void add(double x); + double getAverage(); + double getMaximum(); + + friend ostream &operator<<( ostream &output, const PointT &P ) { + output << "x-coord: " << P.xc << "y-coord: " << P.yc; + return output; +}; + +#endif diff --git a/Lectures/L27_SpecViaUML/DataSet/src/DataSet.cpp b/Lectures/L27_SpecViaUML/DataSet/src/DataSet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0cc8a8e5fd5d52df620a79d81c5d173b249d71e7 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSet/src/DataSet.cpp @@ -0,0 +1,26 @@ +#include "DataSet.h" + +DataSet::DataSet() +{ + this->sum = 0.0; + this->maximum = 0.0; + this->count = 0; +} + +void DataSet::add(double x) +{ + this->sum += x; + if (count == 0 || maximum < x) maximum = x; + count++; +} + +double DataSet::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +double DataSet::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/Makefile b/Lectures/L27_SpecViaUML/DataSetBankAccount/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/bin/.gitkeep b/Lectures/L27_SpecViaUML/DataSetBankAccount/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/bin/experiment b/Lectures/L27_SpecViaUML/DataSetBankAccount/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..9282b727ae21b5adf2bb74c2d25334fc18f6464d Binary files /dev/null and b/Lectures/L27_SpecViaUML/DataSetBankAccount/bin/experiment differ diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/experimentation/main.cpp b/Lectures/L27_SpecViaUML/DataSetBankAccount/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc590ff8b37b3fd881ea44fb29cef447e51a2b9c --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/experimentation/main.cpp @@ -0,0 +1,23 @@ +#include "BankAccount.h" +#include "DataSetBankAccount.h" + +#include <iostream> +using namespace std; + +int main() +{ + + BankAccount b1; + b1.deposit(300); + BankAccount b2; + b2.deposit(100); + + DataSetBankAccount ds; + ds.add(b1); + ds.add(b2); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/include/BankAccount.h b/Lectures/L27_SpecViaUML/DataSetBankAccount/include/BankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..90b9e5870c46c1cefed0a3c8ec91c823cdcaed2a --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/include/BankAccount.h @@ -0,0 +1,20 @@ +#ifndef BANKACCOUNT_H +#define BANKACCOUNT_H + +#include <iostream> + +class BankAccount +{ + public: + BankAccount(); + void deposit(double amount); + void withdraw(double amount); + double getBalance(); + + friend std::ostream& operator<< (std::ostream &out, const BankAccount &ba); + + private: + double balance; +}; + +#endif diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h b/Lectures/L27_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h new file mode 100644 index 0000000000000000000000000000000000000000..fbc4622bd3e39e2aaf2acbfb53ecee1c7e977295 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/include/DataSetBankAccount.h @@ -0,0 +1,20 @@ +#ifndef DATASETBANKACCOUNT_H +#define DATASETBANKACCOUNT_H + +#include "BankAccount.h" + +class DataSetBankAccount +{ + private: + double sum; + BankAccount maximum; + int count; + + public: + DataSetBankAccount(); + void add(BankAccount x); + double getAverage(); + BankAccount getMaximum(); +}; + +#endif diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp b/Lectures/L27_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e4673801d59ef59e3a660e07c6fa33fdd72f085 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/src/BankAccount.cpp @@ -0,0 +1,29 @@ +#include "BankAccount.h" + +BankAccount::BankAccount() +{ + this->balance = 0.0; +} + +void BankAccount::deposit(double amount) +{ + this->balance += amount; +} + +void BankAccount::withdraw(double amount) +{ + this->balance -= amount; +} + +double BankAccount::getBalance() +{ + return balance; +} + +std::ostream& operator<< (std::ostream &out, const BankAccount &ba) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + out << "BankAccount(" << ba.balance << ") "; + + return out; +} diff --git a/Lectures/L27_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp b/Lectures/L27_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..975543369132ab972b32d01fa8bd5828a50f86d8 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetBankAccount/src/DataSetBankAccount.cpp @@ -0,0 +1,26 @@ +#include "DataSetBankAccount.h" +#include "BankAccount.h" + +DataSetBankAccount::DataSetBankAccount() : maximum() +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetBankAccount::add(BankAccount x) +{ + this->sum += x.getBalance(); + if (count == 0 || maximum.getBalance() < x.getBalance()) maximum = x; + count++; +} + +double DataSetBankAccount::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +BankAccount DataSetBankAccount::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/Makefile b/Lectures/L27_SpecViaUML/DataSetPointT/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d2c5aca0dd4a53631812d8d1109cd0107104b023 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/Makefile @@ -0,0 +1,53 @@ +SRC_DIRS := src +C_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.c)) +CXX_SRCS := $(foreach srcdir,$(SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +C_OBJS := ${C_SRCS:.c=.o} +CXX_OBJS := ${CXX_SRCS:.cpp=.o} +OBJS := $(C_OBJS) $(CXX_OBJS) +INCLUDE_DIRS := include +LIBRARY_DIRS := +LIBRARIES := + +prog_NAME := experiment +prog_DIR := bin +prog_FULL := $(prog_DIR)/$(prog_NAME) +prog_SRC_DIRS := experimentation +prog_C_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.c)) +prog_CXX_SRCS := $(foreach srcdir,$(prog_SRC_DIRS),$(wildcard $(srcdir)/*.cpp)) +prog_C_OBJS := ${prog_C_SRCS:.c=.o} +prog_CXX_OBJS := ${prog_CXX_SRCS:.cpp=.o} +prog_OBJS := $(prog_C_OBJS) $(prog_CXX_OBJS) +prog_INCLUDE_DIRS := +prog_LIBRARY_DIRS := +prog_LIBRARIES := + +all_OBJS := $(OBJS) $(prog_OBJS) $(test_OBJS) +DEP := $(all_OBJS:%.o=%.d) + +CXXFLAGS += -std=c++11 +CXXFLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) +LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) + +.PHONY: experiment src clean + +experiment: CXXFLAGS += $(foreach includedir,$(prog_INCLUDE_DIRS),-I$(includedir)) +experiment: LDFLAGS += $(foreach librarydir,$(prog_LIBRARY_DIRS),-L$(librarydir)) +experiment: LDFLAGS += $(foreach library,$(prog_LIBRARIES),-l$(library)) + +experiment: $(prog_FULL) + ./$(prog_FULL) + +$(prog_FULL): $(prog_OBJS) $(OBJS) + $(LINK.cc) $^ -o $@ + +-include $(DEP) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +clean: + @- $(RM) $(prog_FULL) + @- $(RM) $(prog_OBJS) + @- $(RM) $(OBJS) + @- $(RM) $(DEP) diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/bin/.gitkeep b/Lectures/L27_SpecViaUML/DataSetPointT/bin/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/bin/experiment b/Lectures/L27_SpecViaUML/DataSetPointT/bin/experiment new file mode 100755 index 0000000000000000000000000000000000000000..674f0f6c1ffbc463f3ebf29fbb5d2acb7c1e0d3d Binary files /dev/null and b/Lectures/L27_SpecViaUML/DataSetPointT/bin/experiment differ diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/experimentation/main.cpp b/Lectures/L27_SpecViaUML/DataSetPointT/experimentation/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e135e0ffe1abd64ceda2cc412b9e41295d57bf50 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/experimentation/main.cpp @@ -0,0 +1,20 @@ +#include "PointT.h" +#include "DataSetPoint.h" + +#include <iostream> +using namespace std; + +int main() +{ + + DataSetPoint ds; + ds.add(PointT(0.0, 0.0)); + ds.add(PointT(3.0, 4.0)); + ds.add(PointT(7.0, 24.0)); + ds.add(PointT(5.0, 12.0)); + + cout << "average = " << ds.getAverage() << "\n"; + cout << "maximum = " << ds.getMaximum() << "\n"; + + return 0; +} diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/include/DataSetPoint.h b/Lectures/L27_SpecViaUML/DataSetPointT/include/DataSetPoint.h new file mode 100644 index 0000000000000000000000000000000000000000..bcc6f2698b6b83a0a32534baf6386ba57d37eab9 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/include/DataSetPoint.h @@ -0,0 +1,20 @@ +#ifndef DATASETPOINT_H +#define DATASETPOINT_H + +#include "PointT.h" + +class DataSetPoint +{ + private: + double sum; + PointT maximum; + int count; + + public: + DataSetPoint(); + void add(PointT x); + double getAverage(); + PointT getMaximum(); +}; + +#endif diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/include/PointT.h b/Lectures/L27_SpecViaUML/DataSetPointT/include/PointT.h new file mode 100644 index 0000000000000000000000000000000000000000..ce3f800ecd4af22fe4c37714023a797d48500acd --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/include/PointT.h @@ -0,0 +1,21 @@ +#ifndef POINTT_H +#define POINTT_H + +#include <iostream> + +class PointT +{ + public: + PointT(double x, double y); + double xcoord(); + double ycoord(); + double distToOrigin(); + + friend std::ostream& operator<< (std::ostream &out, const PointT &point); + + private: + double xc; + double yc; +}; + +#endif diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp b/Lectures/L27_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc6da8faa43b1d40e9e2de8140453c5c48f58525 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/src/DataSetPoint.cpp @@ -0,0 +1,26 @@ +#include "DataSetPoint.h" +#include "PointT.h" + +DataSetPoint::DataSetPoint() : maximum(0.0, 0.0) +{ + this->sum = 0.0; + this->count = 0; +} + +void DataSetPoint::add(PointT x) +{ + this->sum += x.distToOrigin(); + if (count == 0 || maximum.distToOrigin() < x.distToOrigin()) maximum = x; + count++; +} + +double DataSetPoint::getAverage() +{ + if (count == 0) return 0; + else return sum/count; +} + +PointT DataSetPoint::getMaximum() +{ + return maximum; +} diff --git a/Lectures/L27_SpecViaUML/DataSetPointT/src/PointT.cpp b/Lectures/L27_SpecViaUML/DataSetPointT/src/PointT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f1d5014514b00c70bbffe4c957e03fa9eb3ef62 --- /dev/null +++ b/Lectures/L27_SpecViaUML/DataSetPointT/src/PointT.cpp @@ -0,0 +1,38 @@ +#include "PointT.h" +#include <cmath> + +PointT::PointT(double x, double y) +{ + this->xc = x; + this->yc = y; +} + +double PointT::xcoord() +{ + return this->xc; +} + +double PointT::ycoord() +{ + return this->yc; +} + +double PointT::distToOrigin() +{ + double dx; + double dy; + + dx = this->xc; + dy = this->yc; + + return sqrt(pow(dx,2.0) + pow(dy,2.0)); +} + +std::ostream& operator<< (std::ostream &out, const PointT& point) +{ + //From http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/ + // Since operator<< is a friend of the Point class, we can access Point's members directly. + out << "PointT(" << point.xc << ", " << point.yc << ")"; + + return out; +}