Homework 1 Solution


Category: Tag:


Instructions: Create a subdirectory named “hw1” in your cs410 directory. Use that subdirectory for your files submission on this assignment. You will create the following two files in your hw1 directory:

  1. a single C++ compilable file containing a program written in C++ named “hw1.cpp”

  1. a “typescript” file demonstating program compilation, execution and testing. Use the commands below at the UNIX prompt to generate the typescript file:

script command to start a typescript.

ls -l to list files in your directory and write date/time cat hw1.cpp to print out solution file

g++ -o hw1 hw1.cpp to compile program

./hw1 to execute program with test input (provided on last page) exit command to end typescript file

Background: Hans Moleman needs a new pair of glasses. He’s going to try out a new optometrist in town, a Dr. Riviera. He has been involved in “cutting edge” (see pic) research (see other pic) which is why he has changed residences and started a new practice in optometry. But I digress. Dr. Nick has developed a new formula for determining the grinding thickness for lenseseses. Your program is going to do that

computation. Roughly speaking, the thickness of the lenses (both the same for right and left, since Dr. Nick believes in simplicity) is dependent on both left and right visual acuity, some cliometric1 constants, and the patient’s social security number. The formula is given below













thickness is an integer value in cm (centimeters), LVA is left visual acuity, a positive integer,

RVA is right visual acuity, a positive integer,

K1 is the index of refraction constant that Dr. Nick has discovered empirically. It’s value is the constant integer value 2,

K2 is the Nick Needs Money constant which ensures Dr. Nick a minimum income from each customer; currently it is 4.2, and

IAF is the insurance adjustment factor

IAF is the sum of the last two digits of the patient’s soc sec number. This factor is added into the thickness computation ONLY IF the patient has insurance. Why? Well, it screws up the prescription and then they have to come back to Dr. Nick for another diagnosis and more new lenses. Hence, Nick can bill the insurance companies for more money.

  1. We have no idea what this word means. It sounds cool and impressive, and it boosts our esteem

to use it; we come off as really smart now. Don’t look it up.

Specifications: Your program is to prompt the user for:

Left visual acuity (LVA) and right visual acuity (RVA), both entered as integers,

The last 4 digits of the patient’s social security number (this is entered as a single 4-digit integer), and

Whether the patient has insurance (1 for yes) or not (0 for no). The value be read into a boolean type variable.

Note: The thickness value computed should always be rounded down to the nearest integer value. You are not allowed to use conditional statements (if or if-else) in the program. Think carefully how to use the information you have input from the user, how it is stored, how boolean variables are represented. It is up to you how you want to name your variables and constants. Your program should be “user friendly” in that it should have an opening statement or greeting, user friendly and understandable prompts, and clear and concise outputs and sign-off. Here’s a good example of bad output:







Notice that there are NO prompts to speak of, and the output is completely unexplained. This is horrible output. Something like the following is much much better:

You are using the LENS-O-MATIC program


left visual acuity:


right visual acuity:






thickness of lens:

23 cm

Good luck with those glasses! And come back to see Dr. Nick !

When you submit: When you submit, you will have to enter inputs as a user of the program. Now, in order to make the output uniform for the grader and to keep them sane, ALL OF YOU will enter the same information. For this assignment, it is:

left visual acuity: 20

right visual acuity: 30

last 4 of soc sec: 4567

yes for ins coverage

If you have any questions about this assignment, be sure to ask your TAs or instructor.

error: Content is protected !!