in python please; Write a program that reads in babynames.txt and produces two f
ID: 675316 • Letter: I
Question
in python please;
Write a program that reads in babynames.txt and produces two files, boynames.txt and girlnames.txt, separating the data for the boys and girls. The columns in the file represent Rank, boy’s name, boy’s name count, girl’s name, girl’s name count. here is the babynames ;
1 Jacob 273,450 Emily 223,488
2 Michael 250,174 Madison 192,976
3 Joshua 231,602 Emma 181,055
4 Matthew 221,266 Olivia 155,848
5 Daniel 203,404 Hannah 155,525
6 Christopher 203,006 Abigail 150,746
7 Andrew 202,208 Isabella 149,310
8 Ethan 201,611 Samantha 134,148
9 Joseph 194,377 Elizabeth 133,166
10 William 194,079 Ashley 132,934
11 Anthony 191,592 Alexis 130,622
12 David 179,488 Sarah 124,149
13 Alexander 178,585 Sophia 119,088
14 Nicholas 177,428 Alyssa 114,347
15 Ryan 173,072 Grace 110,584
16 Tyler 165,378 Ava 104,428
17 James 162,812 Taylor 100,882
18 John 160,684 Brianna 99,647
19 Jonathan 144,565 Lauren 97,096
20 Noah 143,238 Chloe 96,348
21 Brandon 142,807 Natalie 94,981
22 Christian 142,181 Kayla 94,233
23 Dylan 139,960 Jessica 90,555
24 Samuel 138,217 Anna 90,032
25 Benjamin 137,050 Victoria 84,823
26 Nathan 134,658 Mia 83,395
27 Zachary 134,621 Hailey 81,862
28 Logan 133,877 Sydney 76,397
29 Justin 122,830 Jasmine 75,920
30 Gabriel 119,610 Julia 70,803
31 Jose 115,612 Morgan 70,703
32 Austin 112,622 Destiny 69,617
33 Kevin 110,956 Rachel 68,139
34 Elijah 110,135 Ella 67,387
35 Caleb 109,900 Kaitlyn 66,841
36 Robert 106,429 Megan 66,781
37 Thomas 101,967 Katherine 65,286
38 Jordan 100,978 Savannah 64,610
39 Cameron 95,759 Jennifer 63,451
40 Jack 95,447 Alexandra 61,191
41 Hunter 94,731 Allison 59,923
42 Jackson 94,380 Haley 56,967
43 Angel 94,195 Maria 56,870
44 Isaiah 92,504 Kaylee 56,336
45 Evan 92,065 Lily 56,108
46 Isaac 90,548 Makayla 54,888
47 Mason 90,398 Brooke 54,630
48 Luke 90,382 Mackenzie 54,493
49 Jason 88,417 Nicole 54,486
50 Gavin 88,359 Addison 51,324
51 Jayden 88,351 Stephanie 49,903
52 Aaron 86,787 Lillian 49,300
53 Connor 85,920 Andrea 49,119
54 Aiden 83,395 Zoe 48,679
55 Aidan 76,435 Faith 48,659
56 Kyle 76,082 Kimberly 48,438
57 Juan 75,764 Madeline 48,252
58 Charles 75,232 Alexa 48,067
59 Luis 74,244 Katelyn 47,776
60 Adam 70,889 Gabriella 47,296
61 Lucas 70,881 Gabrielle 46,964
62 Brian 69,679 Trinity 46,796
63 Eric 69,393 Amanda 46,495
64 Adrian 66,023 Kylie 46,386
65 Nathaniel 64,133 Mary 45,938
66 Sean 64,052 Paige 45,519
67 Alex 63,688 Riley 45,482
68 Carlos 63,094 Leah 45,303
69 Ian 61,871 Jenna 45,250
70 Bryan 61,867 Sara 43,944
71 Owen 61,821 Rebecca 43,533
72 Jesus 61,256 Michelle 43,472
73 Landon 61,037 Sofia 43,329
74 Julian 60,301 Vanessa 43,174
75 Chase 57,109 Jordan 43,126
76 Cole 56,805 Angelina 42,727
77 Diego 55,989 Caroline 41,803
78 Jeremiah 55,481 Avery 41,666
79 Steven 53,798 Audrey 41,476
80 Sebastian 53,794 Evelyn 40,686
81 Xavier 52,365 Maya 39,983
82 Timothy 52,306 Claire 38,985
83 Carter 52,279 Autumn 38,440
84 Wyatt 51,297 Jocelyn 38,348
85 Brayden 50,290 Ariana 37,937
86 Blake 50,043 Nevaeh 37,861
87 Hayden 49,985 Arianna 37,767
88 Devin 49,335 Jada 37,016
89 Cody 48,794 Bailey 36,830
90 Richard 48,514 Brooklyn 36,772
91 Seth 48,098 Aaliyah 36,299
92 Dominic 48,044 Amber 36,168
93 Jaden 46,191 Isabel 35,994
94 Antonio 46,154 Mariah 35,588
95 Miguel 46,034 Danielle 35,568
96 Liam 44,873 Melanie 35,186
97 Patrick 44,720 Sierra 34,467
98 Carson 44,602 Erin 33,342
99 Jesse 43,276 Molly 33,245
100 Tristan 43,232 Amelia 33,214
101 Alejandro 43,072 Isabelle 32,822
102 Henry 42,577 Madelyn 32,597
103 Victor 40,630 Melissa 32,567
104 Trevor 40,005 Jacqueline 32,093
105 Bryce 39,845 Marissa 32,029
106 Jake 39,794 Shelby 31,270
107 Riley 39,570 Angela 31,251
108 Colin 39,100 Leslie 31,026
109 Jared 37,975 Katie 30,355
110 Jeremy 37,427 Jade 30,239
111 Mark 37,177 Catherine 29,654
112 Caden 36,691 Diana 29,520
113 Garrett 36,204 Aubrey 29,492
114 Parker 35,696 Mya 28,743
115 Marcus 35,569 Amy 28,727
116 Vincent 35,235 Briana 28,684
117 Kaleb 34,707 Sophie 28,651
118 Kaden 34,569 Gabriela 28,506
119 Brady 34,290 Breanna 27,962
120 Colton 34,204 Gianna 27,825
121 Kenneth 34,031 Kennedy 27,539
122 Joel 33,604 Gracie 27,447
123 Oscar 33,511 Peyton 27,440
124 Josiah 33,129 Adriana 27,374
125 Jorge 32,993 Christina 27,085
126 Cooper 32,409 Courtney 26,943
127 Ashton 32,382 Daniela 26,615
128 Tanner 31,658 Lydia 26,246
129 Eduardo 31,374 Kathryn 26,235
130 Paul 30,840 Valeria 26,187
131 Edward 30,745 Layla 26,160
132 Ivan 30,634 Alexandria 25,883
133 Preston 30,290 Natalia 25,484
134 Maxwell 30,029 Angel 25,371
135 Alan 29,615 Laura 24,923
136 Levi 29,190 Charlotte 24,217
137 Stephen 28,829 Margaret 23,874
138 Grant 28,394 Cheyenne 23,864
139 Nicolas 28,238 Mikayla 23,708
140 Omar 28,136 Miranda 23,705
141 Dakota 28,106 Naomi 23,624
142 Alexis 28,013 Kelsey 23,370
143 George 27,974 Payton 23,356
144 Collin 27,795 Ana 23,144
145 Eli 27,763 Alicia 23,097
146 Spencer 27,416 Jillian 22,800
147 Gage 27,370 Daisy 22,773
148 Max 27,337 Mckenzie 22,524
149 Cristian 27,170 Ashlyn 22,445
150 Ricardo 27,162 Sabrina 22,301
151 Derek 26,987 Caitlin 22,280
152 Micah 26,956 Summer 22,133
153 Brody 26,668 Ruby 21,969
154 Francisco 26,479 Rylee 21,934
155 Nolan 26,352 Valerie 21,922
156 Ayden 26,246 Skylar 21,851
157 Dalton 26,151 Lindsey 21,624
158 Shane 26,088 Kelly 21,599
159 Peter 26,080 Genesis 21,404
160 Damian 25,983 Zoey 21,341
161 Jeffrey 25,885 Eva 21,307
162 Brendan 25,816 Sadie 21,260
163 Travis 25,692 Alexia 21,205
164 Fernando 25,128 Cassidy 21,153
165 Peyton 24,930 Kylee 21,134
166 Conner 24,892 Kendall 21,012
167 Andres 24,748 Jordyn 20,968
168 Javier 24,599 Kate 20,750
169 Giovanni 24,192 Jayla 20,707
170 Shawn 24,134 Karen 20,583
171 Braden 24,057 Tiffany 20,155
172 Jonah 23,666 Cassandra 20,109
173 Bradley 23,581 Juliana 20,039
174 Cesar 23,576 Reagan 19,959
175 Emmanuel 23,498 Caitlyn 19,761
176 Manuel 23,413 Giselle 19,708
177 Edgar 22,572 Serenity 19,553
178 Erik 22,391 Alondra 19,484
179 Mario 22,390 Lucy 19,352
180 Edwin 22,037 Bianca 18,893
181 Johnathan 21,867 Kiara 18,891
182 Devon 21,585 Crystal 18,876
183 Erick 21,411 Erica 18,843
184 Wesley 21,043 Angelica 18,656
185 Oliver 20,896 Hope 18,644
186 Trenton 20,862 Chelsea 18,000
187 Hector 20,853 Alana 17,900
188 Malachi 20,711 Liliana 17,588
189 Jalen 20,430 Camila 17,538
190 Raymond 20,328 Brittany 17,536
191 Gregory 20,028 Makenzie 17,455
192 Abraham 19,790 Lilly 17,217
193 Elias 19,584 Veronica 17,215
194 Leonardo 19,469 Abby 17,192
195 Sergio 19,424 Jazmin 17,183
196 Donovan 19,302 Adrianna 17,148
197 Colby 19,168 Delaney 17,070
198 Marco 19,102 Karina 17,067
199 Bryson 19,037 Ellie 16,999
200 Martin 18,722 Jasmin 16,890
Explanation / Answer
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
/*Write a program that reads in worked_example_1/babynames.txt and produces two files,
boynames.txt and girlnames.txt , separating the data for the boys and girls.*/
public class P7_11 {
public static void main(String[] args) throws FileNotFoundException {
HashSet<String> maleNames = new HashSet<String>();
HashSet<String> femaleNames = new HashSet<String>();
Scanner fileRead = new Scanner(new File("babynames.txt"));
while (fileRead.hasNext()) {
int rank = fileRead.nextInt();
String maleName = fileRead.next();
int matches = fileRead.nextInt();
double percent = fileRead.nextDouble();
String femaleName = fileRead.next();
matches = fileRead.nextInt();
percent = fileRead.nextDouble();
maleNames.add(maleName);
femaleNames.add(femaleName);
}
fileRead.close();
writeBabyNames("male_baby_names", maleNames);
writeBabyNames("female_baby_names", femaleNames);
}
public static void writeBabyNames(String filename, HashSet<String> names) throws FileNotFoundException {
PrintWriter fileWrite = new PrintWriter(new File(filename));
for (String name : names) {
fileWrite.println(name);
}
fileWrite.close();
}
}
Proram in C
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
//ifstream in_put;
std::string enter_name;
char data;
int index = 0, count = 0;
bool isFoundB = false;
bool isFoundG = false;
string boynames[1000][2];
string girlnames[1000][2];
count = 0;
ifstream fileb("boynames.txt");
while (count < 1000 && fileb.is_open()){
fileb >> boynames[count][0];
fileb >> boynames[count][1];
count++;
}
count = 0;
ifstream fileg("girlnames.txt");
while (count < 1000 && fileg.is_open()){
fileg >> girlnames[count][0];
fileg >> girlnames[count][1];
count++;
}
cout << "Enter the first name that you would like to find the popularity of. "
<< "Be sure to capitalize the first letter of the name. ";
cin >> enter_name;
count = 0;
while(count < 1000){
if (boynames[count][0] == enter_name){
cout << boynames[count][0] << " is ranked " << count << " among boys with " << boynames[count][1] << " namings" << endl;
isFoundB = true;
}
if (girlnames[count][0] == enter_name){
cout << girlnames[count][0] << " is ranked " << count << " among girls with " << girlnames[count][1] << " namings" << endl;
isFoundG = true;
}
count++;
}
if(isFoundB == false){
cout << enter_name << " is not ranked among the top 1000 boy names." << endl;
}
if(isFoundG == false){
cout << enter_name << " is not ranked among the top 1000 girl names." << endl;
}
system("Pause");
return 0;
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
/*Write a program that reads in worked_example_1/babynames.txt and produces two files,
boynames.txt and girlnames.txt , separating the data for the boys and girls.*/
public class P7_11 {
public static void main(String[] args) throws FileNotFoundException {
HashSet<String> maleNames = new HashSet<String>();
HashSet<String> femaleNames = new HashSet<String>();
Scanner fileRead = new Scanner(new File("babynames.txt"));
while (fileRead.hasNext()) {
int rank = fileRead.nextInt();
String maleName = fileRead.next();
int matches = fileRead.nextInt();
double percent = fileRead.nextDouble();
String femaleName = fileRead.next();
matches = fileRead.nextInt();
percent = fileRead.nextDouble();
maleNames.add(maleName);
femaleNames.add(femaleName);
}
fileRead.close();
writeBabyNames("male_baby_names", maleNames);
writeBabyNames("female_baby_names", femaleNames);
}
public static void writeBabyNames(String filename, HashSet<String> names) throws FileNotFoundException {
PrintWriter fileWrite = new PrintWriter(new File(filename));
for (String name : names) {
fileWrite.println(name);
}
fileWrite.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.