aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lawrance <[email protected]>2021-11-02 09:40:20 -0700
committerJames Lawrance <[email protected]>2021-11-02 09:40:20 -0700
commitc0b1c4b42c21d6397d95d77d322301f8e8f74f5f (patch)
treea3bd20cddf82b01e90a39e2c183c259d89c057a8
parentMorning Class Changes 10/30/21 up to 10a (diff)
downloadcst116-lab5-jemersonlawrance-c0b1c4b42c21d6397d95d77d322301f8e8f74f5f.tar.xz
cst116-lab5-jemersonlawrance-c0b1c4b42c21d6397d95d77d322301f8e8f74f5f.zip
Lab 5 Completed
-rw-r--r--CST116F2021-Lab5/CST116F2021-Lab5(2).cpp102
-rw-r--r--CST116F2021-Lab5/CST116F2021-Lab5(Header).h15
-rw-r--r--CST116F2021-Lab5/CST116F2021-Lab5.cpp32
-rw-r--r--TextFile1.txt23
4 files changed, 133 insertions, 39 deletions
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp b/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp
index 343789c..20fea9f 100644
--- a/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp
+++ b/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp
@@ -1,42 +1,88 @@
#include "CST116F2021-Lab5(Header).h"
+//10a
+//9.4 Learn by Doing Exercises
+
//function getName definition
-void getName(char first[], char last[])
-{
- cout << "Please enter your first name: ";
- cin >> first;
- cout << "Please enter your last name: ";
- cin >> last;
-}
+//void getName(char first[], char last[])
+//{
+// cout << "Please enter your first name: ";
+// cin >> first;
+// cout << "Please enter your last name: ";
+// cin >> last;
+//}
//function formatName definition
-void formatName(char first[], char last[])
-{
+//void formatName(char first[], char last[])
+//{
//defining local array and counter variable
- char fullName[32] = {};
- int letterCount = 0;
- int letterCountOffset = 0;
+// char fullName[32] = {};
+// int letterCount = 0;
+// int letterCountOffset = 0;
//copy first to fullName character by character
- while (last[letterCount] != '\0')
- {
- fullName[letterCount] = last[letterCount];
- letterCount++;
- letterCountOffset++;
- }
+// while (last[letterCount] != '\0')
+// {
+// fullName[letterCount] = last[letterCount];
+// letterCount++;
+// letterCountOffset++;
+// }
//add comma and space to fullName after first
- fullName[letterCount] = ',';
- letterCount++;
- letterCountOffset++;
+// fullName[letterCount] = ',';
+// letterCount++;
+// letterCountOffset++;
- fullName[letterCount] = ' ';
- letterCount++;
- letterCountOffset++;
+// fullName[letterCount] = ' ';
+// letterCount++;
+// letterCountOffset++;
//copy last to fullName character by character
- while (first[letterCount-letterCountOffset] != '\0')
+// while (first[letterCount-letterCountOffset] != '\0')
+// {
+// fullName[letterCount] = first[letterCount-letterCountOffset];
+// letterCount++;
+// }
+
+// cout << fullName;
+//}
+
+//10b
+//9.5 Learn by Doing Exercises
+
+//function getStrings definition
+void getStrings(char firstString[], char secondString[])
+{
+ //get firstString
+ cout << "Please enter your first string (at least six characters)\n";
+ cin >> firstString;
+ //get secondString
+ cout << "Please enter your second string (at least six characters)\n";
+ cin >> secondString;
+}
+
+//function compareStrings definition
+void compareStrings(char firstString[], char secondString[])
+{
+ //comparison
+ for (int count = 0; count < 5; count++)
+ {
+ if (firstString[count + 1] == '\0' || secondString[count + 1] == '\0')
+ {
+ //error message
+ cout << endl << "ERROR: both strings must be at least six characters.\n";
+ return;
+ }
+ }
+
+ for (int count = 0; count <= 5; count++)
{
- fullName[letterCount] = first[letterCount-letterCountOffset];
- letterCount++;
+ if (firstString[count] != secondString[count])
+ {
+ //different message
+ cout << endl << "The first six characters of your two strings are different.\n";
+ return;
+ }
}
- cout << fullName;
+ //same message
+ cout << endl << "The first six characters of your two strings are the same\n";
+ return;
} \ No newline at end of file
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5(Header).h b/CST116F2021-Lab5/CST116F2021-Lab5(Header).h
index 86cdb62..f6e58d7 100644
--- a/CST116F2021-Lab5/CST116F2021-Lab5(Header).h
+++ b/CST116F2021-Lab5/CST116F2021-Lab5(Header).h
@@ -3,7 +3,18 @@
#include <iostream>
using namespace std;
+//10a
+// 9.4 Learn by Doing Exercises
+
//function getName prototype
-void getName(char first[], char last[]);
+//void getName(char first[], char last[]);
//function formatName prototype
-void formatName(char first[], char last[]); \ No newline at end of file
+//void formatName(char first[], char last[]);
+
+//10b
+//9.5 Learn by Doing Exercises
+
+//
+void getStrings(char firstString[], char secondString[]);
+//
+void compareStrings(char firstString[], char secondString[]); \ No newline at end of file
diff --git a/CST116F2021-Lab5/CST116F2021-Lab5.cpp b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
index c1b57ec..64e6b3e 100644
--- a/CST116F2021-Lab5/CST116F2021-Lab5.cpp
+++ b/CST116F2021-Lab5/CST116F2021-Lab5.cpp
@@ -220,17 +220,33 @@
//}
//10a
-//9.4 Learn by Doing Exercises (this problem will be broken into 3 files)
+//9.4 Learn by Doing Exercises (broken into 3 files)
-int main()
-{
+//int main()
+//{
//defining arrays
- char firstName[15] = {};
- char lastName[15] = {};
+// char firstName[15] = {};
+// char lastName[15] = {};
//get firstName and lastName (call function getName)
- getName(firstName, lastName);
+// getName(firstName, lastName);
//format full name (call function formatName)
- formatName(firstName, lastName);
+// formatName(firstName, lastName);
- return 0;
+// return 0;
+//}
+
+//10b
+//9.5 Learn by Doing Exercises (broken into 3 files)
+
+int main()
+{
+ //defining arrays
+ char firstString[30] = {};
+ char secondString[30] = {};
+ //greeting
+ cout << "Welcome to the string first six character comparison program.\n";
+ //get string inputs (call function getStrings)
+ getStrings(firstString, secondString);
+ //compare string inputs (call function compareStrings)
+ compareStrings(firstString, secondString);
} \ No newline at end of file
diff --git a/TextFile1.txt b/TextFile1.txt
index d8685d7..7ad3903 100644
--- a/TextFile1.txt
+++ b/TextFile1.txt
@@ -74,4 +74,25 @@ Class average: 62.6
Please enter your first name: James
Please enter your last name: Lawrance
-Lawrance, James \ No newline at end of file
+Lawrance, James
+
+10b -
+9.5 Learn by Doing Exercises output 1-
+
+Welcome to the string first six character comparison program.
+Please enter your first string (at least six characters)
+Halloween!
+Please enter your second string (at least six characters)
+Halloween?
+
+The first six characters of your two strings are the same
+
+output 2 -
+
+Welcome to the string first six character comparison program.
+Please enter your first string (at least six characters)
+mmmJames
+Please enter your second string (at least six characters)
+mmmmJames
+
+The first six characters of your two strings are different. \ No newline at end of file