首页 > 其他 > 详细

期中测试题3

时间:2018-05-23 23:26:59      阅读:236      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!