1.124J Foundations of Software Engineering

Problem Set 0

Due Date: Tuesday 9/12/00

Reference Readings: Documents provided in the class and WWW links given here


General Instructions and Turn in Requirements

This problem set will be checked but not graded. Its purpose is to expose you to the compiling and debugging process, the use of makefiles and header files, the electronic turnin of your homework solutions and the use of CVS.
Although for this problem set you don't have to submit any hardcopies, for all following problem sets you have to:
The provided source code files are in the source repository directory /mit/1.124/src from where you can check them out to your directory using CVS and make the necessary additions and/or modifications.
To use CVS to check out the problem sets from the 1.124 you should set the environment variable CVSROOT as below: (you can also put it in your .environment dotfile to avoid repetition)
% setenv CVSROOT /afs/athena.mit.edu/course/1/1.124/src
then you can use either of the commands:
% cvs co Problems/PS0
% cvs co OOP_PS0         (alias defined in 1.124/src/CVSROOT/modules)
A simple makefile is provided for you, called makePS0a, which you may use to compile and link your code (e.g. % gmake -f makePS0a <program_name>). There is also a more advanced makefile named makePS0b which you can use.

Problem 1: Simple Compiling (direct)

By doing this simple problem you will make sure that you have access to the gnu compiler and you are able to compile a program, either with or without a makefile.
You need to add the gnu locker using the following command to be able to use the gnu compiler:
% add -f gnu
You can customize your account at start-up, using a dotfile, so that it will automatically add the gnu locker. In the file .environment add the following line:
add -f gnu
(The add command attaches the specified locker to your workstation and adds it to your path.)
Compile (directly) the simple program provided in the file ps0_1.C file using the command:
% g++ ps0_1.C -o ps0_1
Then, run the generated executable file ps0_1 to make sure that it runs without any problem.

ps0_1.C

#include <iostream.h> // Problem Set#0 - Problem#1
#include <stdlib.h>
int main ( )
{
cout << "\n Welcome to 1.124 \n" << endl ;
return EXIT_SUCCESS ;
}

Problem 2: Using a header file

You can copy from the directory /mit/1.124/Problems/PS0 the files ps0_2.C and ps0_2.h to your directory, to compile and run another very simple program which uses a header file for the prototype of a function. The function definition is in the same file (ps0_2.C) with main(), while its declaration (prototype) is in the header file (ps0_2.h). You can compile directly the program using the command:
% g++ ps0_2.C -o ps0_2

and then run the executable ps0_2.

Please pay attention to the conditional compilation in ps0_2.h file and the use of ps0_2.h in the dependency line in the makefile.

ps0_2.C

#include <iostream.h> // Problem Set#0 - Problem#2
#include "ps0_2.h"
#include <stdlib.h>
int main ( )
{
 double x , y;
 cout << " \n Give x = " ;
 cin >> x ;
 cout << " \n Give y = " ;
 cin >> y ;
 cout << endl << " x + y = "
         << x << " + " << y << " = "
         << a_plus_b(x,y) << endl << endl;
 return EXIT_SUCCESS ;
}
double a_plus_b(double a , double b)
{
return (a+b) ;
}

ps0_2.h

// Problem Set#0 - Problem#2 : Header file ps0_2.h
#ifndef PS0_2_H
#define PS0_2_H
double a_plus_b(double a , double b) ;
#endif

Problem 3: Compiling using makefiles

You can use makefiles to help you automate the compilation and linking of your programs. Two makefiles, a simple one (makePS0a) and a more advanced one (makePS0b) are provided for you in the directory /mit/1.124/Problems/PS0 from where you can copy them to your directory. Using those makefiles recompile both ps0_1.C and ps0_2.C using a command like the following:
% gmake -f <makefile_name> <target_filename>
Executing this command creates the target_filename according to the instructions provided in the makefile_name file, ( e.g.: gmake -f makePS0a ps0_1 ).
You can find more information related to developing makefiles at the following URL
http://www.lns.cornell.edu/public/COMP/info/make/make_toc.html

Problem 4: Using a debugger

  • Debugging with GDB

  •  

     

    You may also use a debugger to check your code. The gdb debugger allows you to see what is going on in a program when it executes or when it crashes. In order to use the gdb debugger you must first compile and link your code with the flag -g. e.g.:

    % g++ -g filename.C -o filename
    Then, use gdb to run your executable
    % gdb filename
    You can find more information about GDB at the following URL:
  • Debugging with DDD

  •  

     

        Data Display Debugger (DDD), which is available on athena, can be used to step through the program, line by line and examine the program variables. DDD uses the gdb (GNU Debugger) for its operations.

    DDD is available in the outland lockerbut someone also needs g++ compiler from the gnu locker to compile her/his program. Therefore, someone needs to type:

    athena% add outland
    athena% add gnu
       To debug a program, someone has to first compile it with the debug (-g ) option, e.g.
    athena% g++ -ansi -pedantic -g -o filename filename.C
       To invoke the debugger with the executable program,
    athena% ddd filename &


        There are 3 windows that pop up:

      1.     The main window. The main window has three main parts.
          i.  The top panel with the menu and the tool bars.
         ii.  The middle panel with the source code.
        iii.  The bottom panel with the gdb prompt.


      2.    Debugger command tool window, which is titled ddd
      3.     A tip window, which often provides useful debugging tips.

        Someone needs to compile the program, identify errors using the debugger, correct the source code using an editor  (e.g emacs), compile and debug again repeating this process as often as necessary.

        There are ways to stop or break at a line of code and step throught the code. Values of variables can be examined or displayed with various ways. Input and output is done through the debug console, i.e. the bottom panel in the main window with the (gdb) prompt.

       Please, use DDD to debug the programs of problems 1 and 2, i.e. the source code files ps0_1.C and ps0_2.C, repsectively.

    The URL of the DDD web-page is

    http://www.gnu.org/software/ddd/ddd.html
    The URL for the manual of DDD is:
    http://www.gnu.org/manual/ddd

    Problem 5: Using CVS

    For the development of large software packages and programs it may be useful to use a control system for modifications and revisions. Although it may not seem useful for the development of simple small programs (like your first homework problems) it would be very useful for your project, and you will benefit from getting used to using it. In this course we will make use of the CVS (Concurrent Versions System) revision control system to manage our source code. You may obtain more information on CVS using the man command (% man cvs) and from the following URLs:
  • http://hill.ucs.ualberta.ca/Documentation/cvs-1.8.1/cvs_toc.html
  • http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/cvs/
  • http://www.loria.fr/~molli/cvs-index.html
  • http://www.cyclic.com/cvs/info.html
  • To use CVS to check out the problem sets from the 1.124 repository you should set the environment variable CVSROOT as below: (you can also put it in your .environment dotfile)
    % setenv CVSROOT /afs/athena.mit.edu/course/1/1.124/src
    then you can use the command:
    % cvs co Problems/PS0 or, using the alias defined in 1.124/src/CVSROOT/modules
    % cvs co OOP_PS0

    Problem 6: Using Electronic Turnin

    For all following problem sets you must turnin electronically all the source code files you have modified or written. In this problem set (which will not be graded) you are not asked to do any modifications to the source code files provided to you. However, to get familiar with the "electronic turnin" you may electronically turnin the source code files (ps0_1.C, ps0_2.c, & ps0_2.h) and the makefiles (makePS0a & makePS0b)
    To electronically turnin a file use the following command:
    % turnin -c 1.124 problem_set_number filename
    (e.g. to submit the ps0_2.C file of PS0: % turnin -c 1.124 0 ps0_2.C )
    Please do not turnin any executable files electronically. Problems set source code files must be turned in electronically before class starts (i.e at 2:30 pm) on the due date of the Problem Set. Any files turned in later than that time will be considered late and will be penalized.

     

    Problem 7: E-mail us some useful information (optional)

    Finally, to help us understand your background and expectations from this class, please send an e-mail to the TA (petros@mit.edu) with the following information. This is optional, although it would be very helpful to have some feedback from you and also collect some statistics for the students taking the class.
    For 1.124 you need to either know C, or have a strong programming language background (e.g. in Fortran). It is useful but not required to know C. However, especially at the beginning of the course, people who do not know C will need to put much more extra effort.
    E-mail to: petros@mit.edu
    1. Your first name.
    2. Your last name.
    3. Your athena username.
    4. Year of studies (e.g. SM, Ph.D. M.eng) and department?
    5. Do you know C?
    6. Do you know C++?
    7. Do you know Java?
    8. What programming languages (if other than any of the above) do you know?
    9. Have you ever had a numerical analysis class?
    10. Have you ever had a class on algorithms?
    11. Any other computer or programming related experience?
    12. Would you prefer to have this course taught using PC's and microsoft products, or you think it is better the way it is taught now where more emphasis is given to the UNIX operating system by using the athena workstations?
    13. Please, briefly, describe what are your expectations from 1.124 and the reasons for taking the class.


    © 1.124J Foundations of Software Engineering
    Prof. Kevin Amaratunga,1-274, kevina@mit.edu
    TA: Petros Komodromos, 1-245, petros@mit.edu
    TA: Eric Perkins, 1-245, edp@mit.edu