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 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <string>
using namespace std;
const size_t MAX_ITEMS = 10;
class Item
{
string m_desc;
unsigned int m_price;
unsigned int m_code;
public:
Item(string _desc , unsigned int _price , unsigned int _code)
: m_desc(_desc) , m_price(_price) , m_code(_code)
{
}
~Item(void)
{
}
void display(void) const
{
std::cout << "Price : " << m_price << "$ Desc : " << m_desc << std::endl;
}
unsigned int getCode(void)const
{
return m_code;
}
} g_items[MAX_ITEMS] =
{
{"apple" , 10 , 1112},
{"banana" , 10 , 1113},
{"pear" , 10 , 1114},
{"tomato" , 10 , 1115},
{"cucumber" , 10 , 1116},
{"grape" , 10 , 1117},
{"wine" , 10 , 1118},
{"juice" , 10 , 1119},
{"gum" , 10 , 1120},
{"magazine" , 10 , 1121}
};
bool display(unsigned int _code)
{
bool foundItem = false;
for(size_t i = 0 ; i < MAX_ITEMS ; ++ i)
if( g_items[i].getCode() == _code)
{
g_items[i].display();
foundItem = true;
break;
}
return foundItem;
}
int main(int argc , char * argv[])
{
display(1112);
display(1113);
display(1114);
display(1115);
display(1116);
display(1117);
display(1118);
display(1119);
display(1120);
display(1121);
// system("pause");
return EXIT_SUCCESS;
}
|