aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[email protected] <[email protected]>2021-11-09 23:12:15 -0800
committer[email protected] <[email protected]>2021-11-09 23:12:15 -0800
commitaa341a94ac332d0826012084492a351d30dda9e1 (patch)
treef95f9785e9a4005f5f0d384e3365c17031d753d0
parentV2 (diff)
downloadcst116-lab6-rayyanansari03-master.tar.xz
cst116-lab6-rayyanansari03-master.zip
Lab6Ansari Final VersionHEADmaster
-rw-r--r--CST116F2021-Lab6/CST116F2021-Lab6.cpp182
-rw-r--r--CST116F2021-Lab6/LAB6Answers.txt175
2 files changed, 290 insertions, 67 deletions
diff --git a/CST116F2021-Lab6/CST116F2021-Lab6.cpp b/CST116F2021-Lab6/CST116F2021-Lab6.cpp
index 2ba330e..083198e 100644
--- a/CST116F2021-Lab6/CST116F2021-Lab6.cpp
+++ b/CST116F2021-Lab6/CST116F2021-Lab6.cpp
@@ -1,78 +1,126 @@
#include <iostream>
+#include <string>
#include <iomanip>
-using std::cin;
-using std::cout;
-using std::endl;
-using std::setw;
-
-void GetAndDisplayWelcomeInfo();
-void FunctionOne(int varX[], int varY[]);
-void FunctionTwo(int varX[], const int varY[], int varZ[]);
-void PrintFunction(const int varX[], const int varY[],
- const int varZ[]);
-
-const int SIZE = 10;
-
-int main()
-{
- int varX[SIZE];
- 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);
- varZ[0] = -99;
- 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];
+using namespace std;
+bool isPalindrome(char str[100]);
+bool isAlphaStr(char str[100]);
+int countChar(char str[100], char character);
+
+int main() {
+
+ char str1[100];
+ char str2[100];
+ char str3[100];
+ char repeatedletter;
+
+ cout << "Enter word that you would like to count repeated character of: ";
+ cin >> str3;
+ cout << endl;
+ cout << "Enter letter you would like to find: ";
+ cin >> repeatedletter;
+ cout << endl;
+ cout << countChar(str3, repeatedletter);
+
+ cout << endl;
+
+ cout << "ENter word where you want all alphabet: ";
+ cin >> str2;
+ cout << endl;
+
+ if (isAlphaStr(str2) == true) {
+
+ cout << "TRUE";
+
+ }
+
+ else {
+
+
+ cout << "FALSE";
+
+ }
- cout << "\nPlease enter your last name: ";
- cin >> name[1];
+ cout << endl;
+
+
+ cout << "Enter Palindrome word: ";
+ cin >> str1;
- // Breakpoint 2
- // Put breakpoint on the following line
- cout << "\n\n\tWelcome " << name[0] << " " << name[1]
- << "!\n\t Hope all is well \n\n";
+ if (isPalindrome(str1)) {
+
+ cout << "true" << endl;
+
+ }
+ else {
+
+ cout << "false" << endl;
+
+ }
+
+
}
-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;
+
+
+bool isPalindrome(char str[100]) {
+
+ char tempString[100];
+ bool condition = true;
+
+ int j = strlen(str) - 1;
+
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (str[i] != str[j]) {
+
+ condition = false;
+
+ }
+
+ j--;
+
+
+ }
+
+ return condition;
+
+
}
-void FunctionTwo(int varX[], const int varY[], int varZ[])
-{
- varX[1] = 99;
- for (int x = 0; x < SIZE; x++) // Notice the const SIZE here
- varZ[x] = varX[x] + varY[x];
-
+
+
+bool isAlphaStr(char str[100]) {
+
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (!isalpha(str[i])) {
+
+ return false;
+
+ }
+
+ }
+
+ return true;
+
+
}
-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;
+int countChar(char str[100], char character) {
+
+ int amount = 0;
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (str[i] == character) {
+
+ amount++;
+
+ }
+
+
+ }
+
+ return amount;
+
+
} \ No newline at end of file
diff --git a/CST116F2021-Lab6/LAB6Answers.txt b/CST116F2021-Lab6/LAB6Answers.txt
index a93ff77..1e1c990 100644
--- a/CST116F2021-Lab6/LAB6Answers.txt
+++ b/CST116F2021-Lab6/LAB6Answers.txt
@@ -295,3 +295,178 @@ Press any key to close this window . . .
---------------------------------------------------------------
+11c
+10.15 Programming Exercises
+pp 292-293
+10 pts #1
+Submit: code & runs
+
+
+CODE:
+
+#include <iostream>
+#include <string>
+#include <iomanip>
+
+using namespace std;
+bool isPalindrome(char str[100]);
+bool isAlphaStr(char str[100]);
+int countChar(char str[100], char character);
+
+int main() {
+
+ char str1[100];
+ char str2[100];
+ char str3[100];
+ char repeatedletter;
+
+ cout << "Enter word that you would like to count repeated character of: ";
+ cin >> str3;
+ cout << endl;
+ cout << "Enter letter you would like to find: ";
+ cin >> repeatedletter;
+ cout << endl;
+ cout << countChar(str3, repeatedletter);
+
+ cout << endl;
+
+ cout << "ENter word where you want all alphabet: ";
+ cin >> str2;
+ cout << endl;
+
+ if (isAlphaStr(str2) == true) {
+
+ cout << "TRUE";
+
+ }
+
+ else {
+
+
+ cout << "FALSE";
+
+ }
+
+ cout << endl;
+
+
+ cout << "Enter Palindrome word: ";
+ cin >> str1;
+
+ if (isPalindrome(str1)) {
+
+ cout << "true" << endl;
+
+ }
+ else {
+
+ cout << "false" << endl;
+
+ }
+
+
+}
+
+
+bool isPalindrome(char str[100]) {
+
+ char tempString[100];
+ bool condition = true;
+
+ int j = strlen(str) - 1;
+
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (str[i] != str[j]) {
+
+ condition = false;
+
+ }
+
+ j--;
+
+
+ }
+
+ return condition;
+
+
+}
+
+
+bool isAlphaStr(char str[100]) {
+
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (!isalpha(str[i])) {
+
+ return false;
+
+ }
+
+ }
+
+ return true;
+
+
+}
+
+
+int countChar(char str[100], char character) {
+
+ int amount = 0;
+ for (int i = 0; i < strlen(str); i++) {
+
+ if (str[i] == character) {
+
+ amount++;
+
+ }
+
+
+ }
+
+ return amount;
+
+
+}
+
+
+OUTPUT(1):
+
+Enter word that you would like to count repeated character of: Hellooooo
+
+Enter letter you would like to find: o
+
+5
+ENter word where you want all alphabet: hjkdfsn0
+
+FALSE
+Enter Palindrome word: referr
+false
+
+C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 19652) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+OUTPUT(2):
+
+
+Enter word that you would like to count repeated character of: hheeellloooom
+
+Enter letter you would like to find: m
+
+1
+ENter word where you want all alphabet: Hello
+
+TRUE
+Enter Palindrome word: refer
+true
+
+C:\Users\ansar\Source\Repos\cst116-lab6-rayyanansari03-V1\Debug\CST116F2021-Lab6.exe (process 14748) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . .
+
+
+