Write a program to read the data from babynames2012.txt and
1-
Print out on another files “top_common_10 names.txt” the top ten popular boys and
girls names.
2-
Print out on another files “least common_10 names.txt” the least ten popular boys
and girls names
In the text file, there are more than 100 baby names but I cannot copy and paste it all because of the word limit. Here is 50 of them.
1 J1 Jacob Sophia
2 Mason Emma
3 Ethan Isabella
4 Noah Olivia
5 William Ava
6 Liam Emily
7 Jayden Abigail
8 Michael Mia
9 Alexander Madison
10 Aiden Elizabeth
11 Daniel Chloe
12 Matthew Ella
13 Elijah Avery
14 James Addison
15 Anthony Aubrey
16 Benjamin Lily
17 Joshua Natalie
18 Andrew Sofia
19 David Charlotte
20 Joseph Zoey
21 Logan Grace
22 Jackson Hannah
23 Christopher Amelia
24 Gabriel Harper
25 Samuel Lillian
26 Ryan Samantha
27 Lucas Evelyn
28 John Victoria
29 Nathan Brooklyn
30 Isaac Zoe
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
ifstream f1("babynames2012.txt");
ofstream f2("top_common_10 names.txt");
ofstream f3("least_common_10 names.txt");
string text;
while (getline (fr, text)) {
f2<<text;
f3<<text;
}
f1.close();
f2.close();
f3.close();
}
Comments
Leave a comment