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 <fstream>
#include <iostream>
using namespace std;
int main(){
fstream new_file;
fstream top_common_10_names;
fstream least_common_10;
new_file.open("babynames2012.txt",ios::in);
top_common_10_names.open("top_common_10 names.txt",ios::out);
least_common_10.open("least common_10 names.txt",ios::out);
if(new_file.is_open()){
string file;
while(getline(new_file, file)){
cout << file<< "\n";
top_common_10_names<<file<<endl;
}
}
}
Comments
Leave a comment