C++ Programming Assignment Report: String Manipulation, Arrays, OOP, and Manual Sorting & Searching

Eng. Yasser Al-Bahri

Administrator
طاقم الإدارة
تقرير برمجي باستخدام ++C: التعامل مع السلاسل، المصفوفات، البرمجة الكائنية، وفرز/بحث يدوي


    Introduction

    This report documents the solutions for Assignment #3 in Computer Programming 2.

    The assignment includes three main programming tasks using C++: string operations, array handling, and class-based design (OOP).

    Additionally, it involves sorting and searching techniques using Bubble Sort and Binary Search, which were solved manually.





    Question 1: String Manipulation

    The program performs the following operations:

    • Reads a string from user input.
    • Displays the string's length.
    • Reverses the string.
    • Counts vowels and consonants.
    • Extracts a substring using user-specified indices.


    Concepts Applied:

    • Use of <string> and <algorithm> libraries
    • Methods: length(), reverse(), substr()
    Screenshot of Program Code and Output:
    AD_4nXdznhXsdPUCedg9jWtmplUcvnb6XrtdD92xXAcum6HH0YI0CKJLLAiWmiv2HY_akgsZdQMAWt1FGX5K01GZkU1tFZgJc0jwlp1HFIsgaP3j-VWo5qPZ7k2u_PN7ayI5TouIkYjv






    Question 2: Arrays and Average Calculation

    The program collects scores for three students in Math, Science, and English, then calculates and displays the average for each subject.

    Concepts Applied:

    • 2D array declaration and initialization
    • Nested loops
    • Precision control with iomanip
    Screenshot of Program Code and Output:


    AD_4nXdE6apVy1Q-y_6vWA0MiEwovub2FX3azSV2uzUBsGer-OMdjP-z2rwgCj4Ku3ml_0dJDQclaAXGVzvZGTII27bzp0_COgEUEYqSvabofeOtFDxNQo5SomBMeh5pr46nig7Un0G71w




    AD_4nXdxwZQKHOmE_d5vGOGwwVO4fKmkufprqP8-0PJZMhvOFpg6Tn4KqmBRlu8XQZeD4BQEQi6iFJoSSETACOFn9iZHD0tmZts24B_bPXW5P6f6i820Qeo_O7tox0vFBYuC_4ki2-P-KQ






    Question 3: Class Implementation – Library Catalog

    Two C++ classes were implemented:

    • Book: Represents a book with ID, title, author, and genre.
    • Catalog: Manages a list of books and allows adding, removing, displaying, and searching books by ID.
    Concepts Applied:

    • Object-Oriented Programming (OOP)
    • Encapsulation and data abstraction
    • Dynamic arrays using vector
    Screenshot of Program Code and Output:
    AD_4nXcM3wA1nagfNr7k0jyTIiRyhcPhr2Gi9e-oKLXM42yNpUQxAQcnJE-4LUUIxcTygraLyDyk046ptTRnnTkvR72hJdNl0dx0VICRzX22pdBuOLVUr6F7PlSgC1F4fOTgd5rSByzA


    AD_4nXeYlJwh613nD3nPR-7QWdDxRy42Yz4BCE-CL14lRWy8KGt7Cmvk0fsnxHI_Bk47V9QOW_4HhfRfFlNFJT7rGPI_AY4VDGjnRDzzBKLm23I4p_aqglwNVAd0L4jw-URoCZGq5NFG


    AD_4nXcXwzAmQcnG7yPNSzoOfA3W7kTR-bXzwsdGDgBAmpFP69lQ5auEOlvGxvq7gaSpTQa5T0es0IKu09jwY6XgOeDO-4Ph1xg43YFXdD5L_ht2q7uuKoyy7YTv4EzFy338TSx2Rzao








    Part 2: Manual Sorting & Searching

    a) Bubble Sort

    The array was sorted manually using the Bubble Sort algorithm.
    The number of iterations, comparisons, and swaps were recorded.

    b) Binary Search

    Binary Search was used to find the target number 60 after sorting the array.






    Handwritten Calculations for Bubble Sort and Binary Search:








    🟦 Conclusion

    The assignment provided a hands-on experience in core C++ programming techniques, such as handling strings and arrays, applying sorting and searching logic, and developing modular class-based systems.

    The implementation and manual parts together reinforced both practical and theoretical skills essential for a strong foundation in programming.




 
عودة
أعلى