diff options
Diffstat (limited to 'CST116F2021-Lab6/CST116F2021-Lab6.cpp')
| -rw-r--r-- | CST116F2021-Lab6/CST116F2021-Lab6.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/CST116F2021-Lab6/CST116F2021-Lab6.cpp b/CST116F2021-Lab6/CST116F2021-Lab6.cpp index 4ec4360..50c2ade 100644 --- a/CST116F2021-Lab6/CST116F2021-Lab6.cpp +++ b/CST116F2021-Lab6/CST116F2021-Lab6.cpp @@ -43,6 +43,145 @@ int main() 11b 10.14 pg 289-292 #1 (submit code and runs) +#include <iostream> +#include <iomanip> + +using std::cin; +using std::cout; +using std::endl; +using std::setw; + +void GetAndDisplayWelcomeInfo(); +void FunctionOne(int varX[], int varY[]); +void FunctionTwo(const int varX[], const int varY[], int varZ[]); +void PrintFunction(const int varX[], const int varY[], const int varZ[]); + +const int SIZE = 5; + +int main() +{ + int varX[5]; + int varY[SIZE]; + int varZ[SIZE]; // Notice how we used the const here! + + // Breakpoint 1 + // Put breakpoint on the following line + GetAndDisplayWelcomeInfo(); + FunctionOne(varX, varY); + + // Breakpoint 3 + // Put breakpoint on the following line + FunctionTwo(varX, varY, varZ); + PrintFunction(varX, varY, varZ); + + return 0; +} +void GetAndDisplayWelcomeInfo() +{ + char name[2][20]; // First name in row 0, last name in row 1 + + cout << "Please enter your first name:"; + cin >> name[0]; + cout << "\nPlease enter your last name:"; + cin >> name[1]; + + // Breakpoint 2 + // Put breakpoint on the following line + cout << "\n\n\tWelcome " << name[0] << " " << name[1] + << "!\n\t Hope all is well \n\n"; +} +void FunctionOne(int varX[], int varY[]) +{ + for (int x = 0; x < SIZE; x++) // NOTICE '<' NOT <= + // Breakpoint 4 + // Put breakpoint on the following line + varX[x] = x; + + for (int x = 0; x < 5; x++) + varY[x] = x + 100; +} +void FunctionTwo(const int varX[], const int varY[], int varZ[]) +{ + for (int x = 0; x < SIZE; x++) // Notice the const SIZE here + varZ[x] = varX[x] + varY[x]; +} void +PrintFunction(const int varX[20], const int varY[20], + const int varZ[20]) +{ + int x; + + cout << " \t x \t y \t z\n\n"; + + for (x = 0; x < SIZE; x++) + cout << "\t" << setw(3) << varX[x] + << "\t " << varY[x] + << "\t " << varZ[x] << endl; +} 11c 10.15 pg 292-293 #1 (submit code and runs) + +#include <iostream> + +using namespace std; +bool IsAPalindrome(string cString) { + for (int i = 0; i < cString.length() / 2; i++) + { + if (cString[i] != cString[cString.length() - 1 - i]) + { + return false; + } + } + return true; +} +bool IsAlphaStr(string cString) +{ + for (int i = 0; i < cString.length(); i++) + { + if (!((cString[i] >= 'A' && cString[i] <= 'Z') || (cString[i] >= 'a' && cString[i] <= 'z'))) { + return false; + } + + } + return true; +} +int CountChar(string cString, char ch) +{ + int count = 0; + for (int i = 0; i < cString.length(); i++) + { + if (cString[i] == ch) + { + count++; + } + } + return count; +} +int main() +{ + string s; + cout << "Enter the string: \n\n"; + cin >> s; + if (IsAPalindrome(s)) + { + cout << "\nThis string --" << s << "-- is a palindrome\n" << endl; + } + else + { + cout << "\nThis string --" << s << "-- is not a palindrome\n" << endl; + } + if (IsAlphaStr(s)) + { + cout << "\nThis string --" << s << "-- is an alphabetic\n" << endl; + } + else + { + cout << "\nThe string --"<<s<<"-- is not an alphabetic\n" << endl; + } + char ch; + cout << "\nEnter a character to search for: \n\n"; + cin >> ch; + + cout << "\nNumber of times --"<< ch << "-- has occurred: \n\n" << CountChar(s, ch) << endl; + return 0; +} |