+++++Абстракция данных


++ Создайте класс с именем Ноутбук


Download 57.24 Kb.
bet18/23
Sana20.11.2023
Hajmi57.24 Kb.
#1790263
1   ...   15   16   17   18   19   20   21   22   23
Bog'liq
dasturlash

++ Создайте класс с именем Ноутбук. Объявляйте методы и свойства, используя
спецификаторы public и private. Используйте их в основной программе
#include
#include
class Notebook {
public:
Notebook() {
this->brand = "";
this->model = "";
this->year = 0;
}
Notebook(std::string brand, std::string model) {
this->brand = brand;
this->model = model;
this->year = 0;
}
Notebook(std::string brand, std::string model, int year) {
this->brand = brand;
this->model = model;
this->year = year;
}
std::string getBrand() {
return this->brand;
}
std::string getModel() {
return this->model;
}
int getYear() {
return this->year;
}

private:
std::string brand;


std::string model;
int year;
};
int main() {
Notebook defaultNotebook;
Notebook brandModelNotebook("Apple", "MacBook Pro");
Notebook fullNotebook("Dell", "XPS 13", 2020);
std::string defaultBrand = defaultNotebook.getBrand();
std::string defaultModel = defaultNotebook.getModel();
int defaultYear = defaultNotebook.getYear();
std::string brandModelBrand = brandModelNotebook.getBrand();
std::string brandModelModel = brandModelNotebook.getModel();
std::string fullBrand = fullNotebook.getBrand();
std::string fullModel = fullNotebook.getModel();
int fullYear = fullNotebook.getYear();
std::cout << "Default Notebook's Brand: " << defaultBrand << ", Model: " << defaultModel << ", Year: " << defaultYear << std::endl;
std::cout << "Brand and Model Notebook's Brand: " << brandModelBrand << ", Model: " << brandModelModel << std::endl;
std::cout << "Full Notebook's Brand: " << fullBrand << ", Model: " << fullModel << ", Year: " << fullYear << std::endl;
return 0;
}
Создайте класс с именем Ноутбук. Пусть будет два метода и 4 свойства.
. Отправьте марку ноутбука с помощью метода getBrand
#include
#include
class Notebook {
public:
Notebook() {
this->brand = "";
this->model = "";
this->year = 0;
this->price = 0.0;
}
void setBrand(std::string brand) {
this->brand = brand;
}
std::string getBrand() {
return this->brand;
}
private:
std::string brand;
std::string model;
int year;
double price;
};
int main() {
Notebook notebook
notebook.setBrand("Apple");
std::string brand = notebook.getBrand();
std::cout << "Notebook's Brand: " << brand << std::endl;
return 0;
}

Download 57.24 Kb.

Do'stlaringiz bilan baham:
1   ...   15   16   17   18   19   20   21   22   23




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling