Setting up Class Depository Directory

We are going to set up a homework and lab depository where you will submit your homework and lab assignments according to week. The purpose for this is so that you will no longer have to email to submit your code. There will be two script files that you will run: one script builds your directories according to class and week number, and the other sets the permissions to the directories such that the faculty group and you will only have access to the directories. The process from now on is that each homework and lab assignment will declare what to name your fileName.cpp and in which directory to store the assignment. This will save you the burden from having to send me an email with the attatched assignment before midnight. As long as the correctly named assignment exist within the correct subdirectory of 2010_F18, I'll be able to run a script to extract and grade the file. Warning: if the file is not within the correct subdirectory or if the filename is incorrect/misspelled, the assignment will not be extracted. Details of what subdirectory and filenames will be included within the assignment write up.

What To Do

  1. You will execute two scripts:
    /home/fac/derrick/submissions/2010/build_dirs.sh
    This script will create a dir within your home dir called 2010_F18 which will include subdirectories wk1..wk15
    /home/fac/derrick/submissions/2010/set_permissions.sh
    Once completed, your bash logout will call the set_permissions.sh script to ensure permissions are set correctly.
  2. Logout all current sessions, then login again.
  3. At the end of the semester, you may run the following script to remove the logout hook
    /home/fac/derrick/submissions/2010/remove_logout_hook.sh


Lab 2

The purpose of this lab is to compare the difference of numerical data types (int, float, double) by performing arithmetic and assignment operations on declared variables.

What to complete for this lab

Declare two integer variables and two float variables. You will prompt for one integer value and input the value to an integer variable. Prompt for a real number value and input the value to a float variable. With use of cout and the two variables with inputted values, output the following:
(example: given inInt and inFloat)
cout << "Enter an integer value: ";
cin >> inInt;
cout << "Enter a floating point value: ";
cin >> inFloat;
cout << "int + float: " << inInt + inFloat << endl;
cout << "int - float: " << inInt - inFloat << endl;
cout << "int * float: " << inInt * inFloat << endl;
cout << "int / float: " << inInt / inFloat << endl;

Compile, run the program, and enter two values. Take notice the values that were shown. Was the arithmetic correct?

Open the source code and add more code. With the extra integer variable, you will now perform a assignment operation of the same arithmetic operations (+, -, *, /) using the original inputted integer and float values. Then output the value of the variable that was assigned the arithmetic expression.
(example: given resInt)
resInt = inInt + inFloat;
cout << "result int (int + float): " << resInt << endl;
resInt = inInt - inFloat;
cout << "result int (int - float): " << resInt << endl;
resInt = inInt * inFloat;
cout << "result int (int * float): " << resInt << endl;
resInt = inInt / inFloat;
cout << "result int (int / float): " << resInt << endl;

Compile, run the program, and enter two values. Take notice the values that were shown. Was the outputted value correct?

Open the source code and add more code. Do the same thing as above, but store the arithmetic expression into the extra float variable and output its value.
resFloat = inInt + inFloat;
cout << "result float (int + float): " << resFloat << endl;
resFloat = inInt - inFloat;
cout << "result float (int - float): " << resFloat << endl;
resFloat = inInt * inFloat;
cout << "result float (int * float): " << resFloat << endl;
resFloat = inInt / inFloat;
cout << "result float (int / float): " << resFloat << endl;

Compile, run the program, and enter two values. Take notice the values that were shown. Was the outputted value correct?

In a /* multi lined comment */ at the bottom of your source code, answer the following questions:
1) Explain why an (int / float) results to a float.
2) Explain why an (int / int) results to an int.
3) Explain why an (int / float) that is assigned into an integer results as an integer.
4) Explain why an (int / float) that is assigned into a float results as a float.
5) What would be the result of 1 / 2 ?
6) What would be the result of 1.0 / 2 ?
7) What would be the result of 1 / 2.0 ?
8) What would be the result of 1.0 / 2.0 ?

Once completed, show me your completed code with the questions answered and I will check you off for the lab. If you did not finish during lab session, by midnight have the completed source code in your depository directory and named: /2010_F18/wk2/lab2.cpp


Top