Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

c++ homework arrays, dont know what to do?

he said (proffesor) we use everything from the book on this program, i dont even know where to start, i dont know where to make the 2 functions or the struct array?

Lab Assignment Six

This problem is not from the book. This is the last homework for my Fall 2008 Computer Science 575 class. This is intended to be a comprehensive assignment, requiring use of all techniques used in the course. You should plan on using for, while, and do-while loops; if, else, and switch statements; at least two functions; an array of structs; and file I/O.


Input will be a file and user requests. The file contains Zip code ranges and state names. The four data elements in each record are (a) the full state name, (b) the state postal code (e.g. 'CA' for California), (c) the low Zip code for a state, and (d) the high Zip code for a state. The data file is available at this link. You should name it ZipRange.txt and store it in the C:\Temp directory.

The user input will comprise requests and transaction data. The requests will be a transaction processing code (the values 1, 2, and 3) and related data (either Zip codes or state codes).

You may assume that there are 70 or fewer records in the input Zip code file. Sample Records From the Zip code file:

Alaska AK 99501 99950

Alabama AL 35004 36925

Arkansas AR 71601 72959

Arizona AZ 85001 86556

California CA 90001 96162

Colorado CO 80001 81658


Processing comprises the following steps:

1. Read in the ZipRange.txt file. Store each entry in an array of structs. Check to be sure that the number of records in the file does not exceed the array size. Write out error message 1 listed below if the number of records exceeds the array size.

2. When all records have been read in, validate the file data. Verify that no Zip code ranges overlap any other state's Zip code ranges. If they do, write out error message 2 listed below and do not do any further processing. Identify the highest and lowest Zip codes in the table.

3. Write out the number of records read, and the low and high Zip codes, using message 3 listed below.

4. Display message 4 listed below and read in the user's processing code.

5. Validate that the processing code is 1, 2, or 3. If not, display error message 5 listed below and continue with step 4 until a valid code is entered.

6. If the processing code is 1, issue user prompt message 10 and read in a two-character state code. Search the table for that state code and display message 6. If the state code is not found, display error message 7.

7. If the processing code is 2, issue user prompt message 11 and read in a Zip code. Search the table for an entry whose low Zip code range is not greater than the user-supplied Zip code, and whose high Zip code is not less than the user-supplied Zip code. Display message 8 when found. If no entry is found, display error message 9.

8. If the processing code is 3, end execution. If not, continue with step 4.


Use the following messages for output:

• Error message 1:

Too many Zip code range records - maximum is nn

Replace nn with the maximum limit the program will allow. (You define this.)

• Error message 2:

Zip code range aaaaa through bbbbb in state cc overlaps Zip code range xxxxx through yyyyy in state zz

Replace aaaaa and bbbbb with the low and high Zip codes in the overlapping state, and replace cc with the overlapping state code. Replace xxxxx and yyyyy with the low and high Zip codes in overlapped state, and replace zz with the overlapped state code.

• Message 3:

nnnnn Zip Code records read, ranging from xxxxx through yyyyy

Replace nnnnn with the number of Zip code records from the ZipRange.txt file, and replace xxxxx and yyyyy with the low and high Zip codes read in from the file.

• Message 4:

Enter 1 to get the Zip code range for a state, 2 to get the state name for a Zip code, or 3 to end

• Message 5:

Response must be 1, 2, or 3 - please try again

• Message 6:

Zip code range for xx is yyyyy through zzzzz

Replace xx with the state name, and replace yyyyy and zzzzz with the low and high Zip codes respectively.

• Error message 7:

State code xx was not found in the table

Replace xx with the two-character state code entered by the user.

• Message 8:

Zip code xxxxx is in yy

Replace xxxxx with the Zip code entered by the user, and replace yy with the state name.

• Error message 9:

Zip code xxxxx was not found in any state

Replace xxxxx with the Zip code entered by the user.

• User Prompt message 10

Enter a two-character state code.

• >User Prompt message 11

Enter a Zip code

All output numbers are integers. Zip codes should be displayed as five-digit numbers with leading zeroes if needed.

Sample Output

User input is in this color.

63 Zip Code records read, ranging from 00501 through 99999

Enter 1 to get the Zip code range for a state, 2 to get the state name for a Zip code, or 3 to end



2 Answers

  • Anonymous
    1 decade ago
    Favorite Answer

    This question builds on everything that you have been taught in the course. If you don't understand it then go back into your course notes and look at the exercises that you were given.

    The general layout of a C program goes in this sequence:

    1) Library includes

    2) Constants and typedefs

    3) Structures and classes

    4) Variables (this includes arrays)

    5) Functions

    6) Main function

    To make the struct, just Google struct and see how you can adapt the examples to this problem

    • Login to reply the answers
  • 4 years ago

    Solution for 1 void main() { int a; printf("Enter any no."); scanf("%d",&a); if(a==0) printf("\n The no is zero"); else if (a<0) printf("\n The no. is negative"); else printf("\n The no. is positive"); } Solution for 3 void main() { int a; printf("Enter a no."); scanf("%d",&a); if(a<=9) { printf("%d",a); } else printf("%c",char(a)); }

    • Login to reply the answers
Still have questions? Get your answers by asking now.