diff --git a/ControlFlowPlaypen/ControlFlowPlaypen.cpp b/ControlFlowPlaypen/ControlFlowPlaypen.cpp new file mode 100644 index 0000000..eeeec05 --- /dev/null +++ b/ControlFlowPlaypen/ControlFlowPlaypen.cpp @@ -0,0 +1,59 @@ +// ControlFlowPlaypen.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" + +int main() +{ + int a[]{ 1,2,3,4 }; + for (int i = 0; i < 4; i++) + { + cout << a[i] << endl; + } + for (int *p = a, *e = a + 4; p != e; ++p) + { + cout << *p << endl; + } + auto ba = begin(a); + auto ea = end(a); + for (; ba != ea; ba++) + { + cout << *ba << endl; + } + for (auto value : a) + { + cout << value << endl; + } + vector v{ 5,6,7,8 }; + auto bv = begin(v); + auto cbv = cbegin(v); + + for (auto i = v.rbegin(); i != v.rend(); ++i) + { + cout << *i << endl; + } + + int awesome = 0; + + switch (awesome) + { + case 0: + cout << "hello" << endl; + break; + case 1: + cout << "world" << endl; + break; + default: + cout << "final" << endl; + break; + } + + char *s = "plualsight"; + while (*s) + { + putchar(*s); + s++; + } + getchar(); + return 0; +} \ No newline at end of file diff --git a/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj b/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj new file mode 100644 index 0000000..7d7d937 --- /dev/null +++ b/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj @@ -0,0 +1,158 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5} + Win32Proj + ControlFlowPlaypen + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj.filters b/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj.filters new file mode 100644 index 0000000..4b44fa0 --- /dev/null +++ b/ControlFlowPlaypen/ControlFlowPlaypen.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/ControlFlowPlaypen/ReadMe.txt b/ControlFlowPlaypen/ReadMe.txt new file mode 100644 index 0000000..14045c4 --- /dev/null +++ b/ControlFlowPlaypen/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : ControlFlowPlaypen Project Overview +======================================================================== + +AppWizard has created this ControlFlowPlaypen application for you. + +This file contains a summary of what you will find in each of the files that +make up your ControlFlowPlaypen application. + + +ControlFlowPlaypen.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +ControlFlowPlaypen.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +ControlFlowPlaypen.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named ControlFlowPlaypen.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/ControlFlowPlaypen/stdafx.cpp b/ControlFlowPlaypen/stdafx.cpp new file mode 100644 index 0000000..ee13bc2 --- /dev/null +++ b/ControlFlowPlaypen/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// ControlFlowPlaypen.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/ControlFlowPlaypen/stdafx.h b/ControlFlowPlaypen/stdafx.h new file mode 100644 index 0000000..7c7879b --- /dev/null +++ b/ControlFlowPlaypen/stdafx.h @@ -0,0 +1,12 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include +#include +#include +using namespace std; +// TODO: reference additional headers your program requires here diff --git a/OOPlaypen/Address.h b/OOPlaypen/Address.h new file mode 100644 index 0000000..0a2d2ec --- /dev/null +++ b/OOPlaypen/Address.h @@ -0,0 +1,12 @@ +#pragma once +class Address +{ +public: + int house_number; + string street_name; + string city; + Address(const int &house_number, const string &street_name, const string &city) + :house_number(house_number), street_name(street_name), city(city) + { + } +}; diff --git a/OOPlaypen/Employee.cpp b/OOPlaypen/Employee.cpp new file mode 100644 index 0000000..85fc50c --- /dev/null +++ b/OOPlaypen/Employee.cpp @@ -0,0 +1,4 @@ +#include "stdafx.h" +#include "Address.h" +#include "Person.h" +#include "Employee.h" \ No newline at end of file diff --git a/OOPlaypen/Employee.h b/OOPlaypen/Employee.h new file mode 100644 index 0000000..78c8f80 --- /dev/null +++ b/OOPlaypen/Employee.h @@ -0,0 +1,13 @@ +#pragma once +#include "Person.h" +class Employee : + public Person +{ +public: + Employee(int age, string const &name, int sex, string department = string()) + : Person(age, name, sex), department(department) + { + } + string department; + int taxId; +}; diff --git a/OOPlaypen/OOPlaypen.cpp b/OOPlaypen/OOPlaypen.cpp new file mode 100644 index 0000000..cebd9e6 --- /dev/null +++ b/OOPlaypen/OOPlaypen.cpp @@ -0,0 +1,32 @@ +// OOPlaypen.cpp : Defines the entry point for the console application. +// +#include "stdafx.h" +#include "Address.h" +#include "Person.h" +#include "Employee.h" + +int main() +{ + Person p(22, "jane", 0); + Person *p2 = new Person(25, "Tommy", 1); + + Person *p3 = new Person(25, "tommy", 1, 22, "123 fake street", "fake city"); + p3->greet(); + + cout << "le" << Person::getLifeExpectancy(); + delete p2; + delete p3; + Person P5 = *p3; + + Employee e(33, "chris", Person::male, "dep"); + auto u = [](const Person& p) + { + cout << p.name << endl; + }; + u(e); + Person &pr = e; + Employee& er = static_cast(pr); + + getchar(); + return 0; +} \ No newline at end of file diff --git a/OOPlaypen/OOPlaypen.vcxproj b/OOPlaypen/OOPlaypen.vcxproj new file mode 100644 index 0000000..9d0be52 --- /dev/null +++ b/OOPlaypen/OOPlaypen.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A} + Win32Proj + OOPlaypen + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/OOPlaypen/OOPlaypen.vcxproj.filters b/OOPlaypen/OOPlaypen.vcxproj.filters new file mode 100644 index 0000000..091f89c --- /dev/null +++ b/OOPlaypen/OOPlaypen.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/OOPlaypen/Person.cpp b/OOPlaypen/Person.cpp new file mode 100644 index 0000000..2195bc6 --- /dev/null +++ b/OOPlaypen/Person.cpp @@ -0,0 +1,51 @@ +#include "stdafx.h" +#include "Person.h" +#include "Address.h" +Person::Person(const Person & p) + :age(p.age), name(p.name), sex(p.sex) +{ + auto* a = p.address; + address = new Address( + a->house_number, + a->street_name, + a->city); +} +Person::Person(int age, string name, int sex) + :age(age), name(name), sex(sex) +{ + address = nullptr; +} + +Person::Person(int age, string name, int sex, int houseNumber, string streetName, string city) + : Person(age, name, sex) +{ + if (address != nullptr) + { + delete address; + } + address = new Address(houseNumber, streetName, city); +} + +Person::~Person() +{ + if (address != nullptr) + { + delete address; + address = nullptr; + } +} + +int Person::getLifeExpectancy() +{ + return Person::lifeExpetancy; +} + +void Person::greet() +{ + cout << "My name is " << this->name << " and I am " << this->age << endl; + if (address) + { + cout << "I live at " << address->house_number << " " << address->city << endl; + } +} +int Person::lifeExpetancy = 80; \ No newline at end of file diff --git a/OOPlaypen/Person.h b/OOPlaypen/Person.h new file mode 100644 index 0000000..d32927f --- /dev/null +++ b/OOPlaypen/Person.h @@ -0,0 +1,20 @@ +#pragma once +#include "Address.h" +class Person +{ +public: + Person(const Person &p); + Person(int age, string name, int sex); + Person(int age, string name, int sex, int houseNumber, string streetName, string city); + ~Person(); + int age; + string name; + int sex; + Address *address; + const static int female = 0; + const static int male = 1; + static int lifeExpetancy; + + static int getLifeExpectancy(); + void greet(); +}; diff --git a/OOPlaypen/ReadMe.txt b/OOPlaypen/ReadMe.txt new file mode 100644 index 0000000..1191e2b --- /dev/null +++ b/OOPlaypen/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : OOPlaypen Project Overview +======================================================================== + +AppWizard has created this OOPlaypen application for you. + +This file contains a summary of what you will find in each of the files that +make up your OOPlaypen application. + + +OOPlaypen.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +OOPlaypen.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +OOPlaypen.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named OOPlaypen.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/OOPlaypen/stdafx.cpp b/OOPlaypen/stdafx.cpp new file mode 100644 index 0000000..2aacb5e --- /dev/null +++ b/OOPlaypen/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// OOPlaypen.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/OOPlaypen/stdafx.h b/OOPlaypen/stdafx.h new file mode 100644 index 0000000..739bb13 --- /dev/null +++ b/OOPlaypen/stdafx.h @@ -0,0 +1,13 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include +#include +#include + +using namespace std; +// TODO: reference additional headers your program requires here diff --git a/cpptutorial.sln b/cpptutorial.sln index d6433d0..dc80172 100644 --- a/cpptutorial.sln +++ b/cpptutorial.sln @@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cppconsumer", "cppconsumer\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playpen", "playpen\playpen.vcxproj", "{B7BA00F5-5C2A-4AC7-850D-F4236379927E}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ControlFlowPlaypen", "ControlFlowPlaypen\ControlFlowPlaypen.vcxproj", "{F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OOPlaypen", "OOPlaypen\OOPlaypen.vcxproj", "{1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -78,6 +82,26 @@ Global {B7BA00F5-5C2A-4AC7-850D-F4236379927E}.Release|x64.Build.0 = Release|x64 {B7BA00F5-5C2A-4AC7-850D-F4236379927E}.Release|x86.ActiveCfg = Release|Win32 {B7BA00F5-5C2A-4AC7-850D-F4236379927E}.Release|x86.Build.0 = Release|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Debug|x64.ActiveCfg = Debug|x64 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Debug|x64.Build.0 = Debug|x64 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Debug|x86.ActiveCfg = Debug|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Debug|x86.Build.0 = Debug|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Release|Any CPU.ActiveCfg = Release|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Release|x64.ActiveCfg = Release|x64 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Release|x64.Build.0 = Release|x64 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Release|x86.ActiveCfg = Release|Win32 + {F8EF7A4C-3BC4-4E8A-AA0B-DE7067605DF5}.Release|x86.Build.0 = Release|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Debug|x64.ActiveCfg = Debug|x64 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Debug|x64.Build.0 = Debug|x64 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Debug|x86.ActiveCfg = Debug|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Debug|x86.Build.0 = Debug|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Release|Any CPU.ActiveCfg = Release|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Release|x64.ActiveCfg = Release|x64 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Release|x64.Build.0 = Release|x64 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Release|x86.ActiveCfg = Release|Win32 + {1269F55C-C04E-4E06-BC97-B1C3A3B6A20A}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE