تقرير برمجي باستخدام ++C: التعامل مع السلاسل، المصفوفات، البرمجة الكائنية، وفرز/بحث يدوي
- 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.
- Use of <string> and <algorithm> libraries
- Methods: length(), reverse(), substr()
- 2D array declaration and initialization
- Nested loops
- Precision control with iomanip
- 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.
- Object-Oriented Programming (OOP)
- Encapsulation and data abstraction
- Dynamic arrays using vector
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:
Concepts Applied:
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:
Question 3: Class Implementation – Library Catalog
Two C++ classes were implemented:
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:
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.