From 42cd39b0f8ddda09c3d4bb590f61450bf6c2b0f5 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Wed, 27 Mar 2019 12:33:52 -0500 Subject: Post-Spring Lab --- ee1301/wk5/lab4/mysteryBox.cpp | 18 +++++++++++++++ ee1301/wk5/lab4/partner.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ ee1301/wk5/lab4/partner2.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 ee1301/wk5/lab4/mysteryBox.cpp create mode 100644 ee1301/wk5/lab4/partner.cpp create mode 100644 ee1301/wk5/lab4/partner2.cpp diff --git a/ee1301/wk5/lab4/mysteryBox.cpp b/ee1301/wk5/lab4/mysteryBox.cpp new file mode 100644 index 0000000..4737fdd --- /dev/null +++ b/ee1301/wk5/lab4/mysteryBox.cpp @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +bool mystery(string fstr); +int main () { + string e = "Sargent Pepper's Lonely Hearts Club Band"; + cout << mystery(e) << endl; +} + +bool mystery(string fstr) { + string rstr; // a string is like an array of chars, e.g., char[] + for(int i=fstr.length()-1; i>=0 ;i--){ + rstr += fstr[i]; // fstr[i] gets the char at index i + } + cout << fstr << endl << rstr << endl; + return rstr == fstr; +} diff --git a/ee1301/wk5/lab4/partner.cpp b/ee1301/wk5/lab4/partner.cpp new file mode 100644 index 0000000..3313e8c --- /dev/null +++ b/ee1301/wk5/lab4/partner.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +string requestName(); +double requestHeight(string fullName); +int requestNumberOfPartners(); + + +int main() +{ + string fullName[2]; //fullName1, fullName2; + double height[2]; //height1, height2; + + fullName[0] = requestName(); + height[0] = requestHeight(fullName[0]); + fullName[1] = requestName(); + height[1] = requestHeight(fullName[1]); + + cout << "If " << fullName[0] << " and " << fullName[1] + << " form a human tower, their combined height will be " + << (height[0] + height[1]) << endl; + +} + +string requestName() +{ + string name; + cout << "Please enter full name: "; + getline(cin, name); + return name; +} + +double requestHeight(string fullName) +{ + double height; + cout << "Please enter " << fullName << "'s height: "; + cin >> height; + cin.ignore(2, '\n'); // gets rid of \n in the buffer + + return height; +} + +int requestNumberOfPartners() +{ + int numberOfPartners; + cout << "How many partners are there?"; + cin >> numberOfPartners; + + return numberOfPartners; +} + diff --git a/ee1301/wk5/lab4/partner2.cpp b/ee1301/wk5/lab4/partner2.cpp new file mode 100644 index 0000000..3313e8c --- /dev/null +++ b/ee1301/wk5/lab4/partner2.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +string requestName(); +double requestHeight(string fullName); +int requestNumberOfPartners(); + + +int main() +{ + string fullName[2]; //fullName1, fullName2; + double height[2]; //height1, height2; + + fullName[0] = requestName(); + height[0] = requestHeight(fullName[0]); + fullName[1] = requestName(); + height[1] = requestHeight(fullName[1]); + + cout << "If " << fullName[0] << " and " << fullName[1] + << " form a human tower, their combined height will be " + << (height[0] + height[1]) << endl; + +} + +string requestName() +{ + string name; + cout << "Please enter full name: "; + getline(cin, name); + return name; +} + +double requestHeight(string fullName) +{ + double height; + cout << "Please enter " << fullName << "'s height: "; + cin >> height; + cin.ignore(2, '\n'); // gets rid of \n in the buffer + + return height; +} + +int requestNumberOfPartners() +{ + int numberOfPartners; + cout << "How many partners are there?"; + cin >> numberOfPartners; + + return numberOfPartners; +} + -- cgit v1.2.3