Skip to content

Instantly share code, notes, and snippets.

@abrarShariar
Created July 9, 2017 10:30
Show Gist options
  • Select an option

  • Save abrarShariar/0e2daf06ddb78ea1647a1e3d34a37dbc to your computer and use it in GitHub Desktop.

Select an option

Save abrarShariar/0e2daf06ddb78ea1647a1e3d34a37dbc to your computer and use it in GitHub Desktop.
Lab task 03 for C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Pledge[] pledgeArray = new Pledge[2];
float amount = 0.00f;
pledgeArray[0] = new Pledge(200);
pledgeArray[1] = new SpecialPledge(50);
pledgeArray[0].display();
pledgeArray[1].display();
Console.WriteLine("Enter the pledged amount for Pledge Object ");
amount = float.Parse(Console.ReadLine());
pledgeArray[0].add_pledge(amount);
Console.WriteLine("Enter the pledged amount for Special Pledge Object ");
amount = float.Parse(Console.ReadLine());
pledgeArray[1].add_pledge(amount);
pledgeArray[0].display();
pledgeArray[1].display();
}
}
// pledge class
class Pledge {
private float amt1;
public Pledge() { }
public Pledge(float amt1 = 1.00f) {
this.amt1 = amt1;
}
public virtual void add_pledge(float amt1) {
this.amt1 = amt1;
}
public virtual float get_pledge() {
return this.amt1;
}
public virtual void display(){
Console.WriteLine("Pledge Object");
Console.WriteLine("Pledged Amount $: " + this.amt1);
}
}
class SpecialPledge : Pledge {
private float[] amt2;
public SpecialPledge() { }
public SpecialPledge(float value)
: base(value)
{
this.amt2 = new float[12];
for (int i = 0; i < this.amt2.Length;i++)
{
this.amt2[i] = value;
}
}
//overrids method
public override void add_pledge(float value)
{
Console.WriteLine("Enter Month: ");
int month = int.Parse(Console.ReadLine()) - 1;
this.amt2[month] = value;
}
public override float get_pledge()
{
float grandTotal = 0.00f;
for (int i = 0; i < this.amt2.Length;i++ )
{
grandTotal += this.amt2[i];
}
return grandTotal;
}
public override void display() {
Console.WriteLine("Special Pledge Object ");
for (int i = 0; i < this.amt2.Length;i++ )
{
Console.WriteLine("Pledged Amount for month {0} $: {1}",i+1,this.amt2[i]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment