码迷,mamicode.com
首页 > 其他好文 > 详细

期中测试题3

时间:2018-05-23 23:31:48      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:turn   cin   efi   oat   tor   private   str   book   out   

main.cpp

#include <iostream>
#include<vector>
#include"Book.h"
using namespace std;

int main()
{
    vector<Book> books;
    string cx,cv;
    float pl;
    while(cin>>cx>>cv>>pl)
    {
        Book a(cx,cv,pl);
        books.push_back(a);
    }
    for(int i=0;i<books.size();i++)
    {
        books[i].print();
    }
    return 0;
}

book.h

#ifndef BOOK_H_INCLUDED
#define BOOK_H_INCLUDED
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class Book
{
    public:
        Book(string a,string c,float v);
        void print();
    private:
        string isbn;
        string title;
        double price;
};

#endif // BOOK_H_INCLUDED

book.cpp

#include "Book.h"
Book::Book(string a,string b,float c):isbn(a),title(b),price(c){}
void Book::print()
{
    cout<<"出版编号:"<<isbn<<"    "<<"书名:"<<title<<"    "<<"定价:"<<price<<"  RMB"<<endl;
}

 

期中测试题3

标签:turn   cin   efi   oat   tor   private   str   book   out   

原文地址:https://www.cnblogs.com/haruna/p/9080089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!