Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please modify this c program using the requirements below #include int main(void) { int i,j,len=0; char name[10][30],addr[10][60],city[10][60],province[10][2],postal[10][8],phone[10][13]; printf(Address Book Entry ); for(i=0;i <10;i++) { do

please modify this c program using the requirements below

#include

int main(void)

{

int i,j,len=0;

char name[10][30],addr[10][60],city[10][60],province[10][2],postal[10][8],phone[10][13];

printf("Address Book Entry ");

for(i=0;i<10;i++)

{

do

{

printf("Enter the name ");

scanf("%[^ ]%*c",&name[i]); //Name (maximum length 30 characters)

len=strlen(name[i]);

if(len>30)

printf("Maximum length should be 30 characters ");

} while(len>30);

do

{

printf("Enter the Address "); //Address (maximum length 60 characters)

scanf("%[^ ]%*c",&addr[i]);

len=strlen(addr[i]);

if(len>60)

printf("Maximum length should be 60 characters ");

}while(len>60);

do

{

printf("Enter the City "); //City (maximum length 60 characters)

scanf("%[^ ]%*c",&city[i]);

len=strlen(city[i]);

if(len>60)

printf("Maximum length should be 60 characters ");

}while(len>60);

do

{

printf("Enter the Province "); //Province (2 character long)

scanf("%[^ ]%*c",&province[i]);

len=strlen(province[i]);

if(len>2)

printf("Maximum length should be 2 characters ");

}while(len>2);

printf("Enter the Postal Code "); //postal code`

scanf("%[^ ]%*c",&postal[i]);

printf("Enter the Phone Number "); //Phone Number, including area code

scanf("%[^ ]%*c",&phone[i]);

}

printf(" ");

for(i=0;i<10;i++) //displaying the result

{

printf("%s ",name[i]);

printf("%s ",addr[i]);

printf("%s, %s, %s ",city[i],province[i],postal[i]);

printf("%s ",phone[i]);

printf(" ");

}

return 0;

}

General Assumptions - Only Canadian personal (non-business) addresses - All input can be done in upper or lower case - Assume the case as entered is correct for Name, Address and City o After successful validation, convert lower- to upper-case for Province and Postal Code - No foreign character support required for this version Validation Requirements for Name: - User may enter only a first and last name - Maximum length of 30 characters. - Multiple sequential non-alpha-numeric characters will be considered invalid input - Hyphenated names are acceptable - Legal characters range from a to z, A to Z and include , space (0x20), period and apostrophe - Could contain capitalization within the name Validation requirements for street address: - Will accept alpha-numeric characters in upper and lower case and dash, period, comma and quote should be acceptable - Could contain capitalization within the name - General format: number street name street type - Need to support other formats. Examples: R.R. 15 P.O. Box 20 - Need to support apartment number, such as: 50-123 Sesame Street 123 Sesame Street, Unit 50 123 Sesame Street, Unit #50 123 Sesame Street, Suite 50 123 Sesame Street, Suite #50 123 Sesame 123 Sesame Street, Apt. 50 - Street address no longer than 60 characters. - Invalid inputs: o Period char as the first character o Hyphen char as the first or last character o Space char as the first or last character o More than a single hyphen, space or period in a row o A string consisting of a single char, repeated more than 5 times is invalid (numbers are excepted, they can repeat). - May contain street type (ie. Street, Drive, West, South, Boulevard, etc.). The street type must come after the numbers and street name and can be fully spelled out or abbreviated. Validation requirements for City: - May be up to 60 characters. - Valid characters: o Letters o Commas o Hyphens o Periods o Spaces - Integers 0 to 9 Validation requirements for Province: - Canadian province - Abbreviations, two-character code, or full name acceptable - Must match list of acceptable inputs Province names - The province must be a valid Canada Post province abbreviation. It must be two uppercase alphabetical characters matching one of the following: " AB, BC, MB, NB, NL, NS - NT, NU, ON, PE, QC, SK, YT." Validation Requirements for Postal Code: - The system must validate that the postal code entered is in standard Canadian postal code format. That is, starting with a letter, the postal code alternates between an upper case letter and a digit from 0-9. The code must be six characters with a space between the third and fourth characters. E.G. "A1A 1A1". Invalid characters: 'D' 'F' 'I' 'O' 'Q' 'U' Characters that are valid except as the first character 'W' 'Z' - The user must enter 7 characters (including the space) or 6 characters (without the space) Validation Requirements for Phone number - Valid formats (where 'X' is a number and '-' is a delimiter): o "XXX-XXX-XXXX" o "(XXX) XXX-XXXX" o "X-XXX-XXX-XXXX" - The delimiter can be any of the following: o '-' o ' ' (ASCII 0x20 space) o '.' - When entering Phone number, the first 3 digits can only be the following: o 403, 587, 780, 825, 236, 250, 604, 778, 204, 431, 506, 709, 902, 782, 226, 249, 289, 343, 365, 416, 437, 519, 548, 613, 647, 705, 807, 905, 418, 438, 450, 514, 579, 581, 819, 873, 306, 639, 867 Instead of (XXX)-XXX-XXXX, the line for a valid phone input should be (XXX) XXX-XXXX.

For Names, be aware that you might have last names that are two words, like De Groot For Provinces, although only two letter codes are to be stored, it is possible and permissible for the user to enter the full name, two letter code or abbreviation. For example, Ontario, Ont and ON are all valid. (For the abbreviations, just choose some that are reasonable.) The address might will likely have a street type. Just assume there is one, and you do not have to check against a list of valid entries. When the program starts up, display the name Rabbit. Do not put any other identifying information (e.g. "Fred's Address Book) in the program. Once the user has done 10 entries or has chosen to end entry early, the program will then display the contents of the address book, three entries on a page. Each entry will be five lines in size. The lines must be in the following format: Rabbit 11 Cobblestone Lane Bedrock, ON, N2Y 3E8 519-555-1212 ++++++++++++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions