You can use the following functions to do case insensitive string comparison. Place them in your functions file and include appropriate prototypes in your header file. #include #include string stringToLower(string s) { string result = ""; for (int i = 0; i < s.length(); i++) result += tolower(s[i]);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

See attached images.

Please help - C++

CASE INSENSITIVE STRING COMPARISON
You can use the following functions to do case insensitive string comparison. Place them in your functions file
and include appropriate prototypes in your header file.
#include <string>
#include <cstdlib>
string stringToLower(string s)
{
string result = "";
for (int i = 0; i < s.length(); i++)
result += tolower(s[i]);
return result;
}
bool isEqual(string s1, string s2)
return stringToLower(s1)
stringTolower(s2);
==
}
bool isGreater(string s1, string s2)
{
return stringToLower (s1) > stringToLower(s2); }
Transcribed Image Text:CASE INSENSITIVE STRING COMPARISON You can use the following functions to do case insensitive string comparison. Place them in your functions file and include appropriate prototypes in your header file. #include <string> #include <cstdlib> string stringToLower(string s) { string result = ""; for (int i = 0; i < s.length(); i++) result += tolower(s[i]); return result; } bool isEqual(string s1, string s2) return stringToLower(s1) stringTolower(s2); == } bool isGreater(string s1, string s2) { return stringToLower (s1) > stringToLower(s2); }
Write a small application to maintain contact information about people. For each person in your contacts list,
you will maintain the following information: name, phone number, and e-mail address. Your list should be able
to handle a maximum of 100 people. In this program, vou will use an array of structs to store the three atributes
of each person in the contact list.
o See p. 548-549 to see how to use the isdigit library function to make this task easier.
Prompt for the first name separately from the last name. Do not make any assumptions about the
content of the name (for example, either the first or last name might be multiple words).
When the user inputs the email, you should validate it. For our purposes, that means the email
must:
o Contain exactly one @
o Following the @, it must have at least one character, followed by one dot, followed by at
least one character.
Your application should display the following menu:
Main Menu
Delete Person:
A - Add Person
Prompt for and read a last name (only). Search the array for the person, and remove their information
from the list. For simplicity, you may assume that all last names are unique. Display an appropriate error
message if the person is not in the list.
Note: the last name comparison should be case insensitive.
Note: You should not have “blank" entries in your array between names. When you delete an
entry you should “move up" the names after the one you deleted.
D - Delete Person
F - Find and Display Person
L - List All People
S - Save List
E - Exit
Find and Display a Person
Prompt for and read a last name (only). Search the array for the person and display all the information
about that person, or an error message if the person is not in the list.
Note: just as with Delete Person, the last name comparison should be case insensitive.
Enter Choice:
Your program should continue to display the above menu and perform the indicated action until the "E" option
is selected. You do not need to clear the screen between each operation; simply allow the display to scroll
normally. The user should be able to enter either upper or lower case letters when choosing from the menu.
List all People
Display information about every person in the list. This information should be sorted by last name. Use
the bubble sort algorithm given in your book (you will need to modify the algorithm to work with this
data). The comparisons in the sort must be case insensitive.
Each option is described in more detail below.
Save the List
Add Person:
Prompt for and read a name, phone number, and e-mail address from the user. Use this information to
populate the appropriate elements of array. NOTE:
You must validate the phone number. For our purposes, a valid phone number is a string that
contains only digits, dashes, dots, spaces, and parentheses. To keep things simple, you don't
have to verify that the actual content is meaningful, you only have to verify that it doesn’t
contain invalid characters (e.g., we will treat even a phone number like ..-9999) as a valid phone
number).
o Hint: You can access individual characters in a string using standard array notation (eg.,
given that phone is a string variable, you can use phone[i] in a loop to access each
character. Use phone.length() to get the length of the string).
Write the contents of the array to a file named "contacts.txt" in the current directory. Do not prompt the
user for the name of the file; always use the file contacts.txt. Existing contents in the file (if any) should
be replaced by the new data (this will happen automatically when you open the file for writing (use
ofstream to open the file for writing). Each person's data should be written on a separate line of the file,
in the following format:
lastname, firstname,phone,e-mail
All values should be comma-separated in the file (no spaces around commas). The comma is not part of
the data in-memory; commas are in the file only to separate the data values. We are not expecting the
user to ever look at or modify this file directly; all operations on the file are performed by your program.
When your programs starts, it should automatically read and populate the array by reading the contacts.txt file.
If the file is empty or nonexistent, then the program begins its operation with an empty list (this is not
considered an error; it just means we have an empty list).
When the program ends you should ask if the user wants to save their data.
Implementation Issues
Your solution should contain at least one function per Main-Menu option (i.e., a function to add a person, a
function to delete a person, etc.), and you should have additional functions that perform well-defined tasks
(e.g., validate the phone number).
You may assume that there are no duplicate last names in the list.
All updates (add, deletions) are made in-memory only; do not attempt to update the data directly in the file.
At the beginning of the program, you will read the entire file into the array of structs. Your program will
then add/delete from the array in memory. When the user tells you to save the data, the entire previous
contents of the file are replaced with the updated list (using ofstream to write to the file will cause this
behavior).
You can use the functions at the end of this document to do case insensitive string comparisons.
Transcribed Image Text:Write a small application to maintain contact information about people. For each person in your contacts list, you will maintain the following information: name, phone number, and e-mail address. Your list should be able to handle a maximum of 100 people. In this program, vou will use an array of structs to store the three atributes of each person in the contact list. o See p. 548-549 to see how to use the isdigit library function to make this task easier. Prompt for the first name separately from the last name. Do not make any assumptions about the content of the name (for example, either the first or last name might be multiple words). When the user inputs the email, you should validate it. For our purposes, that means the email must: o Contain exactly one @ o Following the @, it must have at least one character, followed by one dot, followed by at least one character. Your application should display the following menu: Main Menu Delete Person: A - Add Person Prompt for and read a last name (only). Search the array for the person, and remove their information from the list. For simplicity, you may assume that all last names are unique. Display an appropriate error message if the person is not in the list. Note: the last name comparison should be case insensitive. Note: You should not have “blank" entries in your array between names. When you delete an entry you should “move up" the names after the one you deleted. D - Delete Person F - Find and Display Person L - List All People S - Save List E - Exit Find and Display a Person Prompt for and read a last name (only). Search the array for the person and display all the information about that person, or an error message if the person is not in the list. Note: just as with Delete Person, the last name comparison should be case insensitive. Enter Choice: Your program should continue to display the above menu and perform the indicated action until the "E" option is selected. You do not need to clear the screen between each operation; simply allow the display to scroll normally. The user should be able to enter either upper or lower case letters when choosing from the menu. List all People Display information about every person in the list. This information should be sorted by last name. Use the bubble sort algorithm given in your book (you will need to modify the algorithm to work with this data). The comparisons in the sort must be case insensitive. Each option is described in more detail below. Save the List Add Person: Prompt for and read a name, phone number, and e-mail address from the user. Use this information to populate the appropriate elements of array. NOTE: You must validate the phone number. For our purposes, a valid phone number is a string that contains only digits, dashes, dots, spaces, and parentheses. To keep things simple, you don't have to verify that the actual content is meaningful, you only have to verify that it doesn’t contain invalid characters (e.g., we will treat even a phone number like ..-9999) as a valid phone number). o Hint: You can access individual characters in a string using standard array notation (eg., given that phone is a string variable, you can use phone[i] in a loop to access each character. Use phone.length() to get the length of the string). Write the contents of the array to a file named "contacts.txt" in the current directory. Do not prompt the user for the name of the file; always use the file contacts.txt. Existing contents in the file (if any) should be replaced by the new data (this will happen automatically when you open the file for writing (use ofstream to open the file for writing). Each person's data should be written on a separate line of the file, in the following format: lastname, firstname,phone,e-mail All values should be comma-separated in the file (no spaces around commas). The comma is not part of the data in-memory; commas are in the file only to separate the data values. We are not expecting the user to ever look at or modify this file directly; all operations on the file are performed by your program. When your programs starts, it should automatically read and populate the array by reading the contacts.txt file. If the file is empty or nonexistent, then the program begins its operation with an empty list (this is not considered an error; it just means we have an empty list). When the program ends you should ask if the user wants to save their data. Implementation Issues Your solution should contain at least one function per Main-Menu option (i.e., a function to add a person, a function to delete a person, etc.), and you should have additional functions that perform well-defined tasks (e.g., validate the phone number). You may assume that there are no duplicate last names in the list. All updates (add, deletions) are made in-memory only; do not attempt to update the data directly in the file. At the beginning of the program, you will read the entire file into the array of structs. Your program will then add/delete from the array in memory. When the user tells you to save the data, the entire previous contents of the file are replaced with the updated list (using ofstream to write to the file will cause this behavior). You can use the functions at the end of this document to do case insensitive string comparisons.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY