Write a function of print_customer and print list of customers whose age is between 18 and 30, or whose gender is female. Attributes of customer are name, age and gender.
#include <iostream>
#include <iomanip>
#include <string>
struct customer
{
std::string name;
int age;
std::string gender;
};
void print_customer(const customer* data, int size)
{
for(int i = 0; i < size; ++i)
{
if(data[i].gender == "female" || (18 <= data[i].age && data[i].age <= 30))
{
std::cout << std::setw(18) << std::left << data[i].name << "\t"
<< data[i].age << "\t" << data[i].gender << "\n";
}
}
}
int main()
{
customer customers[] = {{"Daenerys Targaryen", 13, "female"},
{"Jon Snow", 18, "male"},
{"Tyrion Lannister", 40, "male"}};
print_customer(customers, sizeof(customers) / sizeof(customers[0]));
return 0;
}
Comments
Leave a comment