c++ primer 習題7.31 自己編寫Sales_item類

篤志好學者發表於2013-08-18
Sales_item.h
#pragma once
#include<string>
#include<iostream>
class Sales_item
{
public:
	Sales_item():units_sold(0),price(0){};
	void read();	
	void prints();
private:
	std::string isbn;
	unsigned units_sold;
	double price;
};

Sales_item.cpp

#include "Sales_item.h"
#include<string>
#include<iostream>
void Sales_item::read(){
		std::cin>>isbn>>units_sold>>price;
	}
void Sales_item::prints(){
		std::cout<<isbn<<" "<<units_sold<<" "<<price<<std::endl;
	}
main主函式
#include<iostream>
#include "Sales_item.h"


int main()
{
	Sales_item it;
	it.read();
	it.prints();
	system("pause");
	return 0;
}


相關文章