CSCI 159 Intro to Variables and I/O Lab

CSCI 159: Fall 2024 Lab 2

(Due Sept 24 (NO5) or 25 (NO6) at the beginning of lab)

    Part I

  1. While you are in your top directory, do this "copy" command, which copies a special makefile from your instructor's directory to yours:
    	cp ~gpruesse/make159 .       
    	
    (That command ends with a space and then a period, in case it is hard to see.) Do an "ls" to make sure it is copied over. If you are curious, cat it to the screen, or you can "view make159". The "view" command calls vi in read-only mode. You can exit "view" by hitting ZZ, just like in usual vi.
  2. Still in your top directory, you will type the following command onto the command line and hit return:
    	make -f make159 csci159/lab1 
    	
    You might as well create the directory for lab2 with this similar command, to be executed in your top directory:
    	make -f make159 csci159/lab2 
    	
    This makefile will create a new directory csci159 with a subdirectory called lab1 (and then lab2), and it will populate that directory with some files that your instructor has provided. cd into that lab1 directory. Do an "ls". For this first lab, lab1, you are provided with a README. Read the README. On your first quiz you will be asked about the contents of the README. You are also provided, in directory lab1, with files called makefile, sizes.cpp, and average3.cpp. cat sizes.cpp; you can see that it is empty of all but the #include; the main is empty.
  3. Now copy the files that are your solution to the lab1 exercise into this directory. This can be accomplished by executing the following commands while you are in your csci159/lab1 directory:
    	cp ../../csci159dev/lab1/sizes.cpp .
    	cp ../../csci159dev/lab1/average3.cpp .
    	
    (Those commands end with a space and a dot.) Check that the files are in your directory by doing an "ls". Check that the files have overwritten you old files using Don't copy over the old makefile, because you have a new one that is provided for you. You can cat it to the screen if you like.
  4. The new makefile is ready for you to use. Execute the following command:
    	make sizesx
    	
    Then do the same for average3x. These will check that your code compiles correctly.
  5. Now do the following:
    	make clean
    	
    This cleans up your directory of old executables. "ls" to see what remains.
  6. Your lab1 was done last week, so it is now ready to submit. (If not, speak to your instructor.) Execute the following command:
    	make submit
    	
    If successful, you will see a variety of updates. The git version control program is copying your updated directory contents to a location where the instructor can view and mark it. There is a deadline programmed into git, so if you try to submit after the deadline, it won't let you. Up until that deadline, you can submit and it will keep track of the most recent version, which is the one your instructor will look at.

    PART II


  7. For lab2, you will write a program that has an interface that asks the user for information about their cholesterol and their sex. The C++ file should be called "lab2.cpp" The interface of the program is like this:
    
    What is your Low Density Lipoprotein (LDL) cholesterol, in mg/dL?  185
    What is your High Density Lipoprotein cholesterol (HDL) in mg/dL?  45
    What is your sex (M/F)? F
    Your LDL is higher than the normal range (<=100 mg/dL is considered healthy).
    Your HDL is lower than the healthy range for females (>=50 mg/dL),
    Your LDL to HDL ratio is 4.1, which is above the healthy range (<=2.5 is considered healthy).  
    It is advisable to speak with a doctor if any of these values are outside the healthy range.
    
    Alternative reports from the program would be:
    Your LDL is in the healthy range (<=100 mg/dL is considered healthy).
    Your HDL is in the healthy range for females (>=50 mg/dL is considered healthy).
    Your LDL to HDL ratio is 2.2, which is in the healthy range (<=2.5 is considered healthy).

    For practice writing functions, you are to have three functions:
    • ldlTooHigh(int ldl) -- returns a bool value TRUE if the ldl level is too high, i.e., above 100.
    • hdlTooLow(int hdl, char sex) -- return bool value TRUE if the hdl level is too low: less than 40 for men and less than 50 for women.
    • LdlHdlRatio(int ldl, int hdl) -- return bool value TRUE if LDL/HDL exceeds 2.5.
    The command to "make" the executable (lab2x) is:
    make lab2x
    Do an "ls" to see that lab2x is in your directory. Test it.

  8. When ready to hand in, do "make clean" in your lab2 directory, which gets rid of your executables. Remember to comment your code, and put your name and the name of the program, and the name of the expected executable (lab2x) at the top.
    Then do "make submit" in your directory. Do this by the deadline, i.e., before the start of your next lab.


Useful Links: Gara Pruesse's Homepage
Computing Science Homepage
Vancouver Island University Homepage
X2Go