1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class bag {
string arr[5];
string type;
string name;
double price;
public:
bag (){};
bag (string a, string b, double num, string * c);
bool find(string);
void print();
};
bag::bag (string a, string b, double num, string * c)
: type(b), name(a), price(num)
{
for (int i=0; i<5;i++)
{
arr[i] = c[i];
}
}
void bag::print()
{
cout << "The Bag Brand is: " << name
<< "\nThe Type of the Bag is: " << type
<< "\nThe Price of the Bag is: " << price
<< endl;
cout<<"The item is : \n";
for (int i=0; i<5; i++)
{
cout<<arr[i] << endl;
}
}
bool bag::find(string item_name)
{
for (int i=0; i<5; i++)
if (arr[i] == item_name)
return true;
return false;
}
int main()
{
string a[5]={"pens","books","glasses","Ipad","Headphones"};
bag c("adiddas" ,"back-bag",50,a);
c.print();
cout << boolalpha << c.find("pens");
}
|