matches.txt file data bellow. ``` Charlie Bradbury F 42 65 N Green 5558675309 Bobby Singer M 70 69 Y Brown 5558675309 Dean Winchester M 43 72 N Brown 5558675309 Sam Winchester M 39 75 N Brown 5558675309 Jody Mills F 51 65 N Brown 5558675309 Bela Talbot F 39 69 Y Blue 5558675309 James Novak M 46 71 Y Blue 5558675309 ``` code. #include #include #include #include using namespace std; int main() { char user_gender, user_smoker; string user_eyecolor; int user_minAge, user_maxAge, user_minHeight, user_maxHeight; cout << "What is the gender of your ideal match(M, F, N) ? "; cin >> user_gender; cout << "What is the minimum age? "; cin >> user_minAge; cout << "What is the maximum age? "; cin >> user_maxAge; cout << "What is the minimum height (in inches)? "; cin >> user_minHeight; cout << "What is the maximum height (in inches)? "; cin >> user_maxHeight; cout << "Smoker (Y/N)? "; cin >> user_smoker; cout << "What is the eyecolor (Blue, Green, Grey, Brown)? "; cin >> user_eyecolor; cout << endl << endl; //Variables to check against the conditions int countGender = 0; int partialMatch = 0; int fullMatch = 0; cout << endl << left << setw(1) << " Name" << fixed << right << setw(22) << "Age" << fixed << right << setw(12) << "Height" << fixed << right << setw(12) << "Smoker" << fixed << right << setw(15) << "Eye Color" << fixed << right << setw(22) << "Phone" << endl; cout << "-----------------------------------------------------------------------------------------------------------------" << endl; //Now read the file data. ifstream fin("matches.txt"); if (fin.is_open()) { while (!fin.eof()) { string firstname, lastname, eyecolor, phoneno; char gender, smoker; int age, height; fin >> firstname >> lastname >> gender >> age >> height >> smoker >> eyecolor >> phoneno; if (gender == user_gender) { countGender++; //Now check to see if the age and height are between the maximum and minum preferences. if ((age >= user_minAge && age <= user_maxAge) && (height >= user_minHeight && height <= user_maxHeight)) { //Then check to see if the smoking preference and eye color are also a match. if (user_smoker == smoker && user_eyecolor == eyecolor) { fullMatch++; cout << "* " << firstname << " " << lastname << setw(25) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor << setw(11) << phoneno << endl; } else if (eyecolor == user_eyecolor) { partialMatch++; cout << " " << firstname << " " << lastname << setw(24) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor<< setw(11) << phoneno << endl; } } } } cout << "-----------------------------------------------------------------------------" << endl; cout << "There were " << fullMatch << " matches and " << partialMatch << " partial matches out of " << countGender << " records." << endl; cout << "-----------------------------------------------------------------------------" << endl; fin.close(); } else { cout << "File did not open"; } return 0; }
matches.txt file data bellow.
```
Charlie Bradbury F 42 65 N Green 5558675309
Bobby Singer M 70 69 Y Brown 5558675309
Dean Winchester M 43 72 N Brown 5558675309
Sam Winchester M 39 75 N Brown 5558675309
Jody Mills F 51 65 N Brown 5558675309
Bela Talbot F 39 69 Y Blue 5558675309
James Novak M 46 71 Y Blue 5558675309
```
code.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
char user_gender, user_smoker;
string user_eyecolor;
int user_minAge, user_maxAge, user_minHeight, user_maxHeight;
cout << "What is the gender of your ideal match(M, F, N) ? ";
cin >> user_gender;
cout << "What is the minimum age? ";
cin >> user_minAge;
cout << "What is the maximum age? ";
cin >> user_maxAge;
cout << "What is the minimum height (in inches)? ";
cin >> user_minHeight;
cout << "What is the maximum height (in inches)? ";
cin >> user_maxHeight;
cout << "Smoker (Y/N)? ";
cin >> user_smoker;
cout << "What is the eyecolor (Blue, Green, Grey, Brown)? ";
cin >> user_eyecolor;
cout << endl << endl;
//Variables to check against the conditions
int countGender = 0;
int partialMatch = 0;
int fullMatch = 0;
cout << endl << left << setw(1) << " Name" << fixed << right << setw(22) << "Age" << fixed << right << setw(12) << "Height" << fixed << right << setw(12) << "Smoker" << fixed << right << setw(15) << "Eye Color" << fixed << right << setw(22) << "Phone" << endl;
cout << "-----------------------------------------------------------------------------------------------------------------" << endl;
//Now read the file data.
ifstream fin("matches.txt");
if (fin.is_open())
{
while (!fin.eof())
{
string firstname, lastname, eyecolor, phoneno;
char gender, smoker;
int age, height;
fin >> firstname >> lastname >> gender >> age >> height >> smoker >> eyecolor >> phoneno;
if (gender == user_gender)
{
countGender++;
//Now check to see if the age and height are between the maximum and minum preferences.
if ((age >= user_minAge && age <= user_maxAge) && (height >= user_minHeight && height <= user_maxHeight))
{
//Then check to see if the smoking preference and eye color are also a match.
if (user_smoker == smoker && user_eyecolor == eyecolor)
{
fullMatch++;
cout << "* " << firstname << " " << lastname << setw(25) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor << setw(11) << phoneno << endl;
}
else if (eyecolor == user_eyecolor)
{
partialMatch++;
cout << " " << firstname << " " << lastname << setw(24) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor<< setw(11) << phoneno << endl;
}
}
}
}
cout << "-----------------------------------------------------------------------------" << endl;
cout << "There were " << fullMatch << " matches and " << partialMatch << " partial matches out of " << countGender << " records." << endl;
cout << "-----------------------------------------------------------------------------" << endl;
fin.close();
}
else {
cout << "File did not open";
}
return 0;
}
![Matching Program
C++.
Create a datafile that contains the first name, last name,
gender, age, height, smoking preference, eye color and
phone number. Add a variety of records to the file. A sample
file looks like:
Charlie Bradbury
Bobby Singer
Dean Winchester
Sam Winchester
Jody Mills
Bela Talbot
James Novak
2 龙 42 38 51 39 45
42
70
43
39
51
96
46
SONSS65
69
72
75
matches.txt
69
71
YNNZ
Green 555-867-5309
Brown 555-867-5309
Brown
Brown
Brown
Blue
Blue
555-867-5309
555-867-5309
555-867-5309
555-867-5309
555-867-5309
Write a program that opens the file and reads the records
one by one. The program will skip any records where the
gender preference is not a match. Of those records that
match the gender preference, check to see if the age and
height are between the maximum and minum preferences.
Then check to see if the smoking preference and eye color
are also a match. If at least 3 of the remaining fields match,
consider the record a partial match, and print it in the
report. If all 4 of the remaining fields match, the record is a
perfect match and print it in the report with an asterisk next
to it. At the end of the program, close the file and report how
many total records there were of the specified gender, how
many were a partial match, and how many were a perfect
match. See the sample output below.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F14cda2c8-a0c2-4234-b84b-20d7f7c053e9%2Fd54792bf-b390-4ce9-a475-71fd976348e7%2Fnpw8v28_processed.jpeg&w=3840&q=75)
![Smoker (Y/N)? N
What is the eyecolor (Blue, Green, Grey, Brown)? Brown
Name
Bobby Singer
*Dean Winchester
*Sam Winchester
Age
70
43
39
Height Smoker Eye Color
69 72 75
Program ended with exit code:
A run of the program.
What is the gender of your ideal match (M,F,N)? F
What is the minimum age? 20
Y
N
N
Name
*Dean Winchester
Sam Winchester
There were 2 perfect matches and 1 partial matches out of 4 records.
What is the maximum age? 65
What is the
minimum height (in inches)? 60
What is the maximum height (in inches)? 70
Smoker (Y/N)? Y
What is the eyecolor (Blue, Green, Grey, Brown)? Blue
69
Program ended with exit code: 0
Brown
555-867-5309
Brown 555-867-5309
Brown 555-867-5309
Name
Age Height Smoker Eye Color
* Bela Talbot
39
555-867-5309
Blue
There were 1 perfect matches and partial matches out of 3 records.
Phone
Y
Another run of the program.
What is the gender of your ideal match (M,F,N)? M
What is the minimum age? 42
What is the maximum age? 45
What is the minimum height (in inches)? 69
What is the maximum height (in inches)? 90
Smoker (Y/N)? N
What is the eyecolor (Blue, Green, Grey, Brown)? Brown
===
Age Height Smoker Eye Color
43
72
Brown
555-867-5309
555-867-5309
39
75
Brown
There were 1 perfect matches and 1 partial matches out of 4 records.
Phone
Phone](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F14cda2c8-a0c2-4234-b84b-20d7f7c053e9%2Fd54792bf-b390-4ce9-a475-71fd976348e7%2F6o4kqgi_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
The given C++ program is as follows:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
char user_gender, user_smoker;
string user_eyecolor;
int user_minAge, user_maxAge, user_minHeight, user_maxHeight;
cout << "What is the gender of your ideal match(M, F, N) ? ";
cin >> user_gender;
cout << "What is the minimum age? ";
cin >> user_minAge;
cout << "What is the maximum age? ";
cin >> user_maxAge;
cout << "What is the minimum height (in inches)? ";
cin >> user_minHeight;
cout << "What is the maximum height (in inches)? ";
cin >> user_maxHeight;
cout << "Smoker (Y/N)? ";
cin >> user_smoker;
cout << "What is the eyecolor (Blue, Green, Grey, Brown)? ";
cin >> user_eyecolor;
cout << endl << endl;
//Variables to check against the conditions
int countGender = 0;
int partialMatch = 0;
int fullMatch = 0;
cout << endl << left << setw(1) << " Name" << fixed << right << setw(22) << "Age" << fixed << right << setw(12) << "Height" << fixed << right << setw(12) << "Smoker" << fixed << right << setw(15) << "Eye Color" << fixed << right << setw(22) << "Phone" << endl;
cout << "-----------------------------------------------------------------------------------------------------------------" << endl;
//Now read the file data.
ifstream fin("matches.txt");
if (fin.is_open())
{
while (!fin.eof())
{
string firstname, lastname, eyecolor, phoneno;
char gender, smoker;
int age, height;
fin >> firstname >> lastname >> gender >> age >> height >> smoker >> eyecolor >> phoneno;
if (gender == user_gender)
{
countGender++;
//Now check to see if the age and height are between the maximum and minum preferences.
if ((age >= user_minAge && age <= user_maxAge) && (height >= user_minHeight && height <= user_maxHeight))
{
//Then check to see if the smoking preference and eye color are also a match.
if (user_smoker == smoker && user_eyecolor == eyecolor)
{
fullMatch++;
cout << "* " << firstname << " " << lastname << setw(25) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor << setw(11) << phoneno << endl;
}
else if (eyecolor == user_eyecolor)
{
partialMatch++;
cout << " " << firstname << " " << lastname << setw(24) << age << setw(11) << height << setw(11) << smoker << setw(11) << eyecolor<< setw(11) << phoneno << endl;
}
}
}
}
cout << "-----------------------------------------------------------------------------" << endl;
cout << "There were " << fullMatch << " matches and " << partialMatch << " partial matches out of " << countGender << " records." << endl;
cout << "-----------------------------------------------------------------------------" << endl;
fin.close();
}
else {
cout << "File did not open";
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Still not working for other user inputs as shown in the sreenshot.
Kindly, would you please check for all the three sample output as well? Thank you.
![C: Microsoft Visual Studio Debug Console
What is the minimum age? 0
What is the maximum age? 100
What is the minimum height (in inches)? 45
What is the maximum height (in inches)? 90
Smoker (Y/N)? N
What is the eyecolor (Blue, Green, Grey, Brown)? Blue
Name
Dean Winchester
Sam Winchester
James Novak
■
46
DELL
Age
43
N
39
Height
71
72
O
75
●
Smoker
Y
There were 0 matches and 3 partial matches out of 4 records.
C:\_
N
N
Eye Color
Brown
Brown
C:\Users\demusu\Documents\aims\fall_2022\Computer_science (c++)\assignments\Matching.2\x64\Debug\Matching.2.exe (process
30156) exited with code 0.
Press any key to close this window
Blue
Phone
5558675309
5558675309
5558675309
40°F Sunny
(8)
›)
9:16 AM
10/17/2022](https://content.bartleby.com/qna-images/question/14cda2c8-a0c2-4234-b84b-20d7f7c053e9/76b2a969-759b-4e7e-854f-2c2d013ae1fc/b24xu8m_thumbnail.jpeg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)