Practice Question of OOP
Practice Question of OOP
The basic purpose of this lab is to revise some preliminary concepts of C++ that has
been covered in the course of Introduction to Computing and Programming
Objectiv
Fundamentals and Object Oriented Programming.
e
Instructions:
• Indent your code.
• Comment your code.
• Use meaningful variable names.
• Plan your code carefully on a piece of paper before you implement it.
• Name of the program should be same as the task name. i.e. the first program should be
Task_1.cpp
• void main() is not allowed. Use int main()
• You have to work in multiple files. i.e separate .h and .cpp files
• You are not allowed to use system("pause")
• You are not allowed to use any built-in functions
• You are required to follow the naming conventions as follow:
o Variables: firstName; (no underscores allowed)
o Function: getName(); (no underscores allowed)
o ClassName: BankAccount (no underscores allowed)
Pseudo code
Input: An unsorted array, A of N elements
Output: Sorted array, A
For I = 0:N-1
SmallSub = I
For J = I+1:N-1
If A[J] < A[SmallSub]
SmallSub = J
End-If
End-For
Swap ( A[I], A[SmallSub] )
End-For
Linear Search
In computer science, linear search or sequential search is a method for finding
a particular value in a list that consists of checking every one of its elements,
one at a time and in sequence, until the desired one is found.
Pseudo code
Input: An unsorted array, A of N elements and value to be searched
Output: Index of searched element or -1 if not found
For I = 0:N-1
If ( A[I] == Value )
Return [I];
End-if
End-For
return -1;
Binary Search
Binary search is another searching algorithm, used to search a specific value (or index of
value) from the sorted array.
In binary search, we first compare the value to be searched with the item in the middle
position of the array. If there's a match, we can return immediately. If the key is less than
the middle key, then the item sought must lie in the lower half of the array; if it's greater
than the item sought must lie in the upper half of the array. So we repeat the procedure on
the lower (or upper) half of the array.
Pseudo Code
Input: An Sorted array, A of N elements and value to be searched
Output: Index of searched element or -1 if not found
Task 1
Implement the Selection Sort Algorithm with the help of pseudo code given
above.
Task 2
Create a C++ class named Student, with the following private attributes:
1. regNo: char*
2. CGPA: double
Your task is to create an array of 10 Students. Initialize all objects of the array
with different values and perform the following Search algorithms on them on
the basis of CGPA.
a) Linear Search
b) Binary Search
NOTE: In order to perform Binary Search, the array must be sorted. So you
can use your selection sort function implemented in above task for this
purpose.