///////////////////////// read data from file
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;
// function for random unique ssn number
void randomCode(int code[][3],int count){
bool b=false;
long ssn=0;
while(true){
// get each digit for ssn
// first 3 digits
int fR=rand()%900+100;
// 2nd 2 digits
int mR=rand()%90+10;
// 3rd 4 digits
int lR=rand()%9000+1000;
ssn=fR*1000000+mR*10000+lR;
b=false;
for(int i=0;i<count;i++){
long
number=code[i][0]*1000000+code[i][1]*10000+code[i][2];
// if ssn number
exist ,
if(number==ssn){
b=true;
break;
}
}
// if unique ssn number
if(b==false){
break;
}
}
// split ssn number and insert into array
code[count][0]=(int)(ssn/1000000);
ssn=ssn%1000000;
code[count][1]=(int)(ssn/10000);
code[count][2]=(ssn%10000);
}
int main(){
// input file name
cout<<"Enter input file name : ";
string fName;
cin>>fName;
ifstream in;
in.open(fName.c_str());
// local variables
string firstName[50];
string lastName[50];
char sex[50];
int age[50],i=0;
int ssn[50][3];
int tm=0,tf=0;
if(!in.bad()){
// read all data from file
while(!in.eof()){
string
fname,lname;
char ch;
int age_;
in>>fname;
in>>lname;
in>>ch;
in>>age_;
// by switch 'M'
for male and for 'F' for female
switch(ch){
case 'M':{
tm++;
break;
}
case 'F':
{
tf++;
break;
}
}
// store in
corresponding array
firstName[i]=fname;
lastName[i]=lname;
sex[i]=ch;
age[i]=age_;
randomCode(ssn,i);
// to store in
next block
i++;
}
}
else{
cout<<"\nError in
File.";
}
cout<<"File data loded.\n";
///// output file
cout<<"Enter output file name : ";
string ofName;
cin>>ofName;
ofstream out;
out.open(ofName.c_str());
int k_=0,t_=0,a_=0,s_=0;
if(!out.bad()){
// print and write in file
both
for(int a=0;a<i;a++){
if(sex[a]=='M') {out<<"Mr. ";cout<<"Mr.
";}
if(sex[a]=='F') {out<<"Ms. ";cout<<"Ms.
";}
out<<"
";
out<<firstName[a];
out<<"
";
out<<lastName[a];
out<<"
";
cout<<"
";
cout<<firstName[a];
cout<<"
";
cout<<lastName[a];
cout<<"
";
// age
selection
if(age[a]>=0
&&
age[a]<=12){out<<"kid";cout<<"kid";k_++;}
if(age[a]>=13
&&
age[a]<=20){out<<"Teenager";cout<<"Teenager";t_++;}
if(age[a]>=21
&&
age[a]<=59){out<<"Adult";cout<<"Adult";a_++;}
if(age[a]>=60){out<<"Senior";cout<<"Senior";s_++;}
out<<"
";
out<<ssn[a][0];
out<<"-";
out<<ssn[a][1];
out<<"-";
out<<ssn[a][2];
out<<endl;
cout<<"
";
cout<<ssn[a][0];
cout<<"-";
cout<<ssn[a][1];
cout<<"-";
cout<<ssn[a][2];
cout<<endl;
}
out<<"Kids
"<<k_<<endl;
out<<"Teenagers
"<<t_<<endl;
out<<"Adults
"<<a_<<endl;
out<<"Seniors
"<<s_<<endl;
out<<"Male=
"<<((tm*100)/(tm+tf))<<"%"<<endl;
out<<"Female=
"<<((tf*100)/(tm+tf))<<"%";
cout<<"\nKids
"<<k_;
cout<<"\nTeenagers
"<<t_;
cout<<"\nAdults
"<<a_;
cout<<"\nSeniors
"<<s_;
cout<<"\nMale=
"<<((tm*100)/(tm+tf))<<"%";
cout<<"\nFemale=
"<<((tf*100)/(tm+tf))<<"%";
out.close();
}
else{
cout<<"\nError in
File.";
}
return(0);
}
Using C++ Write a program that gets 5 or more sets of information from user in...
CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and outputs the top 20 names, regardless of gender. The file has the following syntax: RANK# BoyName Boy#OfBirths Boy% GirlName Girl#OfBirths Girl% You should ignore the rank and percentages. Compare the number of births to rerank. Output should go to standard out. Program 2 Write a program that reads a text file containing floating-point numbers. Allow the user to specify the source file name on...
C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....