CS411 – Visual Programming
Assignment No. 01 Total Marks: 20
Semester: Spring 2025
Due Date: 2-May-2025
For Paid Assignment 03234131842
Problem Statement:
In the world of geometry, various shapes exist, each with their unique characteristics. This assignment
focuses on creating a structured object-oriented program that represents different types of shapes,
enabling the simulation of their behaviors and properties.
Requirements:
1. Class Structure:
Base Class:
o Create a class named Shape with a virtual method Display() that outputs a
generic message indicating:
" I am a generic shape."
Derived Classes:
o Implement at least three subclasses of Shape:
Circle: Represents circular shapes and overrides the Display() method
with the message:
" I am a circle shape."
Square: Represents square shapes and provides its own implementation of
the Display() method with the message:
" I am a square shape."
Triangle: Represents triangle shapes and customizes the Display()
method with the message:
" I am a triangle shape."
2. Main Application:
Initializes an array of four Shape objects (one for each: base class and its subclasses).
Iterates through the array and calls the Display() method for each shape, demonstrating
polymorphism.
3. Output Requirements:
The output should clearly indicate the type of each shape when the program is run.
Additionally, your student ID should be displayed at the beginning.
All Subject Paid Assignment Available 03234131842 Page 1
Solution
using System;
namespace PaintingManagementSystem // Fixed namespace (removed space)
{
// Base class
class Shape
{
public virtual void Display()
{
Console.WriteLine("I am a generic shape.");
}
}
// Derived class: Circle
class Circle : Shape
{
public override void Display()
{
Console.WriteLine("I am a Circle shape.");
}
}
// Derived class: Square
class Square : Shape
{
public override void Display()
{
Console.WriteLine("I am a Square shape.");
}
}
// Derived class: Triangle (was missing)
class Triangle : Shape
{
public override void Display()
{
Console.WriteLine("I am a Triangle shape.");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("My student Id is BC200417617\n");
// Create and initialize shape array
Shape[] shapeList = new Shape[]
{
new Shape(),
new Circle(),
new Square(),
All Subject Paid Assignment Available 03234131842 Page 2
new Triangle()
};
// Display each shape
foreach (Shape s in shapeList)
{
s.Display();
}
}
}
}
All Subject Paid Assignment Available 03234131842 Page 3