summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-02-12 15:20:36 -0500
committerMichael Abed <michaelabed@gmail.com>2012-02-12 15:20:36 -0500
commit986e3aa56c96097bb6993e48859ea6540e9ad7cc (patch)
tree9d406e9a2a90e3af396c31603c7fa38294628451
parent0e81d872502c86f061cf9003b77ac5b0abdabcba (diff)
downloadec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.tar.gz
ec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.tar.bz2
ec327-lab1-986e3aa56c96097bb6993e48859ea6540e9ad7cc.zip
Comment things and add headings
-rw-r--r--Q1.cpp16
-rw-r--r--Q2.cpp18
-rw-r--r--Q3.cpp7
3 files changed, 33 insertions, 8 deletions
diff --git a/Q1.cpp b/Q1.cpp
index 0e26609..5736094 100644
--- a/Q1.cpp
+++ b/Q1.cpp
@@ -1,3 +1,10 @@
+/*
+ * Michael Abed <mgabed@bu.edu>
+ *
+ * Lab 1 Problem 1
+ *
+ * Compare area of 2 triangles
+ */
#include <iostream>
@@ -7,14 +14,15 @@ int main()
double t1b, t1h, t2b, t2h; // base and height of triangle 1 and 2
cout << "Enter the information for the first triangle:" << endl;
- do {
+ // make sure valid things are entered
+ do { // triangle 1 base
cout << "Base: ";
cin >> t1b;
if (t1b - (int)t1b != 0 || t1b <= 0)
cout << "Please enter a positive integer" << endl;
} while (t1b <= 0 || t1b - (int)t1b != 0);
- do {
+ do { // triangle 1 height
cout << "Height: ";
cin >> t1h;
if (t1h - (int)t1h != 0 || t1h <= 0)
@@ -23,14 +31,14 @@ int main()
cout << "Second Triangle:" << endl;
- do {
+ do { // triangle 2 base
cout << "Base: ";
cin >> t2b;
if (t2b - (int)t2b != 0 || t2b <= 0)
cout << "Please enter a positive integer" << endl;
} while (t2b <= 0 || t2b - (int)t2b != 0);
- do {
+ do { // triangle 2 height
cout << "Height: ";
cin >> t2h;
if (t2h - (int)t2h != 0 || t2h <= 0)
diff --git a/Q2.cpp b/Q2.cpp
index 255b7f8..20e8d4a 100644
--- a/Q2.cpp
+++ b/Q2.cpp
@@ -1,3 +1,10 @@
+/*
+ * Michael Abed <mgabed@bu.edu>
+ *
+ * Lab 1 Problem 2
+ *
+ * Convert units between pints, liters, and cups
+ */
#include <iostream>
@@ -5,6 +12,8 @@ using namespace std;
int main()
{
+ // the order here corresponds to the number that gets entered by the user
+ // it's just what needs to be multiplied by to get the corresonding unit
double conversion[10] = {0.47317, 2, 0.5, 0.23659, 2.1134, 4.2268};
unsigned short sel;
double amount;
@@ -16,15 +25,15 @@ int main()
cout << "Liters to Pints (enter 4)" << endl;
cout << "Liters to Cups (enter 5)" << endl;
- do {
+ do { // figure out operation
cout << "?: ";
cin >> sel;
if (sel > 5)
cout << "Enter a number between 0 and 5" << endl;
} while (sel > 5);
- do {
- switch (sel) {
+ do { // validate input
+ switch (sel) { // decide how to prompt
case 0: // fallthrough
case 1:
cout << "Enter the amount in Pints: ";
@@ -44,7 +53,8 @@ int main()
} while (amount < 0);
double result = conversion[sel] * amount;
- switch (sel) {
+
+ switch (sel) { // show the output
case 0:
cout << amount << " Pints is " << result << " Liters" << endl;
break;
diff --git a/Q3.cpp b/Q3.cpp
index 17f385a..e8d350c 100644
--- a/Q3.cpp
+++ b/Q3.cpp
@@ -1,3 +1,10 @@
+/*
+ * Michael Abed <mgabed@bu.edu>
+ *
+ * Lab 1 Problem 3
+ *
+ * Calculate hamming distance between 2 decimal numbers
+ */
#include <iostream>