CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Filtering Gem Data

Background

Gemstones are attractive forms of rock crystal, commonly used for decoration and in jewelry. Gemstones also have interesting mineral properties. Gemstones may be classified in a variety of ways, including chemical composition, crystal structure, color, specific gravity, refractive index, and hardness:

  1. Chemical Composition: While some gemstones are primarily composed of atoms of one element (e.g., diamonds are mostly carbon, with coloring coming from traces of other elements), other gemstones are made up of atoms of several atoms (e.g., mica molecules include oxygen, hydrogen, silicon, aluminum, iron, and/or many others). On-line sources of information include general references (e.g., Common Mineral Groups) and references to specific minerals (e.g., micas).
  2. Color may be classified informally (e.g., red, yellow, etc.) or more formally by viewing thin slices of mineral crystals through the microscope, using polarized light (see, for example, Minerals under the Microscope).
  3. Specific Gravity is a measure of the density of a mineral. More precisely, specific gravity is the ratio of the weight of the mineral in air to its weight in an equal volume of water. More details are available from various on-line sources (see, for example, the Mineral and Gemstone Kingdom's glossary for specific gravity.
  4. Refractive Index provides a measure of how much light bends within a crystal. The higher the refractive index, the more bending and the more brilliant a crystal is likely to appear. For more information, see various on-line sources, such as Refractive Index.
  5. Crystal Structure: Crystals typically have one of several standard shapes or structures, including cubic, tetragonal, orthorhombic, hexagonal, monoclinic, and triclinic. While the details of such structures are beyond the scope of this problem, the World Wide Web contains many useful references, including crystal forms (at the macro-level) and the (atomic-level) representation of structures prepared as part of lecture series by S. J. Heyes.
  6. Hardness often is measured on the (nonlinear) Mohs Scale, which associates a hardness number to each mineral, from 1 (softest) to 10 (hardest):
    1. Talc
    2. Gypsum
    3. Calcite
    4. Fluorite
    5. Apatite
    6. Orthoclase
    7. Quartz
    8. Topaz
    9. Corundum
    10. Diamond
    As a comparison, a fingernail has hardness 2.5, glass has hardness 5.5, and a steel file has hardness 6.5. Minerals of the same hardness should not scratch each other, but a mineral of one hardness will scratch minerals with a lower hardness number.

Programming

The file gems.txt contains information on several gemstones, including color, hardness, specific gravity, and refractive index. Within the file, each line contains information about a specific gemstone.

Here are a couple of sample lines, and a character 'ruler' to show how wide the fields are:

          11111111112222222222333333333344444444445555555555666666666677777
012345678901234567890123456789012345678901234567890123456789012345678901234

                Zircon        RED           7.5         4.50         1.95
                 Topaz     YELLOW             8         3.53         1.62

To clarify, the names of the gemstones come first in a line and are right-justified in a column. The colors come next, followed by hardness (on a scale 1 to 10), then specific gravity, and finally refractive index (generally between 1.3 and 2.5).

Write a program print-by-color.c that will let you select the gemstones of a certain color and print the information about those gemstones, where the resulting table is in alphabetical order by gemstone name and where the columns are labeled.

For example, if this program is invoked with the color GREY the procedure should return a table, such as the following:

                                                      Specific   Refractive
              Gemstone       Color       Hardness      Gravity      Index

             Alabaster       GREY             2         2.32         1.53
              Bakelite       GREY           2.5         1.28         1.65
               Calcite       GREY             3          2.7         2.71
                Casein       GREY           2.5         1.33         1.55
              Celluoid       GREY             2         1.35         1.50
            Chalcedony       GREY             7         2.62         1.53
              Corundum       GREY             9         3.99         3.99
               Diamond       GREY            10         3.52         3.52
              Hematite       GREY             6         5.10         5.05
                 Ivory       GREY           2.5         1.80         1.54
               Jadeite       GREY             7         3.34         3.33
           Labradorite       GREY             6          2.7         2.70
                Marble       GREY             3         2.71         1.50
            Meerschaum       GREY             2         1.50         1.53
              Nephrite       GREY           3.5         3.00         2.96
                  Opal       GREY             6         2.10         2.10
                Quartz       GREY             7         2.65         1.55
                Quartz       GREY             7         3.33         2.65
                  Talc       GREY             1         2.70         2.75
Another possible format might be:
                                       Specific   Refractive
Gemstone Name       Color    Hardness   Gravity      Index

Alabaster            GREY       2         2.32        1.53
Bakelite             GREY       2.5       1.28        1.65
Calcite              GREY       3         2.70        2.71
Casein               GREY       2.5       1.33        1.55
Celluoid             GREY       2         1.35        1.50
Chalcedony           GREY       7         2.62        1.53
Corundum             GREY       9         3.99        3.99
Diamond              GREY      10         3.52        3.52
Hematite             GREY       6         5.10        5.05
Ivory                GREY       2.5       1.80        1.54
Jadeite              GREY       7         3.34        3.33
Labradorite          GREY       6         2.70        2.70
Marble               GREY       3         2.71        1.50
Meerschaum           GREY       2         1.50        1.53
Nephrite             GREY       3.5       3.00        2.96
Opal                 GREY       6         2.10        2.10
Quartz               GREY       7         2.65        1.55
Quartz               GREY       7         3.33        2.65
Talc                 GREY       1         2.70        2.75

As shown in each example, the gemstone names and properties must appear in labeled columns. Gemstone names may be either left-justified or right-justified.

Note that some gemstones, such as Quartz above, appear several times in the table, since variations of a gemstone may have different properties.