CMIS 102

Lab exercise #1

  1. Using a web browser, get this C++ source code file:
    http://sensei.ad.umuc.edu/dwills/cmis102/payroll.cpp
    1. Do File | Save As...
      Put it in student's documents which is in the E or F drive.
      change the Save as Type to text *.txt otherwise IE saves it as HTML and messes it up bad by adding tons of junk to the file!.
    2. Change the extension of the file to .cpp:
      Using Windows Explorer (Start|Run|explorer) go to E: drive, then student's documents. Right click the payroll_cpp.txt, choose Rename and change the name to payroll.cpp (A C++ source code files must end in .cpp)
    OR
    1. Highlight the source code text in the browser, copy it by Edit|Copy or Ctrl c, then start compiler and paste into it by Edit|Paste or Ctrl v.
  2. Double click the payroll.cpp file. DevC++ should start.
    Or start DevC++ and Open the payroll.cpp
    Or use VC++
  3. After the program loads into DevC++, add this line before the line that says return 0;
    system("pause");
  4. Compile and Run the program by clicking the "Compile" button (or hold down Ctrl key and hit F10 key, or pull down Execute menu and choose Compile and Run)
  5. The program is a payroll calculating program. You will enter an employee number, the hourly pay rate and the number of hours worked for an employee. You will do this for as many employees as you want or need. Entering a 0 for employee number marks the end of your inputting, as which point the program outputs the total payroll amount.
  6. The program creates an output file (in the same folder as payroll.cpp) called payfile.dat. Open it in DevC++ (it's not a C++ source program, but any text file can be opened and edited by DevC++). Notice that it's a string of numbers that you just entered. The text's example program has a small problem! There are no spaces between the numbers. You can't figure out the individual numbers.
  7. Change this statement in the program:
    	 payFile << empNum << payRate        // Put results into file
    		 << hours  << wages;
    

    Change it to:
    	 payFile << empNum << " " << payRate        // Put results into file
    		 << " " << hours  << " " << wages << endl;
    
  8. Recompile and execute and test your change (reopen the resulting output file).
  9. Introduce a syntax error in the program by deleting any semicolon. Compile and look at the error message. Fix that error.
  10. Make another syntax error by deleting the ) of the while statement. Compile, look, fix.
  11. We'll improve the program further by having it output the calculated wages to the monitor in addition to the file. Add this after the two lines you modified in the previous step to fix the format of the output file.
    	 cout << empNum << " " << payRate       
    	      << " " << hours  << " " << wages << endl;
    
OK. Now let's make our first program, which traditionally is the "hello world" program. Click the New source file button (or pull down File menu and select New). Notice that there's a bunch of code already in the new file. This is the standard boilerplate incantations that every program needs, saving you from having to type it for every new program. Right after the int main() { type cout << "Hello world" << endl; then save the file, compile and run it. Yes, that's the traditional first program.