VectorCollection
これを教えてください。インスタンスが文字列型であるベクトルのコレクションを格納するために使用されるクラスを含むプログラムを作成する必要があります。次のエラーが表示されます
std::cout の operator<< に一致しません
を使用してベクトルを出力しようとするとcout << (*it) << endl;
課題の全文をフォーラムに投稿するのは少し気が進まなかったのですが、混乱を避けるためにここに投稿しました。私は完全に軌道から外れている可能性があると思うので、ガイダンスがあれば感謝します。
インスタンスが文字列型のベクトルのコレクションを格納するために使用される VectorCollection というクラスを含む cpp プログラムを作成します。コレクション内の値を初期化するための文字列の配列を受け取る単一パラメーター コンストラクターを記述します。コレクションへのインスタンスの追加、コレクションからのインスタンスの削除、コレクションからのすべてのエントリの削除、およびコレクション全体の表示を行う関数を追加します。また、* 演算子をオーバーレイして、2 つの VectorCollection オブジェクトの共通部分を返すようにします。クラス内のすべてのメンバー関数とオーバーロードされた演算子をテストするプログラムを作成します。次に、main 関数を変更して、各 Movie オブジェクトに対して個別の変数を作成する代わりに、サンプル データを使用して少なくとも 4 つの Movie オブジェクトの配列を作成します。配列をループして名前を出力し、
//movies.h
//******************************************************************************************************
using namespace std;
#ifndef movies_H
#define movies_H
class VectorCollection
{
//member variables
string newtitle,newgentre,newmpaa,newrating;
vector<VectorCollection> movies;
public:
//function declarations
//default constructor
VectorCollection();
//overload constructor
VectorCollection(string,string,string,string);
//destructor
~VectorCollection();
void settitle(string);
void setgentre(string);
void setmpaa(string);
void setrating(string);
void display(vector<VectorCollection>);
};
#endif // MOVIES_H_INCLUDED
//movies.cpp
//******************************************************************************************************
//constructor definition
VectorCollection::VectorCollection()
{
}
//overloaded constructor def
VectorCollection::VectorCollection(string title,string gentre,string mpaa,string rating)
{
newtitle = title;
newgentre = gentre;
newmpaa = mpaa;
newrating = rating;
}
//destructor def
VectorCollection::~VectorCollection()
{
}
//mutator function
void VectorCollection::settitle(string title)
{
newtitle = title;
}
//mutator function
void VectorCollection::setgentre(string gentre)
{
newgentre = gentre;
}
//mutator function
void VectorCollection::setmpaa(string mpaa)
{
newmpaa = mpaa;
}
//mutator function
void VectorCollection::setrating(string rating)
{
newrating = rating;
}
void VectorCollection::display(vector<VectorCollection> movies)
{
vector<VectorCollection>::iterator it;
for ( it = movies.begin(); it < movies.end(); ++it)
{
//copy(movies.begin(),movies.end(),ostream_iterator<string>(cout," "));
cout << (*it) << endl;
}
}
//main.cpp
//******************************************************************************************************
#include <iostream>
#include <string>
#include "movies.h"
using namespace std;
int main()
{
string title,gentre,mpaa,rating;
vector<VectorCollection> movies;
movies.assign(4,VectorCollection());
VectorCollection *a_movie;
VectorCollection list;
for (int i = 0; i < 3; i++)
{
cout << "Enter the title : ";
cin >> title;
cout << "Enter the gentre: ";
cin >> gentre;
cout << "Enter the MPAA: ";
cin >> mpaa;
cout << "Enter the rating: ";
cin >> rating;
a_movie = new VectorCollection;
a_movie ->settitle(title);
a_movie ->setgentre(gentre);
a_movie ->setmpaa(mpaa);
a_movie ->setrating(rating);
movies.push_back(*a_movie);
cin.get();
}
list.display(movies);
return 0;
}