CSE 459.22 LAB1

 

*************************************
Assigned: 3/31/2005

Due: 4/13/2005 11:59pm

*************************************


Goals

        To practice editing and compiling a C/C++ program in the UNIX environment

        To refresh your mind about C programming

Points

      This lab is worth 100 points.

Steps

I. INTRODUCTION AND SETUP

        LogIn

1. Press any key on the keyboard and wait for the login prompt.
2. When you see the "login:" prompt, type in your username (usually your last name) and hit return.
3. At the "password:" prompt, type in the last four digits of your social security number, followed by your first and last initial in lower case. For example, "5670bd". This is your default password.

NOTE: If you are facing any problems in this regard, i.e. not knowing your login names or the default password, please contact the help desk at 2-6542.  

        Enter user name and password.        

1. On your first login, the system will prompt you to change your password.
2. In future, you can use the passwd command to change your password. Make sure that you remember your new password.

        Open an xterm Window in the UNIX environment, and you will see the following prompt
       /~~~~~~/username/ >
 Now, you are ready to play with the Unix system!

II. FOR YOUR INFORMATION

        Remember to click on the title bar to activate the window you want to work in.

        Remember, this system is case-sensitive.

        Recommend you to create a new directory with name “cse459”, which can help to organize all your files for this class in one place.

mkdir cse459 <return>

cd cse459 <return>

        The UNIX command man will tell you about a specific command.  For example, man mkdir will give the description of Unix command mkdir.

        Some important UNIX commands:

1. ls -l            list files
2. cp              copy files
3. more          display file contents on screen
4. mv             move/rename files
5. rm             remove files
6. mkdir        make directory
7. cd             change directory
8. rmdir         remove directory
9. lp              print command
10. emacs     invokes the Emacs editor

        At the prompt, the up arrow key brings up previously typed commands in reverse order; the down arrow key brings up previously typed commands in forward order.
   

III. DESCRIPTION OF THE ASSIGNMENT  

        Your main() program should give the user a menu to choose from, as shown below.

I. Enter a date
Q. Quit

Your program should proceed based on the user’s choice.

a) If the user chooses I (Input),
read a date from the keyboard as mm/dd/yy;
convert it to the output format if input is right, otherwise, give error message;
return to the main menu and wait for user to choose the next action;
b) If the user chooses Q( quit), exit from the program.

        Specification of Input and Output :

        The correct input format is:

mm/dd/yy,

for example: 01/01/01.

        The correct output format is:

mm/dd/yyyy,

where month and day do not need to be zero filled. An example could be 1/1/2001.

        Assume we are interested only in years between 1950 and 2049, a Y2K correction is necessary for a 2-digit year, .i.e. if (year < 50) year += 2000; else if (year < 100) year += 1900.

        If the input is not in correct format, your program needs to display an error message. For example, if 1/1/01 has been entered as a date by the user, the following error message will be given.

Invalid date format: 1/1/01 

        Hint: you can use functions strtok and atoi from the C library to parse the input and extract month, day and year.

        You don't need to handle invalid date, such as 09/50/01.  We will take care of that in the following labs.

        The following labs will base on the date class in lab0. Try to get this lab working !

        Save your program as lab1.cpp and compile it with g++ by entering the following command in the xterm window:

g++ -o lab1  lab1.cpp <return>

Remove all compilation errors and warning messages before running the program. Recompile each time you make a change to the program. By finishing, your program should compile and return to the prompt without displaying any error messages.

        Run your program by entering the following command in the xterm window:

lab1 <return>

Test your program with several cases you may think of, such as "1/1/01", "01012001", "01/01/50", "12/12/01". It should comply with the specifications given above.


One possible script for running your program is as follows :


(I) Enter a date
(Q) Quit

I <return>

Enter the starting date <mm/dd/yy> => 1/1/01 <return>
Invalid date format: 1/1/01

(I) Enter a date
(Q) Quit

I <return>

Enter the starting date <mm/dd/yy> => 01012001 <return>
Invalid date format: 01012001

(I) Enter a date
(Q) Quit

I <return>

Enter the starting date <mm/dd/yy> => 01/01/50 <return>
The date is 1/1/1950

(I) Enter a date
(Q) Quit

I <return>

Enter the starting date <mm/dd/yy> => 12/12/01 <return>
The date is 12/12/2001 

(I) Enter a date
(Q) Quit

Q <return> 

Submission 

When you finish with the lab, you need to turn it in for grading. The submit command submits your lab electronically. You MUST use the submit command to turn in your labs. The format of submit command is as follows:

submit classname labname files-to-submit

where,

classname is the name of the CIS 459.22 section that you are enrolled in. Your classname is c459.22ab .

labname is the lab you are working on (lab1, lab2, etc.). For this lab, labname is lab1 .

files-to-submit is a list of the files that make up the lab. For now, it only contains lab1.cpp .

NOTE:

1. All of the files in a lab MUST be submitted using one command. If you use two submit commands, the second one erases the files from the first submission.

2. Your programs MUST be submitted in source code form. Make sure that you submit the "lab1.cpp" file only. Do not submit the object file. If you submit the object code, your lab submission will be considered as invalid and late penalty will be imposed.

3. Each submit command MUST be entered on one line without pressing Enter. If the line you are entering is too long, it wraps onto the next line.

4. It is YOUR responsibility to make sure your code can compile and run on CSE server stdsun.cis.ohio-state.edu, if you develop the code using other systems.

Submitting Lab1

To submit your lab for grading, use the following command from the directory which contains your lab1.cpp file:

submit c459.22ab lab1 lab1.cpp