図書館の本を表すクラスを実装する必要があります。各本について、タイトル、著者、ISBN コード、出版年、価格を指定する必要があります。次に、ライブラリ内のすべての本を含む配列を作成する必要があります。これは私が取り組んだコードであり、これはエラーです:
エラー C2512: 'Book': 適切な既定のコンストラクターがありません
私は何を間違っていますか?
Book.h
#ifndef BOOK_H
#define BOOK_H
#include<string>
using namespace std;
class Book
{
private:
string title;
string author;
string code;
string edit;
int year;
double price;
public:
Book();
Book(string t, string a, string c, string e, int y, double p)
{
title=t;
author=a;
code=c;
edit=e;
year=y;
price=p;
}
string GetTitle() const { return title;}
string GetAuthor() const { return author;}
string GetCode() const {return code;}
string GetEdit() const {return code;}
int GetYear() const {return year;}
double GetPrice() const {return price;}
};
#endif
Library.h
#ifndef LIBRARY_H
#define LIBRARY_H
#include"Book.h"
#include<iostream>
class Library
{
private:
Book books[50];
int index;
public:
Library()
{
index=0;
}
void Add(Book book)
{
books[index]=book;
index++;
}
void PrintAll()
{
for (int i = 0; i < index; i++)
{
Book book=books[i];
cout<<book.GetTitle()<<":"
<<book.GetAuthor()<<":"<<book.GetYear()<<endl;
}
}
};
#endif
main.cpp
#include"Library.h"
int main()
{
Library library;
Book b1("title1","author1","code1","edit1",1900,34.5);
library.Add(b1);
Book b2("title2","author2","code2","edit2",1990,12);
library.Add(b2);
library.PrintAll();
}