期中测试题3
Posted haruna
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了期中测试题3相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章