0% found this document useful (0 votes)
7 views2 pages

nt106 Lab

The document presents a C# program that defines a base class 'SinhVien' for student information, including methods for inputting and displaying student data. It also includes two derived classes, 'SinhVienMMT' and 'SinhVienATTT', which override methods to calculate and display average scores differently. The main program creates instances of these classes, collects input from users, and outputs the student information accordingly.

Uploaded by

Hưng Nguyễn
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)
7 views2 pages

nt106 Lab

The document presents a C# program that defines a base class 'SinhVien' for student information, including methods for inputting and displaying student data. It also includes two derived classes, 'SinhVienMMT' and 'SinhVienATTT', which override methods to calculate and display average scores differently. The main program creates instances of these classes, collects input from users, and outputs the student information accordingly.

Uploaded by

Hưng Nguyễn
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/ 2

Code:

using System;

class SinhVien
{
protected string MaSo;
protected string HoTen;
protected double Diem1 = 0, Diem2 = 0, Diem3 = 0;
public virtual void Nhap()
{
Console.Write("Nhap MSSV: ");
MaSo = Console.ReadLine();
Console.Write("Nhap ho ten: ");
HoTen = Console.ReadLine();
Console.Write("Nhap diem mon 1: ");
Diem1 = double.Parse(Console.ReadLine());
Console.Write("Nhap diem mon 2: ");
Diem2 = double.Parse(Console.ReadLine());
Console.Write("Nhap diem mon 3: ");
Diem3 = double.Parse(Console.ReadLine());
}
public virtual void Xuat()
{
Console.WriteLine($"MSSV: {MaSo}, Ho Ten: {HoTen}, Diem TB: {TinhDiemTB():F2}");
}
protected virtual double TinhDiemTB()
{
return (Diem1 + Diem2 + Diem3) / 3.0;
}
}
class SinhVienMMT : SinhVien
{
protected override double TinhDiemTB()
{
return (Diem1 * 2 + Diem2 + Diem3) / 4.0;
}
public override void Xuat()
{
Console.Write("[SinhVienMMT] ");
Console.WriteLine($"MSSV: {MaSo}, Ho Ten: {HoTen}, Diem TB: {TinhDiemTB():F2}");
}
}
class SinhVienATTT : SinhVien
{
public override void Xuat()
{
Console.Write("[SinhVienATTT] ");
base.Xuat();
}
}
class Program
{
static void Main()
{
SinhVien sv1 = new SinhVienMMT();
SinhVien sv2 = new SinhVienATTT();
Console.WriteLine("Thong tin sinh vien MMT:");
sv1.Nhap();
Console.WriteLine("Thong tin sinh vien ATTT:");
sv2.Nhap();
Console.WriteLine("\nThong tin sinh vien MMT va sinh vien ATTT:");
sv1.Xuat();
sv2.Xuat();
}
}

Kết quả:

You might also like