C++ Programming &
Algorithm Challenges
A Practical Session for Undergraduate Computer Science Students
Introduction
Welcome, Future Developers
This session presents three essential programming challenges to reinforce your understanding of C++ fundamentals, string
manipulation, file I/O, and sorting algorithms.
Challenge 1: Password Strength Checker (Logic & Strings)
Challenge 2: File Analysis (File I/O)
Challenge 3: Insertion Sort (Algorithms)
Challenge 1: Password Strength Checker
Your task is to develop a robust C++ program that assesses the security of a user-input password based on essential complexity
criteria.
One Uppercase One Lowercase
At least one capital letter (A-Z). At least one small letter (a-z).
One Digit One Special Character
At least one numeric character (0-9). At least one non-alphanumeric symbol.
Grading the Password Strength
The program must provide feedback by classifying the password into one of
three categories based on how many of the required criteria are met.
Weak
Fails to meet most or all criteria. Requires immediate improvement.
Medium
Meets some criteria, but lacks complexity (e.g., missing special
characters or digits).
Strong
Meets all four mandatory criteria for maximum security.
Challenge 2: Text File Analysis
Develop a C++ application that performs basic text analysis on a user-specified file, demonstrating proficiency in file input/output (I/O)
operations.
Read File Content Count Words
Open and read a text file using C++ streams (e.g., fstream). Implement logic to accurately count the number of words.
Count Characters Display Results
Calculate the total number of characters, including Output both the word count and character count clearly.
whitespace.
File I/O: Key Concepts
Successful execution of Challenge 2 requires a solid grasp of how C++ handles reading external data.
Streams: Understand the difference between ifstream (input file stream)
and ofstream (output file stream).
Error Handling: Check if the file opened successfully before attempting to
read its contents.
Iteration: Use loops (e.g., while (file >> word)) to read data sequentially
from the file until the end-of-file (EOF) is reached.
Challenge 3: Insertion Sort Implementation
Implement the Insertion Sort algorithm in C++ to arrange an array of integers in ascending order. This tests your understanding of
fundamental sorting algorithms.
Pick 2nd Element
Compare Leftward
Shift Larger Right
Insert in Place
Algorithm Requirements
Your Insertion Sort program must be interactive, taking input from the user, and providing clear before-and-after results.
User Input Initial Display
Allow the user to specify the number of elements and then Print the array elements exactly as they were entered (the
input each integer into the array. unsorted state).
Sorting Logic Final Display
Execute the Insertion Sort algorithm effectively, moving Output the array after the sorting process is complete.
elements one by one.
The Principle of Insertion Sort
Insertion Sort is a simple comparison-based sorting algorithm that builds the final sorted array one item at a time. It is efficient for
small data sets or partially sorted arrays.
Imagine sorting a hand of playing cards: you take one card at
a time and insert it into the correct position in your already
sorted hand.
Time Complexity: O(n²) in the worst and average case, but O(n) in the best case (already sorted).
Summary and Acknowledgement
Thank you for engaging with these practical C++ and algorithm challenges. Mastering these topics is crucial for your success in
computer science.
SHARUKESH.R Key Takeaways Next Steps
Roll No: 25BCA149 String and Logic Checks Continue practicing with diverse data
File Handling (I/O) structures and complexity analysis.
Core Algorithms