From 5cc1fc144e14992a53d1e8a57d4b10a42afdd04a Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Wed, 27 Mar 2019 17:24:52 -0500 Subject: Finish Lab 4 --- ee1301/wk5/lab4/arrayCat.cpp | 23 +++++++++++++ ee1301/wk5/lab4/partner3.cpp | 63 +++++++++++++++++++++++++++++++++++ ee1301/wk5/lab4/strap012_lab4_w_2.cpp | 54 ++++++++++++++++++++++++++++++ ee1301/wk5/lab4/swappy.cpp | 24 +++++++++++++ ee1301/wk5/lab4/time1.cpp | 24 +++++++++++++ ee1301/wk5/lab4/time2.cpp | 36 ++++++++++++++++++++ 6 files changed, 224 insertions(+) create mode 100644 ee1301/wk5/lab4/arrayCat.cpp create mode 100644 ee1301/wk5/lab4/partner3.cpp create mode 100644 ee1301/wk5/lab4/strap012_lab4_w_2.cpp create mode 100644 ee1301/wk5/lab4/swappy.cpp create mode 100644 ee1301/wk5/lab4/time1.cpp create mode 100644 ee1301/wk5/lab4/time2.cpp (limited to 'ee1301') diff --git a/ee1301/wk5/lab4/arrayCat.cpp b/ee1301/wk5/lab4/arrayCat.cpp new file mode 100644 index 0000000..1dbcb01 --- /dev/null +++ b/ee1301/wk5/lab4/arrayCat.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +void append (char first[], int l1, char second[], int l2, char result[200]); + +int main () { + char first[] = {'I', ' ', 'a', 'm', ' '}; + char second[] = {'i', 'r', 'o', 'n', 'm', 'a', 'n', '\0'}; + char result[200]; + append(first, 5, second, 8, result); + cout << result << endl; +} + +void append (char first[],int l1, char second[],int l2, char result[200]) { + int length=0; + for (int i=0; i + +using namespace std; + +string requestName(); +double requestHeight(string fullName); +int requestNumberOfPartners(); +void NotinMain(string array1[], double array2[], int numberOfPartners); + +int main() +{ + int numberOfPartners = requestNumberOfPartners(); + string fullName[100]; //fullName1, fullName2; + double height[100]; //height1, height2; + + // fullName[0] = requestName(); + // height[0] = requestHeight(fullName[0]); + for (int i=0; i> 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; + cin.ignore(2, '\n'); + + return numberOfPartners; +} + +void NotinMain(string array1[100], double array2[100], int numberOfPartners) { + double heightTotal=0; + cout << "If " << array1[0]; + for (int i=1; i +using namespace std; + +void bsort(int list[], int length); +void swap (int &a, int &b); +void printArray (int list[], int length); +void makeArray (int list[], int length); +const int n=50; + +int main () { +int list[n]; +makeArray(list,n); +bsort(list, n); +printArray(list, n); +} + +//This function makes the array used for the rest of the program. +void makeArray(int list[], int length) { + int temp=100; + for (int i=0; ilist[j+1]) { + //This is so the bubble can happen + swap(list[j], list[j+1]); + } + } + } +} + +//This function simply swaps two values so the bubbling can commence +void swap (int &a, int &b) { + int temp; + temp=a; a=b; b=temp; +} + +//This function prints the array at 5 per line. +void printArray (int list[], int length) { + int k=0; + for (int j=0; j<(n/10)*2; j++) { + for (int i=0; i<5; i++) { + cout << list[k] << " "; + k++; + } + cout << endl; + } +} diff --git a/ee1301/wk5/lab4/swappy.cpp b/ee1301/wk5/lab4/swappy.cpp new file mode 100644 index 0000000..b697ff5 --- /dev/null +++ b/ee1301/wk5/lab4/swappy.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +void swap (int &a, int &b); +int main(int argc, char* argv[]) { + if (argc !=2) { + cout << "Incorrect number of arguments! USAGE:" << endl + << " swappy " << endl;; + return 3; + } + int i; + for (i=0; i<10000; i++) { + if (argv[1][i]=='\0') { + break; + } + } + swap(argv[1][0],argv[1][(i-1)]); + cout << argv[1] << endl; + +} +void swap (char &a, char &b) { + char temp; + temp=a; a=b; b=temp; +} diff --git a/ee1301/wk5/lab4/time1.cpp b/ee1301/wk5/lab4/time1.cpp new file mode 100644 index 0000000..75c0aab --- /dev/null +++ b/ee1301/wk5/lab4/time1.cpp @@ -0,0 +1,24 @@ +#include +#include + +using namespace std; + +int timeToMinutes(int hours, int mins); +int main() { + int hours, minutes; + char colon, cont = 'y'; + do { + cout << "Enter a time duration (hh:mm) "; + cin >> hours >> colon >> minutes; + cout << "Total minutes: " << timeToMinutes(hours, minutes) << endl; + do { + cout << "Continue? (y/n):"; + cin >> cont; + } while ( !( !(cont!='n') != !(cont!='y') ) ); + //The last logic is a XNOR gate of magic, please do not touch + } while ((cont=='y')); +} + +int timeToMinutes(int hours, int mins) { + return mins + hours * 60; +} diff --git a/ee1301/wk5/lab4/time2.cpp b/ee1301/wk5/lab4/time2.cpp new file mode 100644 index 0000000..e79cd82 --- /dev/null +++ b/ee1301/wk5/lab4/time2.cpp @@ -0,0 +1,36 @@ +#include +#include + +using namespace std; + +void minutesToTime(int minute_value, int& hours, int& mins); +int main() { + int hours, mins; + char cont = 'y'; + do { + cout << "Enter a number of minutes: "; + cin >> mins; + minutesToTime(mins, hours, mins); + cout << hours << ":"; + if (mins<10) { + cout << '0' << mins << endl; + } else { + cout << mins << endl; + } + do { + cout << "Continue? (y/n):"; + cin >> cont; + } while ( !( !(cont!='n') != !(cont!='y') ) ); + //The last logic is a XNOR gate of magic, touching will disturb the magic + } while ((cont=='y')); +} + +void minutesToTime(int minute_value, int& hours, int& mins) { + mins=minute_value%60; + hours=0; + for (int i=minute_value/60; i>0; i--) { + hours++; + if (hours>12) + hours=1; + } +} -- cgit v1.2.3