Answer to Question #200804 in C++ for M Kamran

Question #200804

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. 


1
Expert's answer
2021-05-30T07:29:44-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog