Code
class CD():
def __init__(self,id:int,name:str,author:str,numberOfSongs:int,price:float):
self.__id = id
self.__name = name
self.__author = author
self.__numberOfSongs = numberOfSongs
self.__price = price
def getId(self): return self.__id
def getName(self): return self.__name
def getAuthor(self): return self.__author
def getNumberOfSongs(self): return self.__numberOfSongs
def getPrice(self): return self.__price
def setId(self, id): self.__id = id
def setName(self, name): self.__name = name
def setAuthor(self, author): self.__author = author
def setNumberOfSongs(self, numberOfSongs): self.__numberOfSongs = numberOfSongs
def setPrice(self, price): self.__price = price
class Album():
def __init__(self,size:int):
self.size = size
self.alb = []
def addCD(self):
id = int(input("Nhập mã CD: "))
name = input("Nhập tên CD: ")
author = input("Nhập tên của tác giả: ")
numberOfSongs = int(input("Nhập số bài hát của CD: "))
price = int(input("Nhập giá thành của CD: "))
if len([x for x in range(len(self.alb)) if self.alb[x].getId() == id]) == 0 and len(self.alb) < self.size:
obj = CD(id,name,author,numberOfSongs,price)
self.alb.append(obj)
print("Thành công")
else:
print("Mã CD đã tồn tại hoặc số lượng CD của Album đã đầy")
def getTotalCD(self):
print("Số lượng CD có trong Album: " + str(len(self.alb)))
size = int(input("Nhập kích thước của Album: "))
test = Album(size)
quit = False
print("Bạn muốn làm gì?")
print("1. Thêm CD vào Album")
print("2. Lấy tổng số lượng CD có trong Album")
print("Nếu muốn thoát thì nhập một kí tự khác 1 và 2")
while quit is False:
n = input("Nhập lệnh: ")
if n == "1":
test.addCD()
elif n == "2":
test.getTotalCD()
else:
quit = True
(Sai thì xin lỗi nha vì mình cũng khá kém OOP)
using System;
class CD{
private int ma_cd, so_bai_hat;
private string tua_cd, ca_si;
private float gia_thanh;
public CD(int mcd, string tcd, string cs, int sbh, float gt){
ma_cd = mcd;
tua_cd = tcd;
ca_si = cs;
so_bai_hat = sbh;
gia_thanh = gt;
}
public int get_ma_cd(){
return ma_cd;
}
public string get_tua_cd(){
return tua_cd;
}
public string get_ca_si(){
return ca_si;
}
public int get_so_bai_hat(){
return so_bai_hat;
}
public float get_gia_thanh(){
return gia_thanh;
}
public void set_ma_cd(int nmcd){
ma_cd = nmcd;
}
public void set_tua_cd(string ntcd){
tua_cd = ntcd;
}
public void set_ca_si(string ncs){
ca_si = ncs;
}
public void set_so_bai_hat(int nsbh){
so_bai_hat = nsbh;
}
public void set_gia_thanh(float ngt){
gia_thanh = ngt;
}
}
class ALBUM{
private int n = 0;
private CD[] a = new CD[1000000];
private bool can_add(CD ccd){
for (int i=0; i<n; i++){
if (a[i].get_ma_cd() == ccd.get_ma_cd()){
return false;
}
}
return true;
}
public void add_cd(CD ncd){
if (n<1000000){
if (can_add(ncd)){
a[n] = ncd;
n++;
Console.WriteLine("SUCCESSFULLY ADD CD TO ALBUM.");
}
else{
Console.WriteLine("CAN'T ADD CD TO ALBUM BECAUSE ID OF CD WERE EXIST.");
}
}
else{
Console.WriteLine("CAN'T ADD CD TO ALBUM BECAUSE ALBUM IS FULL.");
}
}
public int so_luong_cd(){
return n;
}
}
$\\$
`@Daoanhviet96`
Tin học, tiếng Anh: informatics, tiếng Pháp: informatique, là một ngành khoa học chuyên nghiên cứu quá trình tự động hóa việc tổ chức, lưu trữ, xử lý và truyền dẫn thông tin của một hệ thống máy tính cụ thể hoặc trừu tượng (ảo). Với cách hiểu hiện nay, tin học bao hàm tất cả các nghiên cứu và kỹ thuật có liên quan đến việc mô phỏng, biến đổi và tái tạo thông tin.
Nguồn : Wikipedia - Bách khoa toàn thưLớp 12 - Năm cuối ở cấp tiểu học, năm học quan trọng nhất trong đời học sinh trải qua bao năm học tập, bao nhiêu kì vọng của người thân xung quanh ta. Những nỗi lo về thi đại học và định hướng tương lai thật là nặng. Hãy tin vào bản thân là mình sẽ làm được rồi tương lai mới chờ đợi các em!
Nguồn : ADMIN :))Xem thêm tại https://loigiaisgk.com/cau-hoi or https://giaibtsgk.com/cau-hoi
Copyright © 2021 HOCTAPSGK