In: Computer Science
C Programming question part 4: The following program is an emergency hospital patient admitting process. This program needs a few changes to be sufficient for the hospital. Some patients who have been arriving at the Hospital have been providing social security numbers that are not valid. Create a function to scan all of the patient's social security numbers and detect if any of them are invalid. A Social Security Number (SSN) consists of nine digits, commonly written as three fields separated by hyphens: AAA-GG-SSSS. The first three-digit field is called the "area number". The central, two-digit field is called the "group number". The final, four-digit field is called the "serial number". Any SSN conforming to one of the following criteria is an invalid number: Any field all zeroes (no field of zeroes is ever assigned)., First three digits above 740
a. If you detect an invalid social security number, print the patient's name, their social security number, and then either "area number", "group number", or "serial number" to indicate where the problem with the social security number was detected.
#include
#include
#include
#include
using namespace std;
int main() {
char lname[][10]=
{"Johnson","Williams","Ling","Albin","Anderson","Baca","Birner","Dominguez","Aimino","Armstrong","Beard","Calderon","Carter","Chaname","
Chaney"}; char fname[][10] =
{"Fred","Betty","Hector","Ross","Jason","Elisa","Dalton","Javier","Ann","Addison","Cindy","Yamil","Thomas","Bryan","Kris"};
char middle[] =
{'N','L','X','L','O','L','M','B','S','T','J','C','P','D','Z'}; char
addr[][50] = {"2763 Filibuster Drive","701 Collage Avenue","1500
Raceway Lane","207 Daisy Avenue","1527 Lewis Road","25 Hunters
Lane","851 Applebe Court","1410 Waterford Blvd","2379 Runners
Way","46 Hawthorne Drive","1814 Constitution Ct","345 Cigar
Row","896 Pine Avenue","24 Blue Belt Drive","2589 College Court"};
cities[]={"Lakeland","Orlando","Tampa","Lakeland","Tampa","Lakeland","Orlando","Orlando","Lakeland","Lakeland","Orlando","Tampa","Tampa"
,"Lakeland","Orlando"};int zip[] =
{37643,31234,32785,32643,32785,32643,31234,31234,32643,32643,31234,32785,32785,32643,31234};
char gender[] =
{'M','F','M','M','M','F','M','M','F','M','F','M','M','M','F'}; char
dob[][11] =
{"05/27/1935","11/27/1971","10/17/2003","12/08/1990","11/25/1991","10/30/1992","09/22/1993","08/04/1994","07/11/1995","06/18/1996","05/2
8/1997","04/07/1998","03/12/1999","02/23/2000","01/15/2001"}; char
social[][12] =
{"164-55-0726","948-44-1038","193-74-0274","458-57-2867","093-00-1093","159-56-9731","695-21-2340","753-66-
6482","852-73-4196","648-81-1456","879-61-1829","123-87-0000","000-65-3197","741-85-9632","963-25-7418"};
vector fullName;
vector zombies_zip;
std::map dups;
char buffer[16];
char buffer2[16];
// for (int i = 0; i < 15; ++i)
// {
// //char buffer[16]; // large enough
// //char buffer2[16];
// strcpy(buffer, lName[i]);
// strcat(buffer, fName[i]);
// cout << lName[i] << " " << fName[i] << "
" << buffer << endl;
// cout << buffer << middleInitial[i] <<
endl;
//
// }
for(int i =0; i < 15; i++){
if(zombie[i] == 'Y'){
zombies_zip.push_back(zip[i]);
}
}
sort(zombies_zip.begin(), zombies_zip.end());
// for (int i=0; i // cout << zombies_zip[i] << "\n";
for(int i : zombies_zip)
++dups[i];
for(auto& dup : dups)
cout << dup.first << " has " << dup.second
<< " zombies\n";
//cout<<"Last Name: "<< last_name << ", "<<
"First Name: " << first_name << " ," << "Middle
name: " << middle_name << " ," << "Street
address: "<< street_address << " ," << "City: "
<< city << " ," << "State: " << state
<<" ," << "Zip: " << zip << endl;
//printf("Zombie: %c, ""Gender: %c, Date of Birth: %d-%d-%d, Insurance: %c, Social Security Number %s", gender, date_of_birth[0], date_of_birth[1], date_of_birth[2], insurance, social_security_number);
//cout<<"Zombie?: "<< zombie << ", "<< "Gender: " << gender << " ," << "Date of Birth: " << date_of_birth[0] << "/" << "/" << date_of_birth[1] << date_of_birth[2] << " ," << "Insurance?: "<< insurance << " ," << "Social Security: " << social_security_number<< endl;
cout << "Number of patients: " <<
sizeof(lName)/sizeof(lName[0]) << endl;
cout<<"Number of zombies: " << num_of_zombies <<
endl;
}
New format for patient record: Last Name, First Name, Middle Initial, Address, City, State, Zip, Sex, Date of Birth, SS #, Zombie?
Screenshot
//header files
#include<stdio.h>
#include<string >
//Function to check length of ssn
//If length not 11 return false
//Otherwise true
bool len(char *arr) {
char j=arr[0];
int cnt = 0;
while (j != '\0') {
cnt++;
j = arr[cnt];
}
if (cnt == 11) {
return true;
}
return false;
}
//Function to check area code
//Input area code
//Check is it 0 's and greater than 740
//Then return false
//Otherwise true
bool checkArea(char *arr) {
char j = arr[0];
int i = 1;
int cnt = 0;
int val = atoi(arr);
while (j != '\0') {
if (j == '0') {
cnt++;
}
j = arr[i];
i++;
}
if (cnt ==3) {
return false;
}
else if (val > 740) {
return false;
}
return true;
}
//Function to check group code
//Input group code
//Check is it 0 's
//Then return false
//Otherwise true
bool checkGroup(char *arr) {
char j = arr[0];
int i = 1;
int cnt = 0;
while (j != '\0') {
if (j == '0') {
cnt++;
}
j = arr[i];
i++;
}
if (cnt == 2) {
return false;
}
return true;
}
//Function to check serial code
//Input serial code
//Check is it 0 's
//Then return false
//Otherwise true
bool checkSerial(char *arr) {
char j = arr[0];
int i = 1;
int cnt = 0;
while (j != '\0') {
if (j == '0') {
cnt++;
}
j = arr[i];
i++;
}
if (cnt == 4) {
return false;
}
return true;
}
int main() {
//Initialize persons deatisl
char lname[][10] = {
"Johnson","Williams","Ling","Albin","Anderson","Baca","Birner","Dominguez","Aimino","Armstrong","Beard","Calderon","Carter","Chaname","
Chaney" };
char fname[][10] = {
"Fred","Betty","Hector","Ross","Jason","Elisa","Dalton","Javier","Ann","Addison","Cindy","Yamil","Thomas","Bryan","Kris"
};
char middle[] = {
'N','L','X','L','O','L','M','B','S','T','J','C','P','D','Z'
};
char addr[][50] = { "2763 Filibuster Drive","701
Collage Avenue","1500 Raceway Lane","207 Daisy Avenue","1527 Lewis
Road","25 Hunters Lane","851 Applebe Court","1410 Waterford
Blvd","2379 Runners Way","46 Hawthorne Drive","1814 Constitution
Ct","345 Cigar Row","896 Pine Avenue","24 Blue Belt Drive","2589
College Court" };
char cities[][20] = {
"Lakeland","Orlando","Tampa","Lakeland","Tampa","Lakeland","Orlando","Orlando","Lakeland","Lakeland","Orlando","Tampa","Tampa"
,"Lakeland","Orlando" };
int zip[] = {
37643,31234,32785,32643,32785,32643,31234,31234,32643,32643,31234,32785,32785,32643,31234
};
char gender[] = {
'M','F','M','M','M','F','M','M','F','M','F','M','M','M','F'
};
char dob[][11] = {
"05/27/1935","11/27/1971","10/17/2003","12/08/1990","11/25/1991","10/30/1992","09/22/1993","08/04/1994","07/11/1995","06/18/1996","05/28/1997","04/07/1998","03/12/1999","02/23/2000","01/15/2001"
};
char social[][12] = {
"164-55-0726","948-44-1038","193-74-0274","458-57-2867","093-00-1093","159-56-9731","695-21-2340","753-66-6482","852-73-4196","648-81-1456","879-61-1829","123-87-0000","000-65-3197","741-85-9632","963-25-7418"
};
char *buff;
char temp[5];
int k = 0,i,j;
//Loop through social array
for (i = 0; i < 15; i++) {
//Get social number
buff=social[i];
//Check length error
if(!len(buff)) {
printf("%s:%s
%s, %s: %s, %s: %s\n", "PatientName:", fname[i], lname[i], "SSN:",
social[i], "Reason:", "Not valid number of digits");
}
//Check hiphen error
else if (buff[3]!='-' ||
buff[6]!='-'){
printf("%s:%s %s, %s: %s, %s: %s\n",
"PatientName:", fname[i], lname[i], "SSN:", social[i], "Reason:",
"Not find proper hiphens");
}
//Otherwise
else {
//Check
area
for (j = 0; j
< 3; j++) {
temp[j] = buff[j];
}
temp[3] =
'\0';
if
(!checkArea(temp)) {
printf("%s:%s %s, %s: %s, %s: %s\n",
"PatientName:", fname[i], lname[i], "SSN:", social[i], "Reason:",
"Invalid area number");
}
//Check
group
k = 0;
for (j = 4; j
< 6; j++) {
temp[k] = buff[j];
k++;
}
temp[2] =
'\0';
if
(!checkGroup(temp)) {
printf("%s:%s %s, %s: %s, %s: %s\n",
"PatientName:", fname[i], lname[i], "SSN:", social[i], "Reason:",
"Invalid group number");
}
//Check
serial
k = 0;
for (j = 7; j
< 11; j++) {
temp[k] = buff[j];
k++;
}
temp[4] =
'\0';
if
(!checkSerial(temp)) {
printf("%s:%s %s, %s: %s, %s: %s\n",
"PatientName:", fname[i], lname[i], "SSN:", social[i], "Reason:",
"Invalid serial number");
}
}
}
}
-------------------------------------------
Output
PatientName::Betty Williams, SSN:: 948-44-1038, Reason:: Invalid
area number
PatientName::Jason Anderson, SSN:: 093-00-1093, Reason:: Invalid
group number
PatientName::Javier Dominguez, SSN:: 753-66-6482, Reason:: Invalid
area number
PatientName::Ann Aimino, SSN:: 852-73-4196, Reason:: Invalid area
number
PatientName::Cindy Beard, SSN:: 879-61-1829, Reason:: Invalid area
number
PatientName::Yamil Calderon, SSN:: 123-87-0000, Reason:: Invalid
serial number
PatientName::Thomas Carter, SSN:: 000-65-3197, Reason:: Invalid
area number
PatientName::Bryan Chaname, SSN:: 741-85-9632, Reason:: Invalid
area number
PatientName::Kris Chaney, SSN:: 963-25-7418, Reason:: Invalid area
number
-------------------------------------------------------------------------
Note:-
I assume that you are expecting output this way