0% found this document useful (0 votes)
22 views

Assignment 2 of OOP

Uploaded by

coolbandtg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 2 of OOP

Uploaded by

coolbandtg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Syed Maaz Ahmed 2023F-BIT-023

SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY


COMPUTER SCIENCE & INFORMATION TECHNOLOGY DEPARTMENT
Spring 2024

Object Oriented Programming (CS-127)

Assignment 2

Semester: II Batch: 2023F


Due Date: 28th June 2024 Max Marks: 4

Instruction:
Attempt all questions

[Question-1]

a) Write a C# program that takes an integer array {10, 20, 50, 110, 90, 30, 100, 40, 80, 70} and
asks user to enter a number to be searched in the given array. Use linear search algorithm.

Code:

Output:

b) Write down main code snippets to accomplish the following tasks using sorting/searching
built-in C# algorithms.
i. The Data are string [ ] names = {"Olive", "Patty", "Richard", "Ned", "Mindy",
"Pakistan", "Karachi"}; Write C# binary Search algorithm.

Page 1 of 5
Syed Maaz Ahmed 2023F-BIT-023

Code:

Output:

ii. Sorting the given string as Alphabetical (Dictionary type) order by using C# sorting
algorithm.
Code:

Output:

iii. Sorting given string as descending order by using C# reverse sorting algorithm.

Page 2 of 5
Syed Maaz Ahmed 2023F-BIT-023

Code:

Output:

[Question-2]

Create a base class, cell phone and derive a class smartphone from it. In cell phone, create protected
string member category, and a public method ringing() that outputs a text message like this: "ringing
the < category >”. In smartphone the constructor should set the category to "Smart ". In the run()
method, call ringing() on the smartphone to test the inheritance.
Code:

Page 3 of 5
Syed Maaz Ahmed 2023F-BIT-023

Output:

a) Extent Q2 override the ringing() method in smartphone class to display a different message.

Code:

Output:

b) Change the cell phone class to abstract, and make ringing() an abstract method . Derive three
new classes from cell phone: android phone, windows phone and iOS phone. Each derived
class should set the category and override the ringing() method.

Page 4 of 5
Syed Maaz Ahmed 2023F-BIT-023

Code:

Output:

Page 5 of 5

You might also like