Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views3 pages

OOP Practical Solutions

The document outlines practical assignments for Object-Oriented Programming (OOP) that include creating Windows form applications, managing arrays, implementing abstract classes, and connecting to a MySQL database. It provides detailed solutions for tasks such as writing and reading from text files, handling user input for deletion in arrays, and utilizing common dialog boxes. Additionally, it covers exception handling in console applications and managing a ListBox for student names with various functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

OOP Practical Solutions

The document outlines practical assignments for Object-Oriented Programming (OOP) that include creating Windows form applications, managing arrays, implementing abstract classes, and connecting to a MySQL database. It provides detailed solutions for tasks such as writing and reading from text files, handling user input for deletion in arrays, and utilizing common dialog boxes. Additionally, it covers exception handling in console applications and managing a ListBox for student names with various functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP Practical - Assignment Solutions

QUESTION 1:
Create a Windows form application to create, write data inputted in a textbox and read from
a text file called 'subjects.txt'. When the read button is clicked, the text will be displayed in a
listbox as shown below. (Use StreamWriter and StreamReader classes)

Solution:
1. Design a form with a textbox for input (label: 'Enter Text'), three buttons: 'Create', 'Write',
and 'Read', and a listbox to display the data.
2. The 'Create' button will trigger creating a 'subjects.txt' file.
3. The 'Write' button will use StreamWriter to write the textbox content to the file.
4. The 'Read' button will use StreamReader to read from the file and display the content in
the listbox.

QUESTION 2:
a) Write a program that creates and loads an array of 10 integer’s numbers and display the
elements. The program will prompt the user to enter a specific integer to delete. After
deletion, display the remaining elements.

Solution:
1. Initialize an array of 10 integers.
2. Create a method to prompt the user for an integer to delete.
3. After deleting the number, display the remaining numbers.

b)
Create an abstract class called 'Shape' that has methods for calculating the area and
perimeter. Create concrete classes called 'Rectangle', 'Square', and 'Circle' that extend the
Shape class and implement the area and perimeter methods.

Solution:
1. Define an abstract class Shape with abstract methods for area and perimeter.
2. Create subclasses 'Rectangle', 'Square', and 'Circle', each implementing the abstract
methods.
3. Each subclass calculates the area and perimeter based on their specific formulas.

QUESTION 3:
Design a Windows forms application to implement the following common Dialog Boxes
using the provided interface:
1. OpenFileDialog
2. SaveFileDialog
3. PrintDialog
4. FontDialog

Solution:
1. Use the respective dialog classes for each function (OpenFileDialog, SaveFileDialog, etc.).
2. Implement buttons for each dialog to interact with the user.
3. Add textboxes for input and implement functionality for opening, saving, printing, and
changing font.

QUESTION 4:
Create a table 'Product' in MySQL. Your table should have the following details: Product
Number, Name, Unit Price.
Create a C# application and connect it to your database. Your application should have the
following buttons: 'Save', 'Exit', 'Add' functionality to your buttons.

Solution:
1. Create a MySQL table with columns: ProductNumber (INT), Name (VARCHAR), UnitPrice
(DECIMAL).
2. Use C# to connect to the database and perform operations like saving data, exiting the
application, and adding records.
3. Create buttons for saving data, exiting, and adding new products to the database.

QUESTION 5:
a) Write a console program that adds and divides two integers entered by the user from the
keyboard using exception handling.Division by zero is mathematically not allowed.

Solution:
1. Create a console application that prompts the user for two integers.
2. Perform addition and division with try-catch blocks for exception handling.
3. Ensure that division by zero is handled properly with an error message.

b)
Use the sample interface below. Write a program with a ListBox containing names of
students. Add five students to the listbox at design time.
The program should enable the user to add more students at runtime via a textbox, clear all
students from the ListBox, count the number of students in the ListBox, and display the
result in a messagebox as well as delete a selected student from the listbox.

Solution:
1. Create a ListBox and initialize it with five student names.
2. Provide a textbox for adding new student names and a button to add them to the list.
3. Implement buttons to count the students, clear the list, and delete a selected student from
the ListBox.

You might also like