Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

BÀI

BU I 07
OOP: TÍNH K TH (PH N 1)

TIÊU
tính trong

overriding)

Class Person, Student và Staff


Person
name: string
birthYear: int
address: string
Person()
Person(string name, int birthYear, string address)
Input(): void
GetAge(): int
ToString(): string

Student Staff
program: string departmenyt: string
year: int salary: double
Student() Staff()
Student(string name, int Staff(string name, int birthYear,
birthYear, string address, string string address, string department,
program, int year) double salary)
Input(): void Input(): void
ToString(): string ToString(): string
ChangeProgram(string UpdateSalary(double salary): void
program): void

Class Person
+ Person(string name, int birthYear, string address): Kh i t o m ng Person v i
c
+ Input(): i dùng l t nh p các thông tin cho m t Person
+ GetAge(): Tính tu i c a Person nt i
+ ToString(): Tr v chu i bi u di n m t Person
name }, Age: {birthYear}, Address: {address}]

| 25
BÀI

Class Student
+ Student(string name, int birthYear, string address, string program, int year): Kh i t o
t om ng Student v i các thông tin c (g i Constructor c a class Person)
+ Input(): c Input() c a class Person i dùng nh p thêm các
thông tin program và year
+ ToString(): c ToString() c a class Person tr v chu i bi u
di n m t Student
Person[Name: {name }, Age: {birthYear}, Address: {address}] - Program:
{program}, Year: {year}]
Class Staff
+ Staff(string name, int birthYear, string address, string department, double salary): Kh i
t ot om ng Staff v c (g i Constructor c a class Person)
+ Input(): c Input() c a class Person i dùng nh p thêm các
thông tin department và salary
+ ToString(): c ToString() c a class Person tr v chu i bi u
di n m t Staff
Person[Name: {name }, Age: {birthYear}, Address: {address}] - Department:
{department}, Salary: {salary}]

Class Fraction và MixedFraction


Fraction
numerator: int
denominator: int
Fraction()
Fraction(int numerator, int denominator)
Fraction(int numerator)
GCD(int a, int b): void
Simplify(): void
ToString(): string
ToDecimal(): double
Add(Fraction f): Fraction
Subtract(Fraction f): Fraction
Multiply(Fraction f): Fraction
Divide(Fraction f): Fraction

MixedFraction

MixedFraction(int wholePart, int numerator, int denominator)


MixedFraction(Fraction f)
ToString(): string

| 26
BÀI

Class Fraction
+ Fraction(): Kh i t o phân s có t s = 0, m u s =1
+ Fraction(int numerator, int denominator): Kh i t o phân s có t s = numerator, m u
s = denominator
+ Fraction(int numerator): Kh i t o phân s có t s = numerator, m u s = 1
+ ToString(): Tr v chu i bi u di n m t phân s có d ng s /m u s
Class MixedFraction
+ MixedFraction(int wholePart, int numerator, int denominator): Kh i t o h n s có ph n
nguyên = wholePart và ph n phân s có t s = numerator, m u s = denominator
G i ý: vi c x n, các h n s c chuy n v i d ng phân s .
chuy i h n s thành phân s và ch 2 thu c tính numerator
và denominator mà không c n khai báo thêm thu c tính wholePart
+ MixedFraction(Fraction f): Kh i t o h n s t m t phân s
+ ToString(): Tr v chu i bi u di n m t h n s có d ng n nguyên [t s /m u s

| 27

You might also like