Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++] Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage.

[C++]

Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name. The file begins with:

Noah Emma

Liam Olivia

Mason Sophia

Jacob Ava

William Isabella

Ethan Mia

James Abigail

Write a program that asks the user to enter a name. The program then searches the file for the name and displays the position of the name in the file if it matches either a boy name or a girl name. The program also displays a message if the name could not be found.

Sample outputs:

Enter a name to search: Daniel

Daniel is ranked 12 for boy names

Daniel was not found for girls

Enter a name to search: Cassandra

Cassandra is ranked 511 for girl names

Cassandra was not found for boys

Enter a name to search: Taylor

Taylor is ranked 76 for girl names

Taylor is ranked 462 for boy names

NOTE: You can use any method you wish to match the name input on the keyboard with the names in the file. You can compare two strings ignoring upper/lower case by using #include in C++ or #include in C and the following comparison if ( stricmp(string1,string2) == 0)

If your compiler does not have stricmp, you may need to use _stricmp or strcasecmp.

THIS PROGRAM DOESN'T WORK CORRECTLY

But it might help you get started

#include #include #include #include #include #include using namespace std;

int main() { ifstream infile; string line; //for reading line from file

// string FileName char fileName[] = "FirstNames2015.txt"; // input file name string searchName; // to store name to search string boyName, girlName; // to store boy name & girl name bool boyDone = false; // if a boy name is encountered or not bool girlDone = false; // if a girl name is encountered or not

// user input for name to be searched cout << "Enter a name to search: "; cin>>searchName;

infile.open(fileName); int rank = 1; // initializwe rank to 1

// open and real file if (infile.is_open()) { while (getline(infile, line)) { // copy string line to character array str char str[1024]; strcpy(str, line.c_str()); // now tokenise char array to get two names char *pch; // extract boy name pch = strtok (str," .,-"); boyName = pch;

//strcasecmp // if boy name is not encountered already and it matches with a name in file if (!boyDone && stricmp(boyName.c_str(), searchName.c_str())==0){ cout<< boyName << " is ranked "<

// extract girl name pch = strtok (NULL," .'-"); girlName = pch; girlName = girlName.substr(0,girlName.length()-1); // if girl name is not encountered already and it matches with a name in file if (!girlDone && stricmp(girlName.c_str(), searchName.c_str())==0){ cout<

// if name found in both boys and girls name then return if(boyDone && girlDone){ break; } rank++; } // if boy name was not found if(!boyDone){ cout<< searchName <<" was not found for boys"<

}

FirstNames2015.txt

Noah Emma Liam Olivia Mason Sophia Jacob Ava William Isabella Ethan Mia James Abigail Alexander Emily Michael Charlotte Benjamin Harper Elijah Madison Daniel Amelia Aiden Elizabeth Logan Sofia Matthew Evelyn Lucas Avery Jackson Chloe David Ella Oliver Grace Jayden Victoria Joseph Aubrey Gabriel Scarlett Samuel Zoey Carter Addison Anthony Lily John Lillian Dylan Natalie Luke Hannah Henry Aria Andrew Layla Isaac Brooklyn Christopher Alexa Joshua Zoe Wyatt Penelope Sebastian Riley Owen Leah Caleb Audrey Nathan Savannah Ryan Allison Jack Samantha Hunter Nora Levi Skylar Christian Camila Jaxon Anna Julian Paisley Landon Ariana Grayson Ellie Jonathan Aaliyah Isaiah Claire Charles Violet Thomas Stella Aaron Sadie Eli Mila Connor Gabriella Jeremiah Lucy Cameron Arianna Josiah Kennedy Adrian Sarah Colton Madelyn Jordan Eleanor Brayden Kaylee Nicholas Caroline Robert Hazel Angel Hailey Hudson Genesis Lincoln Kylie Evan Autumn Dominic Piper Austin Maya Gavin Nevaeh Nolan Serenity Parker Peyton Adam Mackenzie Chase Bella Jace Eva Ian Taylor Cooper Naomi Easton Aubree Kevin Aurora Jose Melanie Tyler Lydia Brandon Brianna Asher Ruby Jaxson Katherine Mateo Ashley Jason Alexis Ayden Alice Zachary Cora Carson Julia Xavier Madeline Leo Faith Ezra Annabelle Bentley Alyssa Sawyer Isabelle Kayden Vivian Blake Gianna Nathaniel Quinn Ryder Clara Theodore Reagan Elias Khloe Tristan Alexandra Roman Hadley Leonardo Eliana Camden Sophie Brody London Luis Elena Miles Kimberly Micah Bailey Vincent Maria Justin Luna Greyson Willow Declan Jasmine Maxwell Kinsley Juan Valentina Cole Kayla Damian Delilah Carlos Andrea Max Natalia Harrison Lauren Weston Morgan Brantley Rylee Braxton Sydney Axel Adalynn Diego Mary Abel Ximena Wesley Jade Santiago Liliana Jesus Brielle Silas Ivy Giovanni Trinity Bryce Josephine Jayce Adalyn Bryson Jocelyn Alex Emery Everett Adeline George Jordyn Eric Ariel Ivan Everly Emmett Lilly Kaiden Paige Ashton Isla Kingston Lyla Jonah Makayla Jameson Molly Kai Emilia Maddox Mya Timothy Kendall Ezekiel Melody Ryker Isabel Emmanuel Brooke Hayden Mckenzie Antonio Nicole Bennett Payton Steven Margaret Richard Mariah Jude Eden Luca Athena Edward Amy Joel Norah Victor Londyn Miguel Valeria Malachi Sara King Aliyah Patrick Angelina Kaleb Gracie Bryan Rose Alan Rachel Marcus Juliana Preston Laila Abraham Brooklynn Calvin Valerie Colin Alina Bradley Reese Jeremy Elise Kyle Eliza Graham Alaina Grant Raelynn Jesse Leilani Kaden Catherine Alejandro Emerson Oscar Cecilia Jase Genevieve Karter Daisy Maverick Harmony Aidan Vanessa Tucker Adriana Avery Presley Amir Rebecca Brian Destiny Iker Hayden Matteo Julianna Caden Michelle Zayden Adelyn Riley Arabella August Summer Mark Callie Maximus Kaitlyn Brady Ryleigh Kenneth Lila Paul Daniela Jaden Arya Nicolas Alana Beau Esther Dean Finley Jake Gabrielle Peter Jessica Xander Charlie Elliot Stephanie Finn Tessa Derek Makenzie Sean Ana Cayden Amaya Elliott Alexandria Jax Alivia Jasper Nova Lorenzo Anastasia Omar Iris Beckett Marley Rowan Fiona Gael Angela Corbin Giselle Waylon Kate Myles Alayna Tanner Lola Jorge Lucia Javier Juliette Zion Parker Andres Teagan Charlie Sienna Paxton Georgia Emiliano Hope Brooks Cali Zane Vivienne Simon Izabella Judah Kinley Griffin Daleyza Cody Kylee Gunner Jayla Dawson Katelyn Israel Juliet Rylan Maggie Gage Dakota Messiah Delaney River Brynlee Kameron Keira Stephen Camille Francisco Leila Clayton Mckenna Zander Aniyah Chance Noelle Eduardo Josie Spencer Jennifer Lukas Melissa Damien Gabriela Dallas Allie Conner Eloise Travis Cassidy Knox Jacqueline Raymond Brynn Peyton Sawyer Devin Evangeline Felix Jordan Jayceon Paris Collin Olive Amari Ayla Erick Rosalie Cash Kali Jaiden Maci Fernando Gemma Cristian Lilliana Josue Raegan Keegan Lena Garrett Adelaide Rhett Journey Ricardo Adelynn Martin Alessandra Reid Kenzie Seth Miranda Andre Haley Cesar June Titus Harley Donovan Charlee Manuel Lucille Mario Talia Caiden Skyler Adriel Makenna Kyler Phoebe Milo Jane Archer Lyric Jeffrey Angel Holden Elaina Arthur Adrianna Karson Ruth Rafael Miriam Shane Diana Lane Mariana Louis Danielle Angelo Jenna Remington Shelby Troy Nina Emerson Madeleine Maximiliano Elliana Hector Amina Emilio Amiyah Anderson Chelsea Trevor Joanna Phoenix Jada Walter Lexi Johnathan Katie Johnny Maddison Edwin Fatima Julius Vera Barrett Malia Leon Lilah Tyson Madilyn Tobias Amanda Edgar Daniella Dominick Alexia Marshall Kathryn Marco Paislee Joaquin Selena Dante Laura Andy Annie Cruz Nyla Ali Catalina Finley Kayleigh Dalton Sloane Gideon Kamila Reed Lia Enzo Haven Sergio Rowan Jett Ashlyn Thiago Christina Kyrie Amber Ronan Myla Cohen Addilyn Colt Erin Erik Alison Trenton Ainsley Jared Raelyn Walker Cadence Landen Kendra Alexis Heidi Nash Kelsey Jaylen Nadia Gregory Alondra Emanuel Cheyenne Killian Kaydence Allen Mikayla Atticus River Desmond Heaven Shawn Arielle Grady Lana Quinn Blakely Frank Sabrina Fabian Kyla Dakota Ada Roberto Gracelyn Beckham Allyson Major Felicity Skyler Kira Nehemiah Briella Drew Kamryn Cade Adaline Muhammad Alicia Kendrick Ember Pedro Aylin Orion Veronica Aden Esmeralda Kamden Sage Ruben Leslie Zaiden Aspen Clark Gia Noel Camilla Porter Ashlynn Solomon Scarlet Romeo Journee Rory Daphne Malik Bianca Daxton Mckinley Leland Amira Kash Carmen Abram Kyleigh Derrick Megan Kade Skye Gunnar Elsie Prince Kennedi Brendan Averie Leonel Carly Kason Rylie Braylon Gracelynn Legend Mallory Pablo Emersyn Jay Logan Adan Camryn Jensen Annabella Esteban Dylan Kellan Elle Drake Kiara Warren Yaretzi Ismael Ariella Ari Zara Russell April Bruce Gwendolyn Finnegan Anaya Marcos Baylee Jayson Brinley Theo Sierra Jaxton Annalise Phillip Tatum Dexter Serena Braylen Dahlia Armando Macy Braden Miracle Corey Madelynn Kolton Briana Gerardo Freya Ace Macie Ellis Helen Malcolm Bethany Tate Leia Zachariah Harlow Chandler Blake Milan Jayleen Keith Angelica Danny Marilyn Damon Viviana Enrique Francesca Jonas Juniper Kane Carolina Princeton Jazmin Hugo Emely Ronald Maliyah Philip Cataleya Ibrahim Jillian Kayson Joy Maximilian Abby Lawson Malaysia Harvey Nylah Albert Sarai Donald Evelynn Raul Nia Franklin Zuri Hendrix Addyson Odin Aleah Brennan Kaia Jamison Bristol Dillon Lorelei Brock Jazmine Landyn Maeve Mohamed Alejandra Brycen Justice Deacon Julie Colby Marlee Alec Phoenix Julio Jimena Scott Emmalyn Matias Nayeli Sullivan Aleena Rodrigo Brittany Cason Amara Taylor Karina Rocco Giuliana Nico Thea Royal Braelynn Pierce Kassidy Augustus Braelyn Raiden Luciana Kasen Aubrie Benson Janelle Moses Madisyn Cyrus Brylee Raylan Leighton Davis Ryan Khalil Amari Moises Eve Conor Millie Nikolai Kelly Alijah Selah Mathew Lacey Keaton Willa Francis Haylee Quentin Jaylah Ty Sylvia Jaime Melany Ronin Elisa Kian Elsa Lennox Hattie Malakai Raven Atlas Holly Jerry Aisha Ryland Itzel Ahmed Kyra Saul Tiffany Sterling Jayda Dennis Michaela Lawrence Madilynn Zayne Jamie Bodhi Celeste Arjun Lilian Darius Remi Arlo Priscilla Eden Jazlyn Tony Karen Dustin Savanna Kellen Zariah Chris Lauryn Mohammed Alanna Nasir Kara Omari Karla Kieran Cassandra Nixon Ariah Rhys Evie Armani Frances Arturo Aileen Bowen Lennon Frederick Charley Callen Rosemary Leonidas Danna Remy Regina Wade Kaelyn Luka Virginia Jakob Hanna Winston Rebekah Justice Alani Alonzo Edith Curtis Liana Aarav Charleigh Gustavo Gloria Royce Cameron Asa Colette Gannon Kailey Kyson Carter Hank Helena Izaiah Matilda Roy Imani Raphael Bridget Luciano Cynthia Hayes Janiyah Case Marissa Darren Johanna Mohammad Sasha Otto Kaliyah Layton Cecelia Isaias Adelina Alberto Jessa Jamari Hayley Colten Julissa Dax Winter Marvin Crystal Casey Kaylie Moshe Bailee Johan Charli Sam Henley Matthias Anya Larry Maia Trey Skyla Devon Liberty Trent Fernanda Mauricio Monica Mathias Braylee Issac Dallas Dorian Mariam Gianni Marie Ahmad Beatrice Nikolas Hallie Oakley Maryam Uriel Angelique Lewis Anne Randy Madalyn Cullen Alayah Braydon Annika Ezequiel Greta Reece Lilyana Jimmy Kadence Crosby Coraline Soren Lainey Uriah Mabel Roger Lillie Nathanael Anika Emmitt Azalea Gary Dayana Rayan Jaliyah Ricky Addisyn Mitchell Emilee Roland Mira Alfredo Angie Cannon Lilith Jalen Mae Tatum Meredith Kobe Guadalupe Yusuf Emelia Quinton Margot Korbin Melina Brayan Aniya Joe Alena Byron Myra Ariel Elianna Quincy Caitlyn Carl Jaelynn Kristopher Jaelyn Alvin Demi Duke Mikaela Lance Tiana London Blair Jasiah Shiloh Boston Ariyah Santino Saylor Lennon Caitlin Deandre Lindsey Madden Oakley Talon Alia Sylas Everleigh Orlando Ivanna Hamza Miah Bo Emmy Aldo Jessie Douglas Anahi Tristen Kaylin Wilson Ansley Maurice Annabel Samson Remington Cayson Kora Bryant Maisie Conrad Nathalie Dane Emory Julien Karsyn Sincere Pearl Noe Irene Salvador Kimber Nelson Rosa Edison Lylah Ramon Magnolia Lucian Samara Mekhi Elliot Niko Renata Ayaan Galilea Vihaan Kensley Neil Kiera Titan Whitney Ernesto Amelie Brentley Siena Lionel Bria Zayn Laney Dominik Perla Cassius Tatiana Rowen Zelda Blaine Jaycee Sage Kori Kelvin Montserrat Jaxen Lorelai Memphis Adele Leonard Elyse Abdullah Katelynn Jacoby Kynlee Allan Marina Jagger Jayden Yahir Kailyn Forrest Avah Guillermo Kenley Mack Aviana Zechariah Armani Harley Dulce Terry Alaia Kylan Teresa Fletcher Natasha Rohan Milani Eddie Amirah Bronson Breanna Jefferson Linda Rayden Tenley Terrance Sutton Marc Elaine Morgan Elliott Valentino Aliza Demetrius Kenna Kristian Meadow Hezekiah Alyson Lee Rory Alessandro Milana Makai Erica Rex Esme Callum Leona Kamari Joselyn Casen Madalynn Tripp Alma Callan Chanel Stanley Myah Toby Karter Elian Zahra Langston Audrina Melvin Ariya Payton Jemma Flynn Eileen Jamir Kallie Kyree Milan Aryan Emmalynn Axton Lailah Azariah Sloan Branson Clarissa Reese Karlee Adonis Laylah Thaddeus Amiya Zeke Collins Tommy Ellen Blaze Hadassah Carmelo Danica Skylar Jaylene Arian Averi Bruno Reyna Kaysen Saige Layne Wren Ray Lexie Zain Dorothy Crew Lilianna Jedidiah Monroe Rodney Aryanna Clay Elisabeth Tomas Ivory Alden Liv Jadiel Janessa Harper Jaylynn Ares Livia Cory Rayna Brecken Alaya Chaim Malaya Nickolas Cara Kareem Erika Xzavier Amani Kaison Clare Alonso Addilynn Amos Roselyn Vicente Corinne Samir Paola Yosef Jolene Jamal Anabelle Jon Aliana Bobby Lea Aron Mara Ben Lennox Ford Claudia Brodie Kristina Cain Jaylee Finnley Kaylynn Briggs Zariyah Davion Gwen Kingsley Kinslee Brett Avianna Wayne Lisa Zackary Raquel Apollo Jolie Emery Carolyn Joziah Courtney Lucca Penny Bentlee Royal Hassan Alannah Westin Ciara Joey Chaya Vance Kassandra Marcelo Milena Axl Mina Jermaine Noa Chad Leanna Gerald Zoie Kole Ariadne Dash Monserrat Dayton Nola Lachlan Carlee Shaun Isabela Kody Jazlynn Ronnie Kairi Kolten Laurel Marcel Sky Stetson Rosie Willie Arely Jeffery Aubrielle Brantlee Kenia Elisha Noemi Maxim Scarlette Kendall Farrah Harry Leyla Leandro Amia Aaden Bryanna Channing Naya Kohen Wynter Yousef Hunter Darian Katalina Enoch Taliyah Mayson Amaris Neymar Emerie Giovani Martha Alfonso Thalia Duncan Christine Anders Estrella Braeden Brenna Dwayne Milania Keagan Salma Felipe Lillianna Fisher Marjorie Stefan Shayla Trace Zendaya Aydin Aurelia Anson Brenda Clyde Julieta Blaise Adilynn Canaan Deborah Maxton Keyla Alexzander Patricia Billy Emmeline Harold Hadlee Baylor Giovanna Gordon Kailee Rene Desiree Terrence Casey Vincenzo Karlie Kamdyn Khaleesi Marlon Lara Castiel Tori Lamar Clementine Augustine Nancy Jamie Simone Eugene Ayleen Harlan Estelle Kase Celine Miller Madyson Van Zaniyah Kolby Adley Sonny Amalia Emory Paityn Junior Kathleen Graysen Sandra Heath Lizbeth Rogelio Maleah Will Micah Amare Aryana Ameer Hailee Camdyn Aiyana Jerome Joyce Maison Ryann Micheal Caylee Cristiano Kalani Giancarlo Marisol Henrik Nathaly Lochlan Briar Bode Holland Camron Lindsay Houston Remy Otis Adrienne Hugh Azariah Kannon Harlee Konnor Dana Emmet Frida Kamryn Marianna Maximo Yamileth Adrien Chana Cedric Kaya Dariel Lina Landry Celia Leighton Analia Magnus Hana Draven Jayde Javon Joslyn Marley Romina Zavier Anabella Markus Barbara Justus Bryleigh Reyansh Emilie Rudy Nathalia Santana Ally Misael Evalyn Abdiel Bonnie Davian Zaria Zaire Carla Jordy Estella Reginald Kailani Benton Rivka Darwin Rylan Franco Paulina Jairo Kayden Jonathon Giana Reuben Yareli Urijah Kaiya Vivaan Sariah Brent Avalynn Gauge Jasmin Vaughn Aya Coleman Jewel Zaid Kristen Terrell Paula Kenny Astrid Brice Jordynn Lyric Kenya Judson Ann Shiloh Annalee Damari Kai Kalel Kiley Braiden Marleigh Brenden Julianne Coen Zion Denver Emmaline Javion Nataly Thatcher Aminah Rey Amya Dilan Iliana Dimitri Jaida Immanuel Paloma Mustafa Asia Ulises Louisa Alvaro Sarahi Dominique Tara Eliseo Andi Anakin Arden Craig Dalary Dario Aimee Santos Alisson Grey Halle Ishaan Aitana Jessie Landry Jonael Alisha Alfred Elin Tyrone Maliah Valentin Belen Jadon Briley Turner Raina Ignacio Vienna Riaan Esperanza Rocky Judith Ephraim Faye Marquis Susan Musa Aliya Keenan Aranza Ridge Yasmin Chace Jaylin Kymani Kyndall Rodolfo Saniyah Darrell Wendy Steve Yaritza Agustin Azaria Jaziel Kaelynn Boone Neriah Cairo Zainab Kashton Alissa Rashad Cherish Gibson Dixie Jabari Veda Avi Nala Quintin Tabitha Seamus Cordelia Rolando Ellison Sutton Meilani Camilo Angeline Triston Reina Yehuda Tegan Cristopher Hadleigh Davin Harmoni Ernest Kimora Jamarion Ingrid Kamren Lilia Salvatore Luz Anton Aislinn Aydan America Huxley Ellis Jovani Elora Wilder Heather Bodie Natalee Jordyn Miya Louie Heavenly Achilles Jenny Kaeden Aubriella Kamron Emmalee Aarush Kensington Deangelo Kiana Robin Lilyanna Yadiel Tinley Yahya Ophelia Boden Moriah Ean Sharon Kye Charlize Kylen Abril Todd Avalyn Truman Mariyah Chevy Taya Gilbert Ireland Haiden Lyra Brixton Noor Dangelo Sariyah Juelz Giavanna Osvaldo Stevie Bishop Rhea Freddy Zaylee Reagan Denise Frankie Frankie Malaki Janiya Camren Jocelynn Deshawn Libby Jayvion Aubrianna Leroy Kaitlynn Briar Princess Jaydon Sidney Antoine Alianna

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

How is E-business a more broad concept than e-commerce?

Answered: 1 week ago

Question

Understanding Group Leadership Culture and Group Leadership

Answered: 1 week ago