about summary refs log tree commit diff
path: root/cpptour
diff options
context:
space:
mode:
Diffstat (limited to 'cpptour')
-rw-r--r--cpptour/README.md10
-rw-r--r--cpptour/Vector-test.cc29
-rw-r--r--cpptour/Vector.cc38
-rw-r--r--cpptour/Vector.h12
-rw-r--r--cpptour/count.cc11
-rw-r--r--cpptour/enumcls.cc28
-rw-r--r--cpptour/helloworld.cc7
-rw-r--r--cpptour/myvec.cc36
-rw-r--r--cpptour/square.cc21
-rw-r--r--cpptour/static-ass.cc8
-rw-r--r--cpptour/veccls.cc32
-rw-r--r--cpptour/vecuser.cc28
-rw-r--r--cpptour/weirdo.cc83
13 files changed, 0 insertions, 343 deletions
diff --git a/cpptour/README.md b/cpptour/README.md
deleted file mode 100644
index b60cb65..0000000
--- a/cpptour/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-A Tour of C++
--------------
-
-These are my draft while following Bjarne Stroustrup tour to learn some C++11.
-Not that I eventually fell for the language, but I did realize that I simply
-cannot evite it forever. In fact, this is the preparation for a Python
-extension.
-
-Since the book is non-free (in either sense), I may not upload it. However,
-one could try to look for it in a *lib*rary. *Gen*erally it's available.
diff --git a/cpptour/Vector-test.cc b/cpptour/Vector-test.cc
deleted file mode 100644
index fbdf129..0000000
--- a/cpptour/Vector-test.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <cassert>
-#include <iostream>
-#include <stdexcept>
-
-#include "Vector.h"
-
-using namespace std;
-
-void
-neg_length ()
-{
-  try { Vector v (-27); }
-  catch (length_error) { cout << "it's alright" << endl; }
-  catch (bad_alloc) { cout << "BIG OOF!" << endl; }
-}
-
-void
-init ()
-{
-  Vector v {7.4, 3.2, 5.2, 6.9, 9.5, 4.2, 21.7};
-  assert(v[5] == 4.2);
-}
-
-int
-main ()
-{
-  neg_length ();
-  init ();
-}
diff --git a/cpptour/Vector.cc b/cpptour/Vector.cc
deleted file mode 100644
index 8f94345..0000000
--- a/cpptour/Vector.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <stdexcept>
-
-#include "Vector.h"
-
-using namespace std;
-
-Vector::Vector (int s)
-{
-  if (s < 0)
-    throw length_error{"You're being negetive!"};
-  elem = new double[s];
-  sz = s;
-}
-
-Vector::Vector (initializer_list<double> lst)
-: elem {new double[lst.size()]}, sz {static_cast<int> (lst.size())}
-{
-  copy(lst.begin(), lst.end(), elem);
-}
-
-Vector::~Vector ()
-{
-  delete[] elem;
-}
-
-int
-Vector::size () noexcept
-{
-  return sz;
-}
-
-double&
-Vector::operator[] (int i)
-{
-  if (i < 0 || size() <= i)
-    throw out_of_range{"Vector::operator[]"};
-  return elem[i];
-}
diff --git a/cpptour/Vector.h b/cpptour/Vector.h
deleted file mode 100644
index 8508503..0000000
--- a/cpptour/Vector.h
+++ /dev/null
@@ -1,12 +0,0 @@
-class Vector {
-public:
-  Vector (int s);
-  Vector (std::initializer_list<double>);
-  ~Vector ();
-  double& operator[] (int i);
-  int size () noexcept;
-  void push_back (double);
-private:
-  double* elem;
-  int sz;
-};
diff --git a/cpptour/count.cc b/cpptour/count.cc
deleted file mode 100644
index a047f04..0000000
--- a/cpptour/count.cc
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-int
-main ()
-{
-  int v[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  for (auto& x : v)
-    cout << x << endl;
-}
diff --git a/cpptour/enumcls.cc b/cpptour/enumcls.cc
deleted file mode 100644
index 2340f65..0000000
--- a/cpptour/enumcls.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-enum class Color { red, blue, green };
-enum class TraficLight { green, yellow, red };
-
-TraficLight& operator++ (TraficLight& t)
-{
-  switch (t)
-    {
-    case TraficLight::green:
-      return t = TraficLight::yellow;
-    case TraficLight::yellow:
-      return t = TraficLight::red;
-    case TraficLight::red:
-      return t = TraficLight::green;
-    }
-}
-
-int
-main ()
-{
-  Color col = Color::red;
-  TraficLight light = TraficLight::red;
-  TraficLight nxt = ++light;
-  // ugh now we test if it compiles? just wanna build some muscle memory
-}
diff --git a/cpptour/helloworld.cc b/cpptour/helloworld.cc
deleted file mode 100644
index 89a7f8a..0000000
--- a/cpptour/helloworld.cc
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <iostream>
-
-int
-main ()
-{
-  std::cout << "Hello, World!" << std::endl;
-}
diff --git a/cpptour/myvec.cc b/cpptour/myvec.cc
deleted file mode 100644
index 1314730..0000000
--- a/cpptour/myvec.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-struct Vector
-{
-  int sz;       // number of elements
-  double* elem; // pointer to elements
-};
-
-void
-vector_init (Vector& v, int s)
-{
-  v.elem = new double[s];
-  v.sz = s;
-}
-
-double
-read_and_sum (int s)
-{
-  Vector v;
-  vector_init (v, s);
-  for (int i = 0; i != s; ++i)
-    cin >> v.elem[i];
-
-  double sum = 0;
-  for (int i = 0; i != s; ++i)
-    sum += v.elem[i];
-  return sum;
-}
-
-int
-main ()
-{
-  cout << read_and_sum (5) << endl;
-}
diff --git a/cpptour/square.cc b/cpptour/square.cc
deleted file mode 100644
index fb14456..0000000
--- a/cpptour/square.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-double
-square (double x)
-{
-  return x * x;
-}
-
-void
-print_square (double x)
-{
-  cout << "the quare of " << x << " is " << square (x) << endl;
-}
-
-int
-main ()
-{
-  print_square (1.234);
-}
diff --git a/cpptour/static-ass.cc b/cpptour/static-ass.cc
deleted file mode 100644
index 837a965..0000000
--- a/cpptour/static-ass.cc
+++ /dev/null
@@ -1,8 +0,0 @@
-constexpr double C = 2999792.458;   // km/s
-
-int
-main ()
-{
-  constexpr double local_max = 160.0 / (60 * 60);
-  static_assert (local_max < C, "can't go that fast");
-}
diff --git a/cpptour/veccls.cc b/cpptour/veccls.cc
deleted file mode 100644
index 0162d23..0000000
--- a/cpptour/veccls.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <iostream>
-
-using namespace std;
-
-class Vector {
-public:
-  Vector (int s) : elem {new double[s]}, sz {s} {}  // construct a Vector
-  double& operator[] (int i) { return elem[i]; }    // random access
-  int size () { return sz; }
-private:
-  double* elem; // pointer to the elements
-  int sz;       // the number of elements
-};
-
-double
-read_and_sum (int s)
-{
-  Vector v (s);
-  for (int i = 0; i != v.size (); ++i)
-    cin >> v[i];
-
-  double sum = 0;
-  for (int i = 0; i != v.size (); ++i)
-    sum += v[i];
-  return sum;
-}
-
-int
-main ()
-{
-  cout << read_and_sum (5) << endl;
-}
diff --git a/cpptour/vecuser.cc b/cpptour/vecuser.cc
deleted file mode 100644
index 0eefb0e..0000000
--- a/cpptour/vecuser.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <cmath>
-#include <iostream>
-#include <stdexcept>
-
-#include "Vector.h"
-
-using namespace std;
-
-double
-sqrt_sum (Vector& v)
-{
-  double sum = 0;
-  for (int i = 0; i <= v.size(); ++i)
-    try { sum += sqrt(v[i]); }
-    catch (out_of_range) { cout << "Yeet!" << endl; }
-  return sum;
-}
-
-int
-main ()
-{
-  int n;
-  cin >> n;
-  Vector v (n);
-  while (n--)
-    cin >> v[n];
-  cout << sqrt_sum (v) << endl;
-}
diff --git a/cpptour/weirdo.cc b/cpptour/weirdo.cc
deleted file mode 100644
index f79336c..0000000
--- a/cpptour/weirdo.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <iostream>
-#include <set>
-#include <stdexcept>
-#include <string>
-#include <unordered_map>
-
-using namespace std;
-
-typedef unordered_map<char, size_t> charmap;
-typedef set<char> charset;
-
-constexpr double INF = 1e7;
-const charset VOWELS {'a', 'e', 'i', 'o', 'u'};
-
-inline size_t
-sqr (size_t i)
-{
-  return i * i;
-}
-
-bool
-isvowel (const string& s, size_t i)
-{
-  try { return VOWELS.count (s.at (i)); }
-  catch (out_of_range const& e) { return true; }
-}
-
-void
-update (const string& s, charmap& x, charmap& f)
-{
-  charset b;
-  for (const auto& c : s)
-    {
-      f[c]++;
-      b.insert (c);
-    }
-  for (const auto& c : b)
-    x[c]++;
-}
-
-int
-main ()
-{
-  size_t t, l;
-  string s;
-
-  cin >> t;
-  while (t--)
-    {
-      charmap xa, fa, xb, fb;
-      cin >> l;
-      while (l--)
-        {
-          cin >> s;
-          size_t i = s.size ();
-          bool a = true;
-
-          while (i--)
-            if (isvowel (s, i - 1) + isvowel (s, i) + isvowel (s, i + 1) < 2)
-              {
-                update (s, xb, fb);
-                a = false;
-                break;
-              }
-          if (a)
-            update (s, xa, fa);
-        }
-
-      double sc = 1.0;
-      for (const auto& p : xa)
-        sc *= p.second;
-      for (const auto& p : fa)
-        sc /= sqr (p.second);
-      for (const auto& p : xb)
-        sc /= p.second;
-      for (const auto& p : fb)
-        sc *= sqr (p.second);
-      if (sc > INF)
-        cout << "Infinity" << endl;
-      else
-        cout << sc << endl;
-    }
-}