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

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

Cs411 Assignment 1 2025 Correct Solution-1-1

The assignment requires creating an object-oriented program to represent various geometric shapes using a base class 'Shape' and derived classes 'Circle', 'Square', and 'Triangle'. Each class must implement a Display() method that outputs a specific message indicating the shape type. The main application initializes an array of shape objects and demonstrates polymorphism by calling the Display() method for each shape, while also displaying the student's ID at the beginning.

Uploaded by

saminarani4595
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)
23 views3 pages

Cs411 Assignment 1 2025 Correct Solution-1-1

The assignment requires creating an object-oriented program to represent various geometric shapes using a base class 'Shape' and derived classes 'Circle', 'Square', and 'Triangle'. Each class must implement a Display() method that outputs a specific message indicating the shape type. The main application initializes an array of shape objects and demonstrates polymorphism by calling the Display() method for each shape, while also displaying the student's ID at the beginning.

Uploaded by

saminarani4595
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

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

You might also like