(Open in Desktop/Laptop/Big Screen for better result.)
Title: A) Design student class, marks class, inherits
it in result class and access it using form. OR
B) Create
a console application for printing result. Create student class, inherit it in
marks class, inherit marks class in result class. (multilevel inheritance).
Theory:
Explain inheritance and its types:
OPEN IMAGE IN NEW TAB FOR BEST RESULT |
Ex.
class A //base class
{
public void eat()
{
return “eating... ”;
}
}
class B:A //derived class
{
public void sleep()
{
return “sleeping... ”;
}
}
2. Hierarchical
inheritance: This is the type in which there are multiple classes derived from one
base class. This type of inheritance is used when there is a requirement of one
class feature that is needed in multiple classes.
Ex:
class A //base class
{
public void eat()
{
return “eating... ”;
}
}
class B:A //derived class
{
public void sleep()
{
return “sleeping... ”;
}
}
class C:A
{
public void drink ()
{
return “drinking....”;
}
}
Ex:
class A //base class
{
public void eat()
{
return “eating... ”;
}
}
class B:A //derived class
{
public void sleep()
{
return “sleeping... ”;
}
}
class C:B
{
public void drink ()
{
return “drinking....”;
}
}
Ex:
interface a // Interface 1
{
Void language();
}
interface b // Interface 2
{
Void course();
}
public c : a,b {
public void languages(){……}
public void courses(){……}
}
using System;
namespace Console_inheritance {
class Student
{
string eno; string name;
public Student()
{
eno = "NULL";
name = "NULL";
}
public Student (string enroll, string rollno)
{
eno = enroll;
name= rollno;
}
public void show()
{
Console.WriteLine("Enrollment number:" + eno);
Console.WriteLine("Name of candidate:" + name);
}
class Marks : Student
{
int sub1, sub2, sub3, total;
public Marks()
{
total = 0;
}
public Marks(string enroll,string rollno,int total1)
: base(enroll,rollno)
{
total = total1;
public void show()
{
base.show();
Console.WriteLine("Total Marks:" + total);
}
public void getdata()
{
sub1 = Int32.Parse(Console.ReadLine());
sub2 = Int32.Parse(Console.ReadLine());
sub3 = Int32.Parse(Console.ReadLine());
}
public void calculate()
{
total = sub1 + sub2+sub3;
}
}
class result : Marks
{
int percentage;
public result()
{
percentage = 0;
}
public result(string enroll, string rollno,
int total1,int per):base(enroll, rollno,total1)
{
percentage = per;
}
public void show()
{
base.show(); Console.WriteLine("Percentage you got:"
+ percentage);
}
}
class Program
{
static void Main(string[] args)
{
m1.show();
}
result m1 = new result("SS19CO055","Rizwan Jamadar",90,85);
Console.ReadKey();
}
}