Classes that first recognize C + +

Source: Internet
Author: User

Sales_item.h
#ifndef salesitem_h#define salesitem_h#include <iostream> #include <string>class sales_item{public:std:: IStream &input (std::istream & in), std::ostream & Output (std::ostream & Out) const;double avg_price () Const;bool SAME_ISBN (sales_item& Rhs) const; Sales_item Add (sales_item& other); Sales_item::sales_item (): unit_sale (0), revenue (0) {}private:std::string ISBN;//ISBN int unit_sale;//quantity Double Revenue;//total price}; #endif

Sales_item.cpp#include "sales_item.h" std::istream& sales_item::input (std::istream & In) {double price;in >> ISBN >> Unit_sale >> price;if (in) revenue = Unit_sale*price;else{unit_sale = 0;revenue = 0.0;} Return in;} std::ostream& sales_item::output (std::ostream & Out) const{out << ISBN << "\ t" << Unit_sale << "\ t" << revenue << "\ t" << avg_price (); return out;} Double Sales_item::avg_price () const{if (unit_sale) return Revenue/unit_sale;elsereturn 0.0; BOOL SALES_ITEM::SAME_ISBN (sales_item& rhs) const{return ISBN = = rhs.isbn;} Sales_item sales_item::add (sales_item& other) {unit_sale + = other.unit_sale;revenue + Other.revenue;return *this;}

  

Main.cpp#include <iostream>//#include <string>//#include <vector>//#include <cctype>//# Include <cstring>//#include <bitset> #include "sales_item.h" using namespace Std;int main (int argc, char * * Argv) {sales_item total, trans;cout << ' Enter some transaction (ctrl + Z to end) ' << endl;if (total.input (CIN)) {//read into the first trade while (trans.input (CIN)) {if (total.same_isbn (trans)) total.add (trans); else{total.output (cout); trans;}} Output last trade total.output (cout) << endl;} Else{cout << "No data!" << endl;return-1;} cout << Endl;system ("pause"); return 0;}

  

  

Classes that first recognize C + +

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.