diff options
| author | till-t <[email protected]> | 2021-11-02 23:19:57 -0700 |
|---|---|---|
| committer | till-t <[email protected]> | 2021-11-02 23:19:57 -0700 |
| commit | efb5378904d824407e24247b19fdeb4f0eea9475 (patch) | |
| tree | 91810de53de404cc3af99144f81e02e5512408e7 | |
| parent | Folder for last lab question. Incomplete. (diff) | |
| download | cst116-lab5-till-t-efb5378904d824407e24247b19fdeb4f0eea9475.tar.xz cst116-lab5-till-t-efb5378904d824407e24247b19fdeb4f0eea9475.zip | |
update
| -rw-r--r-- | mod_10a/source.cpp | 79 | ||||
| -rw-r--r-- | mod_10a/source.h | 13 | ||||
| -rw-r--r-- | mod_10b/main.cpp | 22 | ||||
| -rw-r--r-- | mod_10b/source.cpp | 19 | ||||
| -rw-r--r-- | mod_10b/source.h | 13 |
5 files changed, 77 insertions, 69 deletions
diff --git a/mod_10a/source.cpp b/mod_10a/source.cpp index 442b001..32a1cec 100644 --- a/mod_10a/source.cpp +++ b/mod_10a/source.cpp @@ -1,64 +1,25 @@ -// created by till-t -// 2-nov-2021 -// cst 116 - +/*Tyler Taormina + *CST 116 + * + */ #include "source.h" - // get input for name - -void getName() { - char first[100]{0}; - char last[100]{0}; - cout << "Please enter your first name: "; - cin >> first; - - cout << "Please enter your last name: "; - cin >> last; - - cout << first << ", " << last; - - +void getName(); +{ + char name[50]; + char lastname[50]; + char fullname[100]; // Big enough to hold both name and lastname + + cout<<"Please enter your name: "; + cin.getline ( name, 50 ); + cout<<"Enter your last name: "; + cin.getline ( lastname, 50 ); + fullname[0] = '\0'; // strcat searches for '\0' to cat after + strcat ( fullname, name ); // Copy name into full name + strcat ( fullname, " " ); // We want to separate the names by a space + strcat ( fullname, lastname ); // Copy lastname onto the end of fullname + cout<<"Your full name is "<< fullname <<"\n"; + cin.get(); } - - - -/* - -char first[100]; - char last[100]; - char fullName[100]; - - // void getFirst(char&) - printf("Enter your first name: "); - scanf("%s", first); - while(getchar() != '\n'); // remove new line char - - printf("Enter your last name: "); - scanf("%s", last); - while(getchar() != '\n'); // remove new line char - - first[0] = toupper(first[0]); - last[0] = toupper(last[0]); - - // Now, concat first and last - int i = 0; - int j = 0; - while(last[j] != '\0') { - fullName[i++] = last[j++]; - } - fullName[i++] = ','; - fullName[i++] = ' '; - - j = 0; - while(first[j] != '\0') { - fullName[i++] = first[j++]; - } - fullName[i] = '\0'; - - printf("First name: %s\n", first); - printf("Last name: %s\n", last); - printf("Full name: %s\n", fullName); -*/ - diff --git a/mod_10a/source.h b/mod_10a/source.h index 023c433..ab77514 100644 --- a/mod_10a/source.h +++ b/mod_10a/source.h @@ -1,14 +1,13 @@ -// //Created by Till on 2-Nov-21. // // -#include <iostream> - +#include <iostream> //For cout +#include <cstring> //For the string functions + using namespace std; + +int main(); +getName(); -char first[100]; -char last[100]; - -void getName(); diff --git a/mod_10b/main.cpp b/mod_10b/main.cpp index 489c45a..92605e8 100644 --- a/mod_10b/main.cpp +++ b/mod_10b/main.cpp @@ -1 +1,21 @@ -main +/*Tyler Taormina + * CST 116 + * cStrings problem First/Last name + * + */ + +#include "source.h" + + +int main() +{ + char Firstname = [50]; + char Lname = [50]; + char Fullname= [100]; + + getFullName(Firstname, Lname, Fullname); + + return 0; +} + + diff --git a/mod_10b/source.cpp b/mod_10b/source.cpp index 5a18cd2..3c6b551 100644 --- a/mod_10b/source.cpp +++ b/mod_10b/source.cpp @@ -1 +1,18 @@ -source +/*Tyler Taormina + * Source.cpp + */ +#include "source.h" + +vold getFullName(char& first, char& last, char& full) +{ + cout<<"Please enter your First name: "; + cin.getline ( first, 50 ); + cout<<"Enter your last name: "; + cin.getline ( last, 50 ); + full[0] = '\0'; // strcat searches for '\0' to cat after + strcat ( full, first); // Copy name into full name + strcat ( full, " " ); // We want to separate the names by a space + strcat ( full, last); // Copy lastname onto the end of fullname + cout<<"Your full name is "<< full <<"\n"; + cin.get(); +} diff --git a/mod_10b/source.h b/mod_10b/source.h index 8e83f89..fe51602 100644 --- a/mod_10b/source.h +++ b/mod_10b/source.h @@ -1 +1,12 @@ -header + +#include <iostream> //For cout +#include <cstring> //For the string functions + +using namespace std; + +int main(); +void getFullName(char&, char&, char&); + + + + |