<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      任務一:

      publisher.hpp

      #pragma once
      
      #include <iostream>
      #include <string>
      
      using std::cout;
      using std::endl;
      using std::string;
      
      // 發行/出版物類:Publisher (抽象類)
      class Publisher {
      public:
          Publisher(const string &s = "");            // 構造函數
      
      public:
          virtual void publish() const = 0;                 // 純虛函數,作為接口繼承
          virtual void use() const = 0;                     // 純虛函數,作為接口繼承
      
      protected:
          string name;    // 發行/出版物名稱
      };
      
      Publisher::Publisher(const string &s): name {s} {
      }
      
      
      // 圖書類: Book
      class Book: public Publisher {
      public:
          Book(const string &s = "", const string &a = "");  // 構造函數
      
      public:
          void publish() const override;        // 接口
          void use() const override;            // 接口
      
      private:
          string author;          // 作者
      };
      
      Book::Book(const string &s, const string &a): Publisher{s}, author{a} {
      }
      
      void Book::publish() const {
          cout << "Publishing book: 《" << name << "》 by " << author << endl;
      }
      
      void Book::use() const {
          cout << "Reading book: " << name << " by " << author << endl;
      }
      
      
      // 電影類: Film
      class Film: public Publisher {
      public:
          Film(const string &s = "", const string &d = "");   // 構造函數
      
      public:
          void publish() const override;    // 接口
          void use() const override;        // 接口            
      
      private:
          string director;        // 導演
      };
      
      Film::Film(const string &s, const string &d): Publisher{s}, directorw0obha2h00 {
      }
      
      void Film::publish() const {
          cout << "Publishing film: <" << name << "> directed by " << director << endl;
      }
      
      void Film::use() const {
          cout << "Watching film: " << name << " directed by " << director << endl;
      }
      
      
      // 音樂類:Music
      class Music: public Publisher {
      public:
          Music(const string &s = "", const string &a = "");
      
      public:
          void publish() const override;        // 接口
          void use() const override;            // 接口
      
      private:
          string artist;      // 音樂藝術家名稱
      };
      
      Music::Music(const string &s, const string &a): Publisher{s}, artist{a} {
      }
      
      void Music::publish() const {
          cout << "Publishing music <" << name << "> by " << artist << endl;
      }
      
      void Music::use() const {
          cout << "Listening to music: " << name << " by " << artist << endl;
      }

      task1.cpp

      #include "publisher.hpp"
      #include <vector>
      #include <typeinfo>
      
      using std::vector;
      
      void test() {
         vector<Publisher *> v;
      
         v.push_back(new Book("Harry Potter", "J.K. Rowling"));
         v.push_back(new Film("The Godfather", "Francis Ford Coppola"));
         v.push_back(new Music("Blowing in the wind", "Bob Dylan"));
      
         for(auto &ptr: v) {
              cout << "pointer type: " << typeid(ptr).name() << endl;  // 輸出指針類型
              cout << "RTTI type: " << typeid(*ptr).name() << endl;    // 輸出指針指向的對象類型
              ptr->publish();
              ptr->use();
              cout << endl;
         }
      }
      
      int main() {
          test();
      }

      任務二:

      book.hpp

      #pragma once
      
      #include <string>
      #include <iostream>
      #include <iomanip>
      
      using std::string;
      using std::ostream;
      using std::endl;
      using std::setw;
      using std::left;
      
      class Book {
      public:
          Book(const string &name, const string &author, const string &translator, const string &isbn, float price);
      
          friend ostream& operator<<(ostream &out, const Book &book);
      
      private:
          string name;        // 書名
          string author;      // 作者
          string translator;  // 譯者
          string isbn;        // isbn號
          float price;        // 定價
      };
      
      // 成員函數實現
      Book::Book(const string &name, const string &author, const string &translator, const string &isbn, float price) {
          this->name = name;
          this->author = author;
          this->translator = translator;
          this->isbn = isbn;
          this->price = price;
      }
      
      // 友元實現
      ostream& operator<<(ostream &out, const Book &book) {
          out << left;
          out << setw(15) << "書名:" << book.name << endl
              << setw(15) << "作者:" << book.author << endl
              << setw(15) << "譯者:" << book.translator << endl
              << setw(15) << "ISBN:" << book.isbn << endl
              << setw(15) << "定價:" << book.price;
      
          return out;
      }

      booksale.hpp

      #pragma once
      
      #include "book.hpp"
      #include <iostream>
      #include <string>
      #include <iomanip>
      
      using std::string;
      using std::cout;
      using std::endl;
      using std::setw;
      
      class BookSale {
      public:
          BookSale(const Book &b, float price, int amount);
          int get_amount() const;
          
          friend ostream& operator<<(ostream &out, const BookSale &item);
      
      private:
          Book rb;         
          float sales_price;      // 售價
          int sales_amount;       // 銷售數量
          float revenue;          // 營收
      };
      
      // 成員函數實現
      BookSale::BookSale(const Book &b, float price, int amount): rb{b}, sales_price(price), sales_amount{amount} {  
          revenue = sales_amount * sales_price;
      }
      
      int BookSale::get_amount() const {
          return sales_amount;
      }
      
      // 友元函數實現
      ostream& operator<<(ostream &out, const BookSale &item) {
          out << left;
          out << item.rb << endl
              << setw(15) << "售價:" << item.sales_price << endl
              << setw(15) << "銷售數量:" << item.sales_amount << endl
              << setw(15) << "營收:" << item.revenue;
      
          return out;
      }

      task2.cpp

      #include "booksale.hpp"
      #include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      
      // 按圖書銷售數額比較
      bool compare_by_amount(const BookSale &x1, const BookSale &x2) {
          return x1.get_amount() > x2.get_amount();
      }
      
      void test() {
          using namespace std;
      
           vector<BookSale> sales_lst;         // 存放圖書銷售記錄
      
           int books_number;
          cout << "錄入圖書數量: ";
          cin >> books_number;
      
          cout << "錄入圖書銷售記錄" << endl;
          for(int i = 0; i < books_number; ++i) {
              string name, author, translator, isbn;
              float price;
              cout << string(20, '-') << "" << i+1 << "本圖書信息錄入" << string(20, '-') << endl;
              cout << "錄入書名: "; cin >> name;
              cout << "錄入作者: "; cin >> author;
              cout << "錄入譯者: "; cin >> translator;
              cout << "錄入isbn: "; cin >> isbn;
              cout << "錄入定價: "; cin >> price;
      
              Book book(name, author, translator, isbn, price);
      
              float sales_price;
              int sales_amount;
      
              cout << "錄入售價: "; cin >> sales_price;
              cout << "錄入銷售數量: "; cin >> sales_amount;
      
              BookSale record(book, sales_price, sales_amount);
              sales_lst.push_back(record);
          }
      
          // 按銷售冊數排序
          sort(sales_lst.begin(), sales_lst.end(), compare_by_amount);
      
          // 按銷售冊數降序輸出圖書銷售信息
          cout << string(20, '=') <<  "圖書銷售統計" << string(20, '=') << endl;
          for(auto &t: sales_lst) {
              cout << t << endl;
              cout << string(40, '-') << endl;
          }
      }
      
      int main() {
          test();
      }

       任務三:

      pets.hpp

      #pragma once
      
      #include <iostream>
      #include <string>
      
      class MachinePets {
      protected:
          std::string nickname;
      
      public:
          MachinePets(const std::string &s) : nickname(s) {}
          std::string get_nickname() const {
              return nickname;
          }
          virtual std::string talk() = 0;
          virtual ~MachinePets() {}
      };
      
      class PetCats : public MachinePets {
      public:
          PetCats(const std::string &s) : MachinePets(s) {}
          std::string talk() override {
              return "maio wu~";
          }
      };
      
      class PetDogs : public MachinePets {
      public:
          PetDogs(const std::string &s) : MachinePets(s) {}
          std::string talk() override {
              return "wang wang~";
          }
      };

      task3.cpp

      #include "pets.hpp"
      #include <iostream>
      #include <vector>
      
      void test() {
          using namespace std;
      
          vector<MachinePets *> pets;
      
          pets.push_back(new PetCats("miku"));
          pets.push_back(new PetDogs("da huang"));
      
          for(auto &ptr: pets)
              cout <<ptr->get_nickname() << " says " << ptr->talk() << endl;
      }
      
      int main() {
          test();
      }

      任務四:

      film.hpp

      #ifndef FILM_HPP
      #define FILM_HPP
      
      #include <iostream>
      #include <string>
      
      class Film {
      private:
          std::string title;
          std::string director;
          std::string country;
          int year;
      
      public:
          Film(std::string t = "", std::string d = "", std::string c = "", int y = 0)
              : title(t), director(d), country(c), year(y) {}
      
          friend std::istream& operator>>(std::istream& in, Film& f) {
              std::cout << "錄入片名: ";
              in >> f.title;
              std::cout << "錄入導演: ";
              in >> f.director;
              std::cout << "錄入制片國家/地區: ";
              in >> f.country;
              std::cout << "錄入上映年份: ";
              in >> f.year;
              return in;
          }
      
          friend std::ostream& operator<<(std::ostream& out, const Film& f) {
              out << f.title << "    "
                  << f.director << "    "
                  << f.country << "    "
                  << f.year << "    ";
              return out;
          }
      
          int getYear() const {
              return year;
          }
      };
      
      bool compare_by_year(const Film& a, const Film& b) {
          return a.getYear() < b.getYear();
      }
      
      #endif 

      task4.cpp

      #include "film.hpp"
      #include <iostream>
      #include <vector>
      #include <algorithm>
      
      void test() {
          using namespace std;
      
          int n;
          cout << "輸入電影數目: ";
          cin >> n;
          cout << "錄入" << n << "部影片信息" << endl;
          vector<Film> film_lst;
          for (int i = 0; i < n; ++i) {
              Film f;
              cout << string(20, '-') << "" << i + 1 << "部影片錄入" << string(20, '-') << endl;
              cin >> f;
              film_lst.push_back(f);
          }
      
          // 按發行年份升序排序
          sort(film_lst.begin(), film_lst.end(), compare_by_year);
      
          cout << string(20, '=') + "電影信息(按發行年份)" + string(20, '=') << endl;
          for (auto& f : film_lst)
              cout << f << endl;
      }
      
      int main() {
          test();
          return 0;
      }

      任務五:

      Complex:

      #ifndef COMPLEX_HPP
      #define COMPLEX_HPP
      
      #include <iostream>
      
      template<typename T>
      class Complex {
      private:
          T real;
          T imag;
      
      public:
          Complex(T r = 0, T i = 0) : real(r), imag(i) {}
          T get_real() const { return real; }
          T get_imag() const { return imag; }
      
          Complex& operator+=(const Complex& rhs) {
              real += rhs.real;
              imag += rhs.imag;
              return *this;
          }
      
          Complex operator+(const Complex& rhs) const {
              return Complex(real + rhs.real, imag + rhs.imag);
          }
      
          bool operator==(const Complex& rhs) const {
              return (real == rhs.real) && (imag == rhs.imag);
          }
      
          friend std::istream& operator>>(std::istream& in, Complex& c) {
              in >> c.real >> c.imag;
              return in;
          }
      
          friend std::ostream& operator<<(std::ostream& out, const Complex& c) {
              out << c.real << (c.imag >= 0 ? "+" : "") << c.imag << "i";
              return out;
          }
      };
      
      #endif 

      task5.cpp:

      #include "Complex.hpp"
      #include <iostream>
      
      using std::cin;
      using std::cout;
      using std::endl;
      using std::boolalpha;
      
      void test1() {
          Complex<int> c1(2, -5), c2(c1);
          cout << "c1 = " << c1 << endl;
          cout << "c2 = " << c2 << endl;
          cout << "c1 + c2 = " << c1 + c2 << endl;
      
          c1 += c2;
          cout << "c1 = " << c1 << endl;
          cout << boolalpha << (c1 == c2) << endl;
      }
      
      void test2() {
          Complex<double> c1, c2;
          cout << "Enter c1 and c2: ";
          cin >> c1 >> c2;
          cout << "c1 = " << c1 << endl;
          cout << "c2 = " << c2 << endl;
          cout << "c1.real = " << c1.get_real() << endl;
          cout << "c1.imag = " << c1.get_imag() << endl;
      }
      
      int main() {
          cout << "自定義類模板Complex測試1: " << endl;
          test1();
          cout << endl;
          cout << "自定義類模板Complex測試2: " << endl;
          test2();
      }

      任務六:
      date.h:

      #pragma once
      
      class Date {
          private:
              int year;
              int month;
              int day;
              int totalDays;
          public:
              Date(int year, int month, int day);
              int getYear() const {
                  return year;
              }
              int getMonth() const {
                  return month;
              }
              int getDay() const {
                  return day;
              }
              int getMaxDay() const;
              bool isLeapYear() const {
                  return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
              }
              void show() const;
              int operator-(const Date& date) const {
                  return totalDays - date.totalDays;
              }
      };

      date.cpp

      #include "date.h"
      #include <iostream>
      #include <cstdlib>
      
      using namespace std;
      
      namespace {
          const int DAYS_BEFIRE_MONTH[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
      }
      
      Date::Date(int year, int month, int day) : year(year), month(month), day(day) {
          if (day <= 0 || day > getMaxDay()) {
              cout << "Invalid date: ";
              show();
              cout << endl;
              exit(1);
          }
          int years = year - 1;
          totalDays = years * 365 + years / 4 - years / 100 + years / 400 + DAYS_BEFIRE_MONTH[month - 1] + day;
          if (isLeapYear() && month > 2) totalDays++;
      }
      
      int Date::getMaxDay() const {
          if (isLeapYear() && month == 2)
              return 29;
          else
              return DAYS_BEFIRE_MONTH[month] - DAYS_BEFIRE_MONTH[month - 1];
      }
      
      void Date::show() const {
          cout << getYear() << "-" << getMonth() << "-" << getDay();
      }

      accumulator.h

      #pragma once
      
      #include "date.h"
      
      class Accumulator {
      private:
          Date lastDate;
          double value;
          double sum;
      
      public:
          double getSum(const Date& date) const {
              return sum + value * (date - lastDate); 
          }
          Accumulator(const Date& date, double value) : lastDate(date), value(value), sum{ 0 } {}
      
         void change(const Date& date, double value) {
             sum = getSum(date);
             lastDate = date;
             this->value = value;
         }
      
         void reset(const Date& date, double value) {
             lastDate = date;
              this->value = value;
             sum = 0;
          }
      };

      account.h

      #pragma once
      
      #include "date.h"
      #include "accumulator.h"
      #include <string>
      
      class Account {
      private:
          std::string id;
          double balance;
          static double total;
      protected:
          Account(const Date &date, const std::string &id);
          void record(const Date& date, double amount, const std::string& desc);
          void error(const std::string& msg) const;
      public:
          const std::string& getId() {
              return id;
          }
          double getBalance() const {
              return balance;
          }
          static double getTotal() {
              return total;
          }
          virtual void deposit(const Date& date, double amount, const std::string& desc) = 0;
          virtual void withdraw(const Date& date, double amount, const std::string& desc) = 0;
          virtual void settle(const Date& date) = 0;
          virtual void show() const;
      };
      
      class SavingsAccount : public Account {
      private:
          Accumulator acc;
          double rate;
      public:
          SavingsAccount(const Date& date, const std::string& id, double rate);
          double getRate() const {
              return rate;
          }
          void deposit(const Date& date, double amount, const std::string& desc);
          void withdraw(const Date& date, double amount, const std::string& desc);
          void settle(const Date& date);
      };
      
      class CreditAccount : public Account {
      private:
          Accumulator acc;
          double credit;
          double rate;
          double fee;
          double getDebt() const {
              double balance = getBalance();
              return (balance < 0 ? balance : 0);
          }
      public:
          CreditAccount(const Date& date, const std::string& id, double credit, double rate, double fee);
          double getCredit() const {
              return credit;
          }
          double getRate() const {
              return rate;
          }
          double getFee() const {
              return fee;
          }
          double getAvailableCredit() const {
              if (getBalance() < 0) return credit + getBalance();
              else return credit;
          }
          void deposit(const Date& date, double amount, const std::string& desc);
          void withdraw(const Date& date, double amount, const std::string& desc);
          void settle(const Date& date);
          void show() const;
      };

      account.cpp

      #include "account.h"
      #include <cmath>
      #include<iostream>
      using namespace std;
      
      double Account::total = 0;
      Account::Account(const Date& date, const string& id) : id(id), balance(0) {
          date.show();
          cout << "\t#" << id << " created" << endl;
      
      }
      
      void Account::record(const Date& date, double amount, const string& desc) {
          amount = floor(amount * 100 + 0.5) / 100;
          balance += amount;
          total += amount;
          date.show();
             cout << "\t#" << id << "\t" << amount << "\t" << balance << "\t" << desc << endl;
      
      }
      
      void Account::show() const {
          cout << id << "\tBalance: " << balance;
      
      }
      
      void Account::error(const string& msg) const {
          cout << "Error (#" << id << "): " << msg << endl;
      
      }
      
      SavingsAccount::SavingsAccount(const Date& date, const string& id, double rate)
          : Account(date, id), rate(rate), acc(date, 0) {}
      
      void SavingsAccount::deposit(const Date& date, double amount, const string& desc) {
          record(date, amount, desc);
          acc.change(date, getBalance());
      
      }
      
      void SavingsAccount::withdraw(const Date& date, double amount, const string& desc) {
          if (amount > getBalance()) {
              error("not enough money");
      
          }
         else {
              record(date, -amount, desc);
               acc.change(date, getBalance());
          }
      
      }
      
      void SavingsAccount::settle(const Date& date) {
          if (date.getMonth() == 1)
          {
              double interest = acc.getSum(date) * rate / (date - Date(date.getYear() - 1, 1, 1));
              if (interest != 0) record(date, interest, "interest");
              acc.reset(date, getBalance());
          }
      }
      
      CreditAccount::CreditAccount(const Date& date, const string& id, double credit, double rate, double fee)
          : Account(date, id), credit(credit), rate(rate), fee(fee), acc(date, 0) {}
      
      void CreditAccount::deposit(const Date& date, double amount, const string& desc) {
          record(date, amount, desc);
          acc.change(date, getDebt());
      
      }
      
      void CreditAccount::withdraw(const Date& date, double amount, const string& desc) {
          if (amount - getBalance() > credit) {
              error("not enough credit");
      
          }
          else {
              record(date, -amount, desc);
              acc.change(date, getDebt());
      
          }
      
      }
      
      void CreditAccount::settle(const Date& date) {
          double interest = acc.getSum(date) * rate;
          if (interest != 0) record(date, interest, "interest");
          if (date.getMonth() == 1) record(date, -fee, "annual fee");
          acc.reset(date, getDebt());
      
      }
      
      void CreditAccount::show() const {
          Account::show();
          cout << "\tAvailable credit: " << getAvailableCredit();
       
       }

      8_8.cpp

      #include"account.h"
      #include<iostream> 
      
      using namespace std;
      
      int main() {
          Date date(2008, 11, 1);
          SavingsAccount sa1(date, "S3755217", 0.015);
          SavingsAccount sa2(date, "02342342", 0.015);
          CreditAccount ca(date, "C5392394", 10000, 0.0005, 50);
          Account* accounts[] = { &sa1,&sa2,&ca };
          const int n = sizeof(accounts) / sizeof(Account*);
          cout << "(d)deposit (w)withdraw (s)show (c)change day (n)next month (e)exit" << endl;
          char cmd;
          do {
              date.show();
              cout << "\tTotal:" << Account::getTotal() << "\tcommand>";
              int index, day;
              double amount;
              string desc;
              cin >> cmd;
              switch (cmd) {
                  case 'd':
                      cin >> index >> amount;
                      getline(cin, desc);
                      accounts[index]->deposit(date, amount, desc);
                      break;
      
                  case 'w':
                      cin >> index >> amount;
                      getline(cin, desc);
                      accounts[index]->withdraw(date, amount, desc);
                      break;
                  case 's':
                      for (int i = 0; i < n; i++) {
                          cout << "[" << i << "]";
                          accounts[i]->show();
                          cout << endl;
                      }
                      break;
      
                  case 'c':
                      cin >> day;
                      if (day < date.getDay()) {
                          cout << "You cannot specify a previous day";
                      } else if (day > date.getMaxDay())
                          cout << "Invalid day";
                      else date = Date(date.getYear(), date.getMonth(), day);
                      break;
                  case 'n':
                      if (date.getMonth() == 12)
                          date = Date(date.getYear() + 1, 1, 1);
                      else date = Date(date.getYear(), date.getMonth() + 1, 1);
                      for (int i = 0; i < n; i++) {
                          accounts[i]->settle(date);
                      }
                      break;
              }
          } while (cmd != 'e');
          return 0;
      }

       

      posted on 2024-12-07 19:20  陸一鳴·  閱讀(16)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 18禁免费无码无遮挡不卡网站 | 国产成人AV国语在线观看| 男女一级国产片免费视频| 麻豆精品国产熟妇aⅴ一区| 国产精品无码a∨精品| 亚洲国产高清av网站| 国产精品国产高清国产av| 国产激情免费视频在线观看| 蜜臀av日韩精品一区二区| 嘉峪关市| 免费观看欧美猛交视频黑人| 亚洲一区成人在线视频| 在线高清免费不卡全码| 亚洲天堂av在线免费看| 亚洲综合一区二区三区不卡| 日韩av高清在线看片| 国产精品欧美一区二区三区不卡| 激情一区二区三区成人文| 依依成人精品视频在线观看| 九九热精品在线观看视频| 久久香蕉国产线看观看怡红院妓院 | 久久久久免费看黄a片app| 国产自产一区二区三区视频 | 日韩毛片在线视频x| 成人网站免费观看| 亚洲欧洲av人一区二区| 91中文字幕一区在线| 韩国青草无码自慰直播专区| 色www永久免费视频| 少妇激情一区二区三区视频小说| 人人妻人人澡人人爽| 银川市| 亚洲欧洲日韩精品在线| 国产成人精品无码专区| 中文字幕人成无码免费视频| 最近中文字幕完整版2019| 思热99re视热频这里只精品| 亚洲国产精品一区二区第一页| 免费午夜无码片在线观看影院| 在线观看国产区亚洲一区| 日本道之久夂综合久久爱|