實驗8 Problem G 來開個書店吧

2022-05-09 09:27:09 字數 3506 閱讀 3236

home

web board

problemset

standing

status

statistics

problem g: 來開個書店吧time limit: 1 sec  memory limit: 128 mb

submit: 537  solved: 331

[submit][status][web board]某出版社可出版圖書和磁帶。其中圖書按照每頁的**乘以頁數進行定價,磁帶根據每10分鐘的**乘以磁帶錄音的分鐘數進行定價。請定義publicatioin、book、tape以及bookstore四個類。其中:

1. publication類:

1)資料成員double price表示單價(對於書,是每頁的**;對於磁帶,是每10分鐘錄音的**)。

2)資料成員int length表示出版物的長度,對於書,是頁數;對於磁帶, 是分鐘數。

3)成員函式gettotalprice()用於返回乙個出版物的定價。

4)建構函式publication(double, int)用於構造乙個出版物。

5)成員函式double getprice() const和int getlength()用於返回出版物的單價及長度。

6)析構函式。

2. book類是publication的子類。

1)建構函式book(double,int)。

2)重寫父類的gettotalprice返回定價,定價為單價乘以長度(即頁數)。

3)析構函式。

3. tape是publication的子類:

1)建構函式tape(double,int)。

2)重寫父類的gettotalprice返回定價。注意:price屬性是每10分鐘錄音的單價,而磁帶的長度不一定是10的整數倍。計算定價時,不足10分鐘部分,按照10分鐘計算。

3)析構函式。

輸入分多行。

第一行是整數m>0,表示有m個測試用例。

每個測試佔一行,分為三部分:第一部分是出版物型別(b表示book,t表示tape)、單價和數量(頁數或分鐘數)。

見樣例。

3b 0.10 201

t 0.50 100

t 0.40 105

call publication's constructor!

call book's constructor!

call publication's constructor!

call tape's constructor!

call publication's constructor!

call tape's constructor!

call publication's constructor!

call book's constructor!

call publication's constructor!

call tape's constructor!

call publication's constructor!

call tape's constructor!

there are 1 books and 2 tapes. their total price is 29.50.

call book's de-constructor!

call publication's de-constructor!

call tape's de-constructor!

call publication's de-constructor!

call tape's de-constructor!

call publication's de-constructor!

call book's de-constructor!

call publication's de-constructor!

call tape's de-constructor!

call publication's de-constructor!

call tape's de-constructor!

call publication's de-constructor!

call bookstore's de-constructor!

使用typeid判斷物件指標指向的實際物件的型別。

[submit][status][web board]

한국어<  

中文فارسی

english

ไทยsdustoj

team

gpl2.0

2003-2011

hustoj project

team

anything about the problems, please contact admin:

admin

#include#include 

#include

using

namespace

std;

class

publication

publication(

double p, int l):price(p),length(l)

double getprice() const

int getlength()

virtual ~publication()

};class book:public

publication

double gettotalprice()

~book()

};class tape:public

publication

double

gettotalprice()

~tape()

};class

bookstore

else}}

intgetnumofbook()

return

c; }

intgetnumoftape()

return

c; }

~bookstore()

delete

pubs;

cout

<<"

call bookstore's de-constructor!\n";

}};int

main()

}bookstore bookstore(pub, cases);

cout

<<"

there are

"<"

books and

"<"

tapes.";

total = 0

;

for (int i = 0; i < cases; i++)

cout

<<"

their total price is

"<2)<<"."

delete

pub;

return0;

}

實驗12 Problem G 強悍的矩陣運算來了

這個題目主要是乘法運算子的過載,卡了我好久,矩陣的乘法用3個巢狀的for迴圈進行,要分清楚矩陣的乘法結果是第乙個矩陣的行,第二個矩陣的列所組成的矩陣。過載 運算子時,可以在引數列表中傳兩個矩陣引用 分別表示前後進行運算的矩陣,或者是只傳運算子之後的矩陣引用 前乙個矩陣用的是隱含的this指標指向的矩...

實驗8 模板

1 理解函式模板 類模板,應用模板函式 模板類。2.實驗內容 1 用函式模板方式設計乙個函式模板sort,採用直接插入排序方式對資料進行排序,並對整數序列和字串行進行排序。template class t void sort t a,int n includeusing namespace std ...

實驗8 模板

實驗目的和要求 1.能夠使用c 模板機制定義過載函式。2.能夠例項化及使用模板函式。3.能夠例項化和使用模板類。4.應用標準c 模板庫 stl 通用演算法和函式物件實現查詢和排序。實驗內容 1.分析並除錯下列程式,了解函式模板的作用。sy8 1.cpp includeusing namespace ...