C++primer 15.4-day exercise

Source: Internet
Author: User

Exercise 15.15, Exercise 15.16

1#include <iostream>2#include <string>3#include <utility>4#include <memory>5#include <vector>6 7 using namespacestd;8 9 classQuote {Ten  Public: OneQuote () =default; AQuote (Const string&book,Doublesales_price): Bookno (book), Price (Sales_price) {} -     Const string& ISBN ()Const{returnBookno;} -     Virtual DoubleNet_price (size_t N)Const{returnn *Price ;} the     Virtual~quote () =default; - Private: -     stringBookno; - protected: +     DoublePrice =0.0; - }; +  A classDisc_quote: Publicquote{ at  Public: -Disc_quote () =default; -Disc_quote (Const string&book,DoubleSales_price, size_t Quan,Doubledis): Quote (book, Sales_price), Quantity (Quan), Discount (dis) {} -     DoubleNet_price (size_t N)Const=0; - protected: -size_t quantity =0; in     DoubleDiscount =0.0; - }; to  + classBulk_quote: PublicDisc_quote { -  Public: theBulk_quote () =default; *Bulk_quote (Const string& Book,DoubleP, size_t qty,Doubledisc): Disc_quote (Book, p, qty, disc) {} $     DoubleNet_price (size_t N)Const Override;Panax Notoginseng }; -  the classLim_discount: PublicDisc_quote { +  Public: ALim_discount () =default; theLim_discount (Const string& Book,DoubleP, size_t qty,Doubledisc): Disc_quote (Book, p, qty, disc) {} +     DoubleNet_price (size_t N)Const Override; - }; $  $ DoublePrint_total (ostream& OS,Constquote&item, size_t t); -  - intMain () the { -Bulk_quote B1 ("C + + primer",128.0,Ten,0.60);WuyiLim_discount L1 ("C + + primer",128.0, -,0.9); thePrint_total (cout, B1, One); -Print_total (cout, B1,9); WuPrint_total (cout, L1, +); -Print_total (cout, L1, +); AboutSystem"Pause"); $     return 0; - } -  - DoublePrint_total (Ostream & OS,ConstQuote &item, size_t t) A { +     DoubleRET =Item.net_price (t); theOS <<"ISBN:"<< ITEM.ISBN () <<"# Sold:"<< T <<"Total Due:"<< ret <<Endl; -     returnret; $ } the  the DoubleBulk_quote::net_price (size_t N)Const the { the     if(N >=quantity) -         returnn * (1-Discount) *Price ; in     Else the         returnn *Price ; the } About  the DoubleLim_discount::net_price (size_t N)Const the { the     if(N <=quantity) +         returnn * (1-Discount) *Price ; -     Else the         returnQuote::net_price (n);Bayi}

Exercise 15.17

1>f:\c++projicets\project1\project1\ source. cpp: Error C2259: "Disc_quote": Cannot instantiate abstract class
1> f:\c++projicets\project1\project1\ Source. cpp: NOTE: Due to the following members:
1> f:\c++projicets\project1\project1\ Source. cpp: NOTE: "Double Disc_quote::net_price (std::size_t) const": Abstract
1> f:\c++projicets\project1\project1\ source. CPP (+): note: See the "Disc_quote::net_price" statement
========== Generation: Success 0, failure 1, latest 0, skip 0 ==========

C++primer 15.4 Exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.