// Baikiemtra3Cau3.cpp : This file contains the 'main' function. Program execution begins and ends there.//#include <iostream>#include <string.h>#include <iomanip>#include <fstream>using namespace std;class HANG {public: virtual void INRA() = 0;};class DIENTU :public HANG {public: virtual char* Mahang() = 0; virtual char* Tenhang() = 0; virtual int Namsx() = 0; virtual float Dongia() = 0; virtual char* Size() = 0; void INRA() { cout << Mahang() << " " << Tenhang() << " " << Namsx() << " " << setprecision(2) << fixed << Dongia() << " " << Size(); }};class MAYMAC :public HANG {public: virtual char* Mahang() = 0; virtual char* Tenhang() = 0; virtual int Namsx() = 0; virtual float Dongia() = 0; virtual char* Size() = 0; void INRA() { cout << Mahang() << " " << Tenhang() << " " << Namsx() << " " << setprecision(2) << fixed << Dongia() << " " << Size() << endl; }};class MAYTINH :public DIENTU {private: char mahang[10]; char tenhang[30]; int namsx; float dongia; char size[20]; char sizebonho[15];public: MAYTINH() { strcpy_s(this->mahang, ""); strcpy_s(this->tenhang, ""); this->namsx = 0; this->dongia = 0; strcpy_s(this->size, ""); strcpy_s(this->sizebonho, ""); } MAYTINH(string mahang, string tenhang, int namsx, float dongia, string size, string sizebonho) { strcpy_s(this->mahang, mahang.c_str()); strcpy_s(this->tenhang, tenhang.c_str()); this->namsx = namsx; this->dongia = dongia; strcpy_s(this->size, size.c_str()); strcpy_s(this->sizebonho, sizebonho.c_str()); } char* Mahang() { return this->mahang; } char* Tenhang() { return this->tenhang; } int Namsx() { return this->namsx; } float Dongia() { return this->dongia; } char* Size() { return this->size; } void GHITEP() {//Ghi thong tin may tinh ra MT.TXT MAYTINH mt; ofstream fout; fout.open("MT.TXT", ios::out); char ok; cout << "Nhap mat hang may tinh ghi vao tep:" << endl; while (1) { cout << "Ma hang:"; cin.getline(mt.mahang, 10); cout << "Ten hang:"; cin.getline(mt.tenhang, 30); cout << "Nam san xuat:"; cin >> mt.namsx; cin.ignore(); cout << "Don gia:"; cin >> mt.dongia; cin.ignore(); cout << "Size man hinh:"; cin.getline(mt.size, 20); cout << "Size bo nho:"; cin.getline(mt.sizebonho, 15); cout << "Co nhap tiep khong (C/K)?"; cin >> ok; cin.ignore(); fout.write((char*)&mt, sizeof(mt)); if ((ok == 'k') || (ok == 'K')) { break; } } } void INRA() { DIENTU::INRA(); cout << " " << this->sizebonho << endl; } int MAYTINH2018(); //San xuat tu 2018 den nay };int MAYTINH::MAYTINH2018() { //San xuat tu 2018 den nay ifstream fin; fin.open("MT.TXT", ios::in); if (fin.fail()) { return 0; } MAYTINH mt; int tongs = 0; while (fin.read((char*)&mt, sizeof(mt))) { if (mt.namsx >= 2018) { tongs++; } } return tongs;}class TIVI :public DIENTU {private: char mahang[10]; char tenhang[30]; int namsx; float dongia; char size[20];public: TIVI() { strcpy_s(this->mahang, ""); strcpy_s(this->tenhang, ""); this->namsx = 0; this->dongia = 0; strcpy_s(this->size, ""); } TIVI(string mahang, string tenhang, int namsx, float dongia, string size) { strcpy_s(this->mahang, mahang.c_str()); strcpy_s(this->tenhang, tenhang.c_str()); this->namsx = namsx; this->dongia = dongia; strcpy_s(this->size, size.c_str()); } char* Mahang() { return this->mahang; } char* Tenhang() { return this->tenhang; } int Namsx() { return this->namsx; } float Dongia() { return this->dongia; } char* Size() { return this->size; } void INRA() { DIENTU::INRA(); cout << endl; }};class AO :public MAYMAC {private: char mahang[10]; char tenhang[30]; int namsx; float dongia; char size[20];public: AO() { strcpy_s(this->mahang, ""); strcpy_s(this->tenhang, ""); this->namsx = 0; this->dongia = 0; strcpy_s(this->size, ""); } AO(string mahang, string tenhang, int namsx, float dongia, string size) { strcpy_s(this->mahang, mahang.c_str()); strcpy_s(this->tenhang, tenhang.c_str()); this->namsx = namsx; this->dongia = dongia; strcpy_s(this->size, size.c_str()); } char* Mahang() { return this->mahang; } char* Tenhang() { return this->tenhang; } int Namsx() { return this->namsx; } float Dongia() { return this->dongia; } char* Size() { return this->size; }};class VAY :public MAYMAC {private: char mahang[10], tenhang[30]; int namsx; float dongia; char size[20];public: VAY() { strcpy_s(this->mahang, ""); strcpy_s(this->tenhang, ""); this->namsx = 0; this->dongia = 0; strcpy_s(this->size, ""); } VAY(string mahang, string tenhang, int namsx, float dongia, string size) { strcpy_s(this->mahang, mahang.c_str()); strcpy_s(this->tenhang, tenhang.c_str()); this->namsx = namsx; this->dongia = dongia; strcpy_s(this->size, size.c_str()); } char* Mahang() { return this->mahang; } char* Tenhang() { return this->tenhang; } int Namsx() { return this->namsx; } float Dongia() { return this->dongia; } char* Size() { return this->size; }};int main(){ /*In thong tin cac loai hang theo ki thuat da hinh thai*/ HANG* hang; MAYTINH mt("MT01", "May tinh", 2019, 12000000, "14inh", "500Gb"); hang = &mt; hang->INRA(); TIVI tv = TIVI("TV01", "Ti vi", 2020, 10000000, "50inh"); hang = &tv; hang->INRA(); AO ao = AO("AO01", "Ao so mi nam", 2021, 235000, "M"); hang = &ao; hang->INRA(); VAY vay = VAY("VO01", "Vay cong so", 2021, 40000, "L"); hang = &vay; hang->INRA(); /*Ghi mat hang may tinh ra tep va thong ke may tinh san xuat tu nawm 2018 den nay*/ MAYTINH mt; mt.GHITEP(); cout << "So luong mat hang may tinh san xuat tu nam 2018 den nay: " << mt.MAYTINH2018() << endl; return 0;}
Tác giả: Vàng Văn Quyn
Những tin mới hơn
Những tin cũ hơn
- Click vào nút hiển thị ngày trong tuần hoặc tháng âm lịch để xem chi tiết
- Màu đỏ: Ngày tốt
- Xanh lá: Đầu tháng âm lịch
- Màu vàng: Ngày hiện tại