Posts

Showing posts from 2019

Temporary Change of Course Focus

The CPPForSchool website has been a great learning tool for me.  At this time, I have made it to the halfway point of the C++ Lab Assignments , specifically completing String Set-1.  However, I cannot move forward as the course material has become quite unfamiliar to my current comprehension of arrays in C++.  Upon skimming the Array - Two Dimension Set-1 assignments, I realized that I will need to go back and review in order to move forward.  With that said, I will be utilizing a book by Bjarne Stroustrup, Programming Principles and Practice Using C++ . During my off time, I have been skimming through this book and I have found it to be very useful in regards to reinforcing prior knowledge.  Now that I have come to a crawling pace, I will now utilize it as it was originally intended.  At this time, I am not sure if I will blog about the practice programs from this book, but if I find it to be insightful, it will make it onto the blog.  For now, it i...

CPPForSchool.com: String Set 1 Assignment 12

12. Write the output of the following program int main() { char name[] = "CoMPutER"; for (int x = 0; x < strlen(name); x++) if (islower(name [x])) name [x] = toupper(name[x]); else if (isupper(name[x])) if (x % 2 == 0) name[x] = tolower(name[x]); else name[x] = name[x-1]; cout << name; return 0; } --------------------------------------------- cOmmUTee

CPPForSchool.com: String Set 1 Assignment 11

11. Write the output of the following program. Assume that all necessary header files are included. void Encrypt(char T[]) { for (int i = 0; T[i] != '\0'; i += 2) if (T[i] == 'A' || T[i] == 'E') T[i] = '#'; else if (islower(T[i])) T[i] = toupper(T[i]); else T[i] = '@'; } int main() { char text[]="SaVE EArtH"; Encrypt(text); cout << text << endl; return 0; } -------------------------------------------------- @a@E@E#rTH

CPPForSchool.com: String Set 1 Assignment 10

Image
10. Write a program to convert a string in uppercase. This assignment was not too difficult.  It became very obvious that I just had to modify Assignment 9 to an uppercase algorithm.  Instead of the algorithm checking for uppercase characters, I changed it to lowercase characters and subtracted 32 instead of adding.  Nevertheless, this was a good learning experience because I am now able to convert strings without using islower, isupper, tolower, or toupper.  Granted, I am not sure how truly impactful it will be to the performance, but it is nice to know that I have options. Below is my source code and output.  Also, I have included the sample source and output.

CPPForSchool.com: String Set 1 Assignment 9

Image
9. Write a program to convert a string in lowercase. Originally, I was going to code this assignment using the "isupper" and "tolower" functions using the string library.  However, that would not have been indicative of the assignment and tutorials.  With that said, I went ahead and analyzed the course tutorial and coded the assignment accordingly.  Admittedly, I am not 100% sure of what is occurring with the algorithm, but from what I understand it checks to see if the character set contains uppercase ASCII values.  From there, it converts each letter accordingly.

CPPForSchool.com: String Set 1 Assignment 8

Image
8. Write a program to reverse a string. At a glance, this task appears to be something I have already completed in a prior assignment.  However, after further examination, I quickly discovered that there is another way to accomplish this task.  Originally, I created a function that mimicked the tutorials, but I found that it would not be able to accomplish this particular task.  Admittedly, I was quite lost so I went ahead and began reviewing the sample source code.  Below is my rendition of the source code.

CPPForSchool.com: String Set 1 Assignment 7

Image
7. Write a program to find a substring within a string. If found display its starting position. This assignment had me quite clueless as how to create a substring within a string.  With that said, I searched online for examples and began coding accordingly.  However, after reviewing the sample source code, I quickly discovered that I jumped ahead of the curve.  Below is an example of using the string library.  It is important to note that I have updated the program and provided additional screenshots for comparison. For my first attempt, I utilized the example from GeeksForGeeks .  Ultimately, the user will need to input two words separated by a colon.  From there, the program will locate the colon and separate the second word into its own variable, in this case "sub". In regards to using external libraries, I have become quite fond of the concept.  Anything to get the ball rolling, I guess.  Now, the source code below is ...

CPPForSchool.com: String Set 1 Assignment 6

Image
6. Write a program to check a string is palindrome or not. According to Merriam Webster's Online Dictionary : Palindrome: a word, verse, or sentence, or a number that reads the same backward or forward. For example: 1881, madam, "Able was I ere I saw Elba" This assignment was quite the eye opener.  My original approach was to place the string in backwards order within a separate string and then compare values.  Unfortunately, it did not work.  Concept wise, it seemed like a solid approach.  However, when practiced, it appears that there are some additional hurdles to overcome.  Nevertheless, the first set of screenshots demonstrates my first source code and output, which shows the downfall of the approach.  For some reason, when the second string array acquired the same characters, there seems to be some additional artifacts that comes along with it.  This results in a false interpretation of the contents of the string array. ...

CPPForSchool.com: String Set 1 Assignment 5

Image
5. Write a program to compare two strings they are exact equal or not. Strings are quite interesting to me because they are essentially just arrays with characters instead of numbers.  Nevertheless, I utilized the code from prior exercises along with creating an if/else condition to determine whether if the values in both character strings are the same.  Below is my source code and output.  For comparison, I have also included the sample source and output.

CPPForSchool.com: String Set 1 Assignment 4

Image
4. Write a program to concatenate one string contents to another. This assignment was quite puzzling at first.  However, after reviewing the string tutorials, I was able to get things moving in the correct direction.  Below is my source code and output.  I've also included the sample source code and output.

CPPForSchool.com: String Set 1 Assignment 3

Image
3. Write a program to count number of words in string. Like the past two assignments, this heavily depends on the prior tasks.  Nevertheless, the approach to finding each word is to locate the spaces between them.  This program worked as expected.  It is very exciting to see programs work after tirelessly learning as much about C++.

CPPForSchool.com: String Set 1 Assignment 2

Image
2. Write a program to display string from backward. This assignment was built upon the prior task of counting characters in a string.  From there, I had to utilize the algorithm provided within the tutorials.  Nevertheless, I am extremely happy with the outcome.  It works!  Ultimately, the program firsts determines the length of the string array, followed by printing the array counting from right to left.  This was accomplished by subtracting one from the length with each pass.

CPPForSchool.com: String Set 1 Assignment 1

Image
1. Write a program to find the length of string. This assignment was a lot of fun.  I was able to code it rather quickly.  It was quite interesting to utilize "cin.getline".  It will take getting use to using cin without an immediate set of "<<", but I am sure it comes with the territory.  Below is my source, output, and the sample source/output.

CPPForSchool.com: Array - Single Dimension Set 1 Assignment 9

Image
9. Suppose X. Y, Z are arrays of integers of size M, N, and M + N respectively. The numbers in array X and Y appear in descending order. Write a user-defined function in C++ to produce third array Z by merging arrays X and Y in descending order. For this assignment, I had a lot of trouble setting the algorithms up correctly.  It seemed like every step forward resulted in additional problems.  I eventually had to throw in the towel because I was at a complete loss.  Nevertheless, after reviewing the sample source, I began to truly understand my shortcomings and how to handle this sort of task in the future.  ------------------------------------------------------------------------------------------------------------------------- Sample Source Code ------------------------- #include <iostream> using namespace std ; void Merge ( int A [], int B [], int C [], int N , int M , int & K ); int main () { in...