C# Practice Exercise On OOP
C# Practice Exercise On OOP
using System;
namespace st
{
class Student
{
private int rollno;
private string name;
private string course;
private int feepaid;
get
{
return TotalFee - feepaid;
}
}
class UseStudent
{
}
}
}
Add a static member to store Service Tax, which is set to 12.3%. Also allow a property
through which we can set and get service tax.
Modify TotalFee and DueAmount properties to consider service tax.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oop1
{
class Student2
{
private int rollno;
private string name;
private string course;
private int feepaid;
get
{
return TotalFee - feepaid;
}
}
class UseStudent2
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace st
{
abstract class Course
{
protected string name;
protected int duration;
protected int coursefee;
class TestCourse
{
}
}
3.) Create an interface called Stack with methods Push(), Pop() and property
Length. Create a class that implements this interface. Use an array to
implement stack data structure.
Create user-defined exceptions and ensure Push() and Pop() methods throw those
exceptions when required.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oop1
{
interface IStack
{
void Push(int v);
int Pop();
int Length { get; }
}
class StackFullException : Exception
{
public StackFullException()
: base("Stack Full")
{
}
}
if (top == 10)
throw new StackFullException();
a[top] = v;
top++;
}
top--;
return a[top];
}
Console.WriteLine(s.Pop());
Console.WriteLine(s.Length);
Console.WriteLine(s.Pop());
}
}
}