SlideShare a Scribd company logo
1 of 9
Download to read offline
The problem is called "Name Search" and it has to be in C#
6. Name Search
In the Chap07 folder of the Student Sample Programs, you will find the following
files:
• GirlNames.txt—This file contains a list of the 200 most popular names given to
girls born in the United States from 2000 through 2009.
• BoyNames.txt—This file contains a list of the 200 most popular names given to
boys born in the United States from 2000 through 2009.
Create an application that reads the contents of the two files into two separate
arrays or Lists. The user should be able to enter a boy’s name, a girl’s name, or
both, and the application should display
Solution
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace NameSearch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Intitialize the form.
}
private void btnSearch_Click(object sender, EventArgs e)
{//On clicking the search button..
string fileName;//fileName variable
string fileName2;//second filename variable
string searchName;//search name variable from user input
string searchName2;//second search name variable from user input
string nameType;//type of name(boy/girl)
try//try to..
{
if (txtBoysInput.Text != "" || txtGirlsInput.Text != "")
//If either of the textboxes are not empty..
{
if (txtBoysInput.Text != null && txtGirlsInput.Text == "")
{
//if the boys text box is not empty
fileName = "BoyNames.txt";
nameType = "boy's";
//set the file name, and the name type to reflect the masculine gender
searchName = txtBoysInput.Text;
//set the search name variable to the boy's contents.
parseSearchSingleFile(fileName, searchName, nameType);
//Parse the file into a list, and search it.
}
else if (txtGirlsInput.Text != null && txtBoysInput.Text == "")
{//if the girls textbox is not empty and the boys is empty..
fileName = "GirlNames.txt";
nameType = "girl's";
//set the file name, and the name type to reflect the feminine gender
searchName = txtGirlsInput.Text;
//set the search name to the user's input
parseSearchSingleFile(fileName, searchName, nameType);
//parse the file into a list, and search the list.
}
else if (txtGirlsInput.Text != null && txtBoysInput.Text != null)
{
fileName = "GirlNames.txt";
searchName = txtBoysInput.Text;
fileName2 = "BoyNames.txt";
searchName2 = txtGirlsInput.Text;
//set the file names, and collect the user input for the search names.
parseSearchBothFiles(fileName, fileName2, searchName, searchName2);
//parse the files, and search both of them.
}
}
else
{
MessageBox.Show("Enter a name, please.");
//Show the messagebox for empty textboxes. AKA prompt for user entry.
}
}
catch (Exception ex)
{
MessageBox.Show("Error Code: " + ex);
//if something goes wrong, show the error code, please.
}
}
private void parseSearchSingleFile(string fileName, string searchName, string nameType)
{
List names = new List();
//create a list array of names
using (var reader = new StreamReader(fileName))
{
while (reader.Peek() >= 0)
//if there's more than 0 lines left..
names.Add(reader.ReadLine());
//add the line to the list.
}
if (searchName != "")
{//if the searchname is not empty
if (names.Contains(searchName))
{//and the list contains the search name..
MessageBox.Show("The name " + searchName + "is among the most popular " +
nameType + " names!");
}//Tell us about it.
else
{//otherwise..
MessageBox.Show("The name was not among the most popular " + nameType +
" names.");
}//Tell us it isn't in the list.
}
else
{
MessageBox.Show("Enter a name, please.");
}//if it is empty, prompt for user entry.
}
private void parseSearchBothFiles(string fileName, string fileName2, string searchName,
string searchName2)
{
List girlsNames = new List();
//create a girls name list
using (var girlsReader = new StreamReader(fileName))
{
while (girlsReader.Peek() >= 0)//If there's more than 0 valid lines
girlsNames.Add(girlsReader.ReadLine());//add the line to the list
}
if (searchName != "" && searchName2 != "")
{//if both search names aren't empty..
List boysNames = new List();
//create a list of boy's names
using (var boysReader = new StreamReader(fileName2))
{
while (boysReader.Peek() >= 0)//while there are more than 0 lines left
boysNames.Add(boysReader.ReadLine());
}
if (girlsNames.Contains(searchName2) && boysNames.Contains(searchName))
{//if both names are on the list
MessageBox.Show("The name " + searchName2 + " was among the most popular
girl's names, and the name " + searchName + "was among the most popular boy's names!");
}//tell us about it
else if (boysNames.Contains(searchName))
{//if just the boy's name is on the list
MessageBox.Show("The name " + searchName + "was among the most popular
boy's names!");
}//tell us about it
else if (girlsNames.Contains(searchName2))
{//if just the girls name is on the list
MessageBox.Show("The name " + searchName2 + " was among the most popular
girl's names!");
}//tell us about it
else
{
MessageBox.Show("The name was not amongst the most popular names.");
}//If not, let us know as well.
}
else
{//if the search names were empty..
MessageBox.Show("Enter a name, please.");
}//Prompt for valid user input.
}
}
}
Form1.Designer.cs
namespace NameSearch
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.txtBoysInput = new System.Windows.Forms.TextBox();
this.txtGirlsInput = new System.Windows.Forms.TextBox();
this.lblBoysInput = new System.Windows.Forms.Label();
this.lblInputGirls = new System.Windows.Forms.Label();
this.btnSearch = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtBoysInput
//
this.txtBoysInput.Location = new System.Drawing.Point(105, 48);
this.txtBoysInput.Name = "txtBoysInput";
this.txtBoysInput.Size = new System.Drawing.Size(100, 20);
this.txtBoysInput.TabIndex = 0;
//
// txtGirlsInput
//
this.txtGirlsInput.Location = new System.Drawing.Point(105, 74);
this.txtGirlsInput.Name = "txtGirlsInput";
this.txtGirlsInput.Size = new System.Drawing.Size(100, 20);
this.txtGirlsInput.TabIndex = 1;
//
// lblBoysInput
//
this.lblBoysInput.AutoSize = true;
this.lblBoysInput.Location = new System.Drawing.Point(33, 51);
this.lblBoysInput.Name = "lblBoysInput";
this.lblBoysInput.Size = new System.Drawing.Size(66, 13);
this.lblBoysInput.TabIndex = 2;
this.lblBoysInput.Text = "Boy's Name:";
//
// lblInputGirls
//
this.lblInputGirls.AutoSize = true;
this.lblInputGirls.Location = new System.Drawing.Point(36, 77);
this.lblInputGirls.Name = "lblInputGirls";
this.lblInputGirls.Size = new System.Drawing.Size(63, 13);
this.lblInputGirls.TabIndex = 3;
this.lblInputGirls.Text = "Girl's Name:";
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(91, 138);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(75, 23);
this.btnSearch.TabIndex = 4;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(258, 187);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.lblInputGirls);
this.Controls.Add(this.lblBoysInput);
this.Controls.Add(this.txtGirlsInput);
this.Controls.Add(this.txtBoysInput);
this.Name = "Form1";
this.Text = "Name Search";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtBoysInput;
private System.Windows.Forms.TextBox txtGirlsInput;
private System.Windows.Forms.Label lblBoysInput;
private System.Windows.Forms.Label lblInputGirls;
private System.Windows.Forms.Button btnSearch;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NameSearch
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

More Related Content

Similar to The problem is called Name Search and it has to be in C# 6. .pdf

Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
mallik3000
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
cgraciela1
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 
javaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdfjavaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdf
birajdar2
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
Blake0FxCampbelld
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdf
aonesalem
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
anokhijew
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
aioils
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
anandatalapatra
 
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
faithxdunce63732
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
fedosys
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
lhkslkdh89009
 

Similar to The problem is called Name Search and it has to be in C# 6. .pdf (20)

Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
javaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdfjavaFix in the program belowhandle incomplete data for text fil.pdf
javaFix in the program belowhandle incomplete data for text fil.pdf
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Main issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdfMain issues with the following code-Im not sure if its reading the fil.pdf
Main issues with the following code-Im not sure if its reading the fil.pdf
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdfplease navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
please navigate to cs112 webpage and go to assignments -- Trees. Th.pdf
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Chapter 5 Class File
Chapter 5 Class FileChapter 5 Class File
Chapter 5 Class File
 
What's in a language? By Cheng Lou
What's in a language? By Cheng Lou What's in a language? By Cheng Lou
What's in a language? By Cheng Lou
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
 
5 Structure & File.pptx
5 Structure & File.pptx5 Structure & File.pptx
5 Structure & File.pptx
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
 
Files nts
Files ntsFiles nts
Files nts
 

More from karymadelaneyrenne19

Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdfPart A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
karymadelaneyrenne19
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
karymadelaneyrenne19
 
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdfHow is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
karymadelaneyrenne19
 
Day care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdfDay care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdf
karymadelaneyrenne19
 
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdfBelow is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
karymadelaneyrenne19
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 
Across the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdfAcross the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdf
karymadelaneyrenne19
 
A linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdfA linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdf
karymadelaneyrenne19
 
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
karymadelaneyrenne19
 
When you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdfWhen you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdf
karymadelaneyrenne19
 

More from karymadelaneyrenne19 (20)

Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdfPart A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
Is this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdfIs this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdf
 
in the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdfin the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdf
 
In HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdfIn HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdf
 
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdfHow is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
 
How do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdfHow do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdf
 
How do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdfHow do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdf
 
Describe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdfDescribe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdf
 
Day care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdfDay care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdf
 
Consider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdfConsider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdf
 
An administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdfAn administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdf
 
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdfBelow is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Across the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdfAcross the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdf
 
A linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdfA linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdf
 
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
 
With respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdfWith respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdf
 
Why do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdfWhy do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdf
 
When you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdfWhen you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdf
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

The problem is called Name Search and it has to be in C# 6. .pdf

  • 1. The problem is called "Name Search" and it has to be in C# 6. Name Search In the Chap07 folder of the Student Sample Programs, you will find the following files: • GirlNames.txt—This file contains a list of the 200 most popular names given to girls born in the United States from 2000 through 2009. • BoyNames.txt—This file contains a list of the 200 most popular names given to boys born in the United States from 2000 through 2009. Create an application that reads the contents of the two files into two separate arrays or Lists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application should display Solution Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace NameSearch { public partial class Form1 : Form { public Form1() { InitializeComponent(); //Intitialize the form. }
  • 2. private void btnSearch_Click(object sender, EventArgs e) {//On clicking the search button.. string fileName;//fileName variable string fileName2;//second filename variable string searchName;//search name variable from user input string searchName2;//second search name variable from user input string nameType;//type of name(boy/girl) try//try to.. { if (txtBoysInput.Text != "" || txtGirlsInput.Text != "") //If either of the textboxes are not empty.. { if (txtBoysInput.Text != null && txtGirlsInput.Text == "") { //if the boys text box is not empty fileName = "BoyNames.txt"; nameType = "boy's"; //set the file name, and the name type to reflect the masculine gender searchName = txtBoysInput.Text; //set the search name variable to the boy's contents. parseSearchSingleFile(fileName, searchName, nameType); //Parse the file into a list, and search it. } else if (txtGirlsInput.Text != null && txtBoysInput.Text == "") {//if the girls textbox is not empty and the boys is empty.. fileName = "GirlNames.txt"; nameType = "girl's"; //set the file name, and the name type to reflect the feminine gender searchName = txtGirlsInput.Text; //set the search name to the user's input parseSearchSingleFile(fileName, searchName, nameType); //parse the file into a list, and search the list. } else if (txtGirlsInput.Text != null && txtBoysInput.Text != null) { fileName = "GirlNames.txt";
  • 3. searchName = txtBoysInput.Text; fileName2 = "BoyNames.txt"; searchName2 = txtGirlsInput.Text; //set the file names, and collect the user input for the search names. parseSearchBothFiles(fileName, fileName2, searchName, searchName2); //parse the files, and search both of them. } } else { MessageBox.Show("Enter a name, please."); //Show the messagebox for empty textboxes. AKA prompt for user entry. } } catch (Exception ex) { MessageBox.Show("Error Code: " + ex); //if something goes wrong, show the error code, please. } } private void parseSearchSingleFile(string fileName, string searchName, string nameType) { List names = new List(); //create a list array of names using (var reader = new StreamReader(fileName)) { while (reader.Peek() >= 0) //if there's more than 0 lines left.. names.Add(reader.ReadLine()); //add the line to the list. } if (searchName != "") {//if the searchname is not empty if (names.Contains(searchName)) {//and the list contains the search name..
  • 4. MessageBox.Show("The name " + searchName + "is among the most popular " + nameType + " names!"); }//Tell us about it. else {//otherwise.. MessageBox.Show("The name was not among the most popular " + nameType + " names."); }//Tell us it isn't in the list. } else { MessageBox.Show("Enter a name, please."); }//if it is empty, prompt for user entry. } private void parseSearchBothFiles(string fileName, string fileName2, string searchName, string searchName2) { List girlsNames = new List(); //create a girls name list using (var girlsReader = new StreamReader(fileName)) { while (girlsReader.Peek() >= 0)//If there's more than 0 valid lines girlsNames.Add(girlsReader.ReadLine());//add the line to the list } if (searchName != "" && searchName2 != "") {//if both search names aren't empty.. List boysNames = new List(); //create a list of boy's names using (var boysReader = new StreamReader(fileName2)) { while (boysReader.Peek() >= 0)//while there are more than 0 lines left boysNames.Add(boysReader.ReadLine()); } if (girlsNames.Contains(searchName2) && boysNames.Contains(searchName)) {//if both names are on the list MessageBox.Show("The name " + searchName2 + " was among the most popular
  • 5. girl's names, and the name " + searchName + "was among the most popular boy's names!"); }//tell us about it else if (boysNames.Contains(searchName)) {//if just the boy's name is on the list MessageBox.Show("The name " + searchName + "was among the most popular boy's names!"); }//tell us about it else if (girlsNames.Contains(searchName2)) {//if just the girls name is on the list MessageBox.Show("The name " + searchName2 + " was among the most popular girl's names!"); }//tell us about it else { MessageBox.Show("The name was not amongst the most popular names."); }//If not, let us know as well. } else {//if the search names were empty.. MessageBox.Show("Enter a name, please."); }//Prompt for valid user input. } } } Form1.Designer.cs namespace NameSearch { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used.
  • 6. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.txtBoysInput = new System.Windows.Forms.TextBox(); this.txtGirlsInput = new System.Windows.Forms.TextBox(); this.lblBoysInput = new System.Windows.Forms.Label(); this.lblInputGirls = new System.Windows.Forms.Label(); this.btnSearch = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtBoysInput // this.txtBoysInput.Location = new System.Drawing.Point(105, 48); this.txtBoysInput.Name = "txtBoysInput"; this.txtBoysInput.Size = new System.Drawing.Size(100, 20); this.txtBoysInput.TabIndex = 0; // // txtGirlsInput // this.txtGirlsInput.Location = new System.Drawing.Point(105, 74); this.txtGirlsInput.Name = "txtGirlsInput"; this.txtGirlsInput.Size = new System.Drawing.Size(100, 20);
  • 7. this.txtGirlsInput.TabIndex = 1; // // lblBoysInput // this.lblBoysInput.AutoSize = true; this.lblBoysInput.Location = new System.Drawing.Point(33, 51); this.lblBoysInput.Name = "lblBoysInput"; this.lblBoysInput.Size = new System.Drawing.Size(66, 13); this.lblBoysInput.TabIndex = 2; this.lblBoysInput.Text = "Boy's Name:"; // // lblInputGirls // this.lblInputGirls.AutoSize = true; this.lblInputGirls.Location = new System.Drawing.Point(36, 77); this.lblInputGirls.Name = "lblInputGirls"; this.lblInputGirls.Size = new System.Drawing.Size(63, 13); this.lblInputGirls.TabIndex = 3; this.lblInputGirls.Text = "Girl's Name:"; // // btnSearch // this.btnSearch.Location = new System.Drawing.Point(91, 138); this.btnSearch.Name = "btnSearch"; this.btnSearch.Size = new System.Drawing.Size(75, 23); this.btnSearch.TabIndex = 4; this.btnSearch.Text = "Search"; this.btnSearch.UseVisualStyleBackColor = true; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(258, 187); this.Controls.Add(this.btnSearch);
  • 8. this.Controls.Add(this.lblInputGirls); this.Controls.Add(this.lblBoysInput); this.Controls.Add(this.txtGirlsInput); this.Controls.Add(this.txtBoysInput); this.Name = "Form1"; this.Text = "Name Search"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox txtBoysInput; private System.Windows.Forms.TextBox txtGirlsInput; private System.Windows.Forms.Label lblBoysInput; private System.Windows.Forms.Label lblInputGirls; private System.Windows.Forms.Button btnSearch; } } Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace NameSearch { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);