Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem is in C++ A customer database file named CustomerDb.txt contains a list of customers (one per line), each customer consisting of a unique customer

Problem is in C++

A customer database file named CustomerDb.txt contains a list of customers (one per line), each customer consisting of a unique customer id followed by a first and last name. Given an id, output the customer's first and last name. If the id is not found, output "Not found". If the input id is 27, the output might be "Sarah Lee" (if found).

FYI, the customer database's contents happen to be: 42 Mike Jones 16 Al Garcia 27 Sarah Lee 12 Stan Lee 99 Amy Hernandez

Hints:

The template code has functions for opening and closing the customer database file. You need not understand those functions. Just know that customerDb can be read just like cin. So customerDb >> x gets the next value from the file into variable x, just like cin >> x. You might also note that the expression evaluates to 0 when the end of file is reached, so the while loop will exit.

In the while loop, you'll want to skip the first and last names for that id, since that line's id didn't match the id to find.

After the while loop, check if the id was found (you can compare idToFind with dbId to detect this). If so, read the first and last name, and print them. Else, print "Not found".

#include #include #include int main() { std::string idToFind; // Using string for id in case has both numbers and letters, like M47 std::string dbId; std::string dbFirstName; std::string dbLastName; std::ifstream customerDb; cin >> idToFind; return 0; }

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_2

Step: 3

blur-text-image_3

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions