Week 2 of My C++ Learning Journey: Advancing with Strings, Bit Manipulation & OOP

Adhyan Jain - Feb 17 - - Dev Community

Another week of coding, another set of challenges! In Week 2, I dived deeper into C++ by exploring advanced topics like strings, bitwise operations, and object-oriented programming (OOP). Each day brought new concepts and problem-solving techniques that strengthened my understanding of C++.


Day 8: Exploring Strings

Strings are an essential part of C++ programming, used for handling text and character data.

๐Ÿš€ Topics Covered:
โœ… Character arrays vs. string class
โœ… String operations (concatenation, comparison, substring)
โœ… String manipulation functions
โœ… String streams

๐Ÿ’ป Key Practice:
๐Ÿ”น Reversed a string
๐Ÿ”น Checked if a string is a palindrome
๐Ÿ”น Counted vowels and consonants
๐Ÿ”น Removed spaces from a string
๐Ÿ”น Found the first non-repeating character


Day 9: Introduction to Bitwise Operations

Bitwise operations allow efficient manipulation of individual bits, which is useful for optimizing performance.

๐Ÿš€ Topics Covered:
โœ… AND, OR, XOR, NOT operators
โœ… Left & Right Shift operations
โœ… Setting, clearing, and toggling bits
โœ… Updating the i-th bit

๐Ÿ’ป Key Practice:
๐Ÿ”น Extracted the i-th bit of a number
๐Ÿ”น Set and cleared specific bits
๐Ÿ”น Toggled bits in an integer
๐Ÿ”น Implemented bitwise tricks for fast computations


Day 10: Advanced Bit Manipulation

Taking bitwise operations further, I explored real-world applications of bit manipulation.

๐Ÿš€ Topics Covered:
โœ… Checking if a number is a power of 2
โœ… Counting set bits efficiently
โœ… Generating subsets using bitwise techniques

๐Ÿ’ป Key Practice:
๐Ÿ”น Counted the number of ones in a binary representation
๐Ÿ”น Generated all subsets of an integer set
๐Ÿ”น Generated all subsets of a character set


Day 11: XOR Properties & Unique Number Problems

XOR operations have powerful applications in finding unique numbers in an array.

๐Ÿš€ Topics Covered:
โœ… XOR properties and their applications
โœ… Finding unique numbers in different scenarios
โœ… Efficiently counting set bits

๐Ÿ’ป Key Practice:
๐Ÿ”น Found a unique number in an array where all others appear twice
๐Ÿ”น Found two unique numbers in an array
๐Ÿ”น Found a unique number where all others appear thrice


Day 12: Structures, Unions, and Enums

Structures and unions help in organizing and optimizing data storage, while enums provide meaningful constants.

๐Ÿš€ Topics Covered:
โœ… Defining and using structures
โœ… Memory efficiency with unions
โœ… Using enums for readability

๐Ÿ’ป Key Practice:
๐Ÿ”น Created an Employee struct and found the highest salary
๐Ÿ”น Demonstrated how unions store different data types
๐Ÿ”น Implemented an enum for days of the week


Day 13: Introduction to Classes & Objects

Classes are the foundation of object-oriented programming in C++.

๐Ÿš€ Topics Covered:
โœ… Defining and using classes
โœ… Object-oriented programming basics
โœ… Access specifiers: public, private, protected

๐Ÿ’ป Key Practice:
๐Ÿ”น Created a Student class with attributes
๐Ÿ”น Implemented a Circle class with a function to calculate area


Day 14: Nesting of Member Functions

I explored function nesting inside classes to enhance encapsulation.

๐Ÿš€ Topics Covered:
โœ… Private member functions
โœ… Nesting functions for better encapsulation
โœ… Oneโ€™s complement operation

๐Ÿ’ป Key Practice:
๐Ÿ”น Validated binary format using a private function
๐Ÿ”น Performed oneโ€™s complement operation
๐Ÿ”น Implemented binary addition using a Binary class


Key Takeaways from Week 2:

๐Ÿ”น Bit manipulation is an incredibly powerful technique for optimizing performance in problem-solving. If you understand the logic you'll find it much better than normal way of solving a problem. Though it was a bit tough understanding the concepts I am sure it would be useful later on.
๐Ÿ”น OOP concepts like classes and structures help in writing organized and maintainable code.
๐Ÿ”น Strings and their operations are fundamental to text processing in C++.

Whatโ€™s Next?

Next Iโ€™ll explore dynamic memory allocation, inheritance, and polymorphism to deepen my OOP understanding.

Learning C++ has been an exciting journey so far, and Iโ€™m eager to keep pushing forward! Let me know your thoughtsโ€”how do you approach these concepts in C++? ๐Ÿš€

. . . . . . . . .