Assignment 04

Due: Friday, February 20, 2015 at noon 100 points

You will submit one .cpp file for this assignment in the usual way. Make sure you submit according to the cssubmit process.

Background: From the last assignment, you can see that nested if-elses can be cumbersome. You can alleviate some of that "pain" by using the switch-case statement. You will use the switch-case statement in this assignment. This program will be "menu driven", meaning that you will present menu(s) along the way for the user to choose input choices. The switch-case will then be used to handle the inputs/outputs.

Specifications: Your program is to present an initial menu that looks like this (with these specific choices):

In criminal forensics, one often uses special lights to illuminate the presence of certain substances (blood, fibres, saliva, hair, chicken-noodle soup, and green goo are among the most often identified) giving investigators necessary evidence to identify suspects and perpetrators. Well, Action Jackson has procured a new model of the "Crime-o-Light 400" to use in his work, but he is needing you to program a solution to some inherent problems with the device. The problem is that the device requires you to dial in the frequency of the light you need for the job to be done (it has a big knob on the front with big numbers that have big meanings that give Action big headaches). So your program is to input the stuff Action is looking for and output the wavelength of light to set the dial on the Crime-o-Light 400 to.

Wavelength for hair: The wavelength of light emission from the Crime-o-Light 400 that will make hair show up is given by

w = 400 nm (nanometers)

That's it. Four hundred nm. It's because 'hair' has 4 letters, and hundred is hundred. Very scientific!

Wavelength for Saliva and hair: The wavelength of light emission that will make hair and saliva come alive is

w = 100 * ( 1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/n) nm, n > 1

The value of n used will clearly determine the precision of the wavelength value. The larger the value of n, the better the precision. If this option is chosen, then your program must first prompt the user for a value of n that is positive and less than 8. Given this value of n, your code will calculate w and, of course, output it.

Wavelength for chicken noodle soup and saliva and hair: The wavelength of light emission that will make chicken noodle soup and hair and saliva pop out is

w = 100 * ( 1 + 1/2 + 1/4 + 1/8 + 1/16 + ... + 1/2n) nm, n > 0

Again, the value of n makes the precision and should first be prompted for.

Wavelength for green goo: The wavelength of light emission that will make green goo show up better is dependent on the 'grade' of the goo you are hoping to find. You see, green goo (GG) is sort of like motor oil - it comes in different grades/weights dependent on what part of the galaxy the little green alien is from.1 The grades are simply integers 0, 1, .... , 6. GG of grade 0 requires 200 nm, the base wavelength (bw). GG of grade 1 requires the bw plus 43; grade 2 GG needs 17 more than the wavelength for grade 1; grade 3 GG requires the wavelength for grade 2 plus 23; GG of grade 4 needs 77 more than that for grade 3; for grade 5, it is 55 more than for grade 4; and grade 6 GG uses wavelength 35 more than the one for grade 5. Thus, for this option, your code will also have to query the user for the grade of GG they are looking for (an integer from 0 to 6). Note: there is a really coooool way to code this with a switch statement. Can you figure it out? Note: the values in the foregoing paragraph are currently known (very scientific) values, but they could change in the future...when better scientific methods are developed....or better scientists are born. (This is a big hint that you should consider constants and a step-wise assignment of wavelength.)

In all the cases above, the value output should be an integer rounded down in every case. Also, you are not to use functions from the cmath library for this assignment; in particular, you are not to use the pow() function. You are to use loops to code that functionality. And, once again, after outputting the wavelength, the program should redisplay the main menu and the program should terminate only if the quit option is chosen.

When you submit: During the submission,

  1. Choose option 1

  2. Choose option 2 and enter n = -4 when prompted

  3. Choose option 2 and enter n = 4

  4. Choose option 3 and enter n = 7

  5. Choose option 4 and enter grade 3

  6. Quit

As usual, if you have any questions, be sure to ask.

1very very scientific.

Specs on Specs: You need to understand that the recommended wavelength for this machine is chosen in a very scientific manner. And the type of material sought is critical in determining that wavelength. The calculations for the wavelength were developed over the course of many years by many eminent scientific minds. Figure 1 to the right shows one of these great scientists performing an experiment that led to ... uhh, something surprising, I'm sure. So, you should not discard the following formulations as ridiculous, as they are reasonable and certainly scientific.

(Don't put that stuff in red in your menu; it's just to make you laugh.)

The program is to then output the recommended wavelength. Also, the program should present this initial menu until the user chooses to exit/quit.

Crime-o-Light 400 Don't put this red stuff in your menu

-----------------------

1. Hair (The barber did it!)

2. Saliva and hair (The barber did it ... by biting him to death!)

3. Chicken-noodle soup and saliva and hair (Oh, clearly the cook did it)

4. Green Goo (Some little green man did it)

5. exit