Faqs About Assignment 1

Total Page:16

File Type:pdf, Size:1020Kb

Faqs About Assignment 1

CIS 501 Spring 2003

FAQs about Assignment 1

These questions pertain to the Preliminary Assignment – related to the Lookup Table.

1. No one taught us how to create a grade.dat file or its purpose

ANS: The only file you need to create right now is the file that is to be used to initialize your lookup table. You can create that file in ANY editor you want by entering information something like this:

98 A+ 92 A 90 A- 88 B+ 82 B etc, down to … 62 D 60 D- 0 F

Each pair of items is on a separate line, terminated with a carriage return. I think I mentioned in class how to create this file. I may try to get the grader to create the master file you have to work with for the larger assignment, but I will need to talk to her tomorrow. In the meanwhile, you do not need anything else but the file for the lookup table.

2. Personally, I cannot conceive why initialize_table and get_letter_grade is two different functions. Why can't you get the grades from just the one?

ANS: The purpose of the table is to provide you with an encapsulated, totally separate mechanism for taking a computed, weighted average, such as 76, and converting it to a letter grade (such as C). There are several ways to do this, but I suggest that you use the lookup table approach because we will make use of this later and because it is an important exercise (see list below).

Essentially, you need a function which, given a numeric average grade (such as 76) determines the CORRESPONDING letter grade. Your function is to do this by taking the average score for the student -- e.g., 76 and finding the score range in which that score fits (in this case, that range is 72-77). This range is always noted in the table by the lowest grade in the range (in this case, 72). You can always put the lowest and highest grades for each category of grade in the lookup table, as that may help to clarify things for you. If you use the highest and lowest grades, the information to be stored in the lookup table might look like this:

98 100 A+ 92 97 A 90 91 A- … 72 77 C 70 71 C- 68 69 D+ … 0 59 F but both numbers are not really needed for the lookup. Let's assume for now, however, that you want both numbers in your table. Then, if you call your lookup function with the average grade of 76, your\ function should stop its lookup when it finds the table entries

72 77 C

The function should then return the corresponding letter grade, in this case a C

NOW -- the answer to your question:

Before you can lookup the letter grade in the table, you have to have information IN the table. Thus you need to read the data (above) from your file and store it in your table BEFORE you can look anything up. This reading and storage might be done in a separate function, initialize, which might have a loop in it. The loop might look something like this:

// Priming read myinstr >> minscore >> maxscore >> lettergrade; while (!myinstr.eof()) { // Process data read table[i].mns=minscore; table[i].mxs=maxscore; table[i].lg=lettergrade; // Next read myinstr >> minscore >> maxscore >> lettergrade; }

This assumes you are storing both the min and max scores as well as the letter grade for each grade category. Note that we are assuming that there is a table of size 13 (I think -- if I can count) where each element is a struct of 3 fields --

FAQs re Assignment 1 Page 2 the fields named mns, mxs, and lg.

In your lookup function, somewhere you will have a comparison, something like this if (score >= table[i].mns && score <= table[i].mxs) return table[i].lg;

3. Why do we need to create a lookup file, can't we do the entire program in main()?

Of course you can -- but very soon your programs, including this one, will become very complicated and I think you will find that writing separate components and testing them separately will make a BIG difference in everything you do in this course.

This is a good time to get in the habit of doing this (my opinion, of course). Even with this project, if we take things one step at a time, we will

1. get a better idea of what you have learned already (and what you forgot) 2. have a much easier time understanding programs 3. have a much easier time testing programs 4. have a much easier integrating components into larger systems 5. learn how to decompose a complex problem into a simpler one 6. learn how to pass arguments back and forth between components 7. learn how to compile and execute a program having multiple components 8. be better prepared to handle large and more complex problems (using classes for example)

In a few weeks, we will see how to implement the data stores and operations on the lookup table as a C++ class. But for now, unless you know how to write classes, I want you to implement the lookup table as a MODULE, as discussed in class. Basically, you put the two lookup table operations (initialize_table and lookup_score), along with the two data stores (the table itself and its size) in a separate file (lookup.cpp). You then put the prototypes for the two functions in another file (lookup.h) which will be included in lookup.cpp and main (use #ifndef to do this). Your test driver program and the two lookup files all should be in your Assignment 1 directory.

4. How should we test this program. Use a few data items that test out each possibility of things that could occur. For example:

99 {fits in highest category} 100 {is an end point in a category} 76 {is in the middle of a middle category 43 59 0 -5 102 72

FAQs re Assignment 1 Page 3 You can decide why the last 6 items are important to try.

FAQs re Assignment 1 Page 4

Recommended publications