From 986e3aa56c96097bb6993e48859ea6540e9ad7cc Mon Sep 17 00:00:00 2001 From: Michael Abed Date: Sun, 12 Feb 2012 15:20:36 -0500 Subject: Comment things and add headings --- Q1.cpp | 16 ++++++++++++---- Q2.cpp | 18 ++++++++++++++---- Q3.cpp | 7 +++++++ 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 + * + * Lab 1 Problem 1 + * + * Compare area of 2 triangles + */ #include @@ -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 + * + * Lab 1 Problem 2 + * + * Convert units between pints, liters, and cups + */ #include @@ -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 + * + * Lab 1 Problem 3 + * + * Calculate hamming distance between 2 decimal numbers + */ #include -- cgit v1.2.3-54-g00ecf