Posts

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 ...