ECS 40

Program #2 (50 points, 2 hours)

Spring 2009

 

Due: Wednesday, April 22nd at 11:59 pm using handin to p2 directory of cs40

Filenames: main.cpp, house.h, house.cpp, room.h, room.cpp, wall.h, wall.cpp, screen.h, screen.cpp, and Makefile.

Executable Name: house.out.

 

For the next four programming assignments, we will be writing a program that reads in, edits, displays, and writes out a house.  For this first assignment, you will just write the functions needed to add rooms to a new house.  For this first assignment, you will write in C, but use the g++ compiler.  This will allow you to use the “//” line comments of C++, and have functions with identical names.  For those who do not know C, but do know C++, I have included alternative specifications labeled C++:.

 

1. Measurements

1.1. All measurements will be whole feet.  A foot is represented as a character width or height on the screen.

1.2. The lower left of the drawing is considered (0,0), with the first value being the horizontal location.  All locations have non-negative values.

2. House, Room, Wall, and Screen.

2.1. Each of these should be declared as typedef structs (C++: classes) in their respective header files.

2.2. For this assignment, a House can contain up to five Rooms.

2.2.1.      Houses can never be more than 20 feet vertically, and 70 feet horizontally

2.3. A Room can have up to six walls.

2.3.1.      The ending location of the last wall will be the starting location of the first wall.

2.4. A Wall has at least a starting location, and an ending location.

2.5. A Screen contains a 70 x 20 two-dimensional array of chars.

2.5.1.      A Screen type variable named screen should be declared globally in screen.cpp, and declared as extern in screen.h.

2.5.2.      You will use screen to keep track of the current appearance of the house.

2.5.3.      You will need to update screen in the editing functions of the other types.

2.5.4.      Vertical walls are drawn with “|”.  Horizontal walls are drawn with “-”.  Corners are drawn with ‘|’;

3. Functions may take one, or two parameters.  Exactly one of those parameters must be a pointer to one of the four typedef structs.  (C++: a function may take at most one parameter, and that parameter cannot be a class object.)

3.1. The functions with a typedef struct as a parameter must be declared in that struct’s header file, and defined in its respective .cpp file.

4. main()

4.1. main.cpp will only contain main().

4.2. main() will only have a declaration of a House, function calls, and return 0. 

4.3. There must not be any flow control statements in main().

5. You may assume that the user will always enter valid input.

6. All output must match mine exactly.

7. All compiling in your Makefile must be done with –Wall, -g, and –ansi options.  Points will be deducted for warnings.

8. Ten points of your grade will be based on adherence to the Programming Standards.

9. Suggestions

9.1. Write in a top-down fashion starting with House.  Write stubs for House functions called from main(), and then compile and run it.  As you fill in the House functions, write stubs for the functions they call, and compile and run each time.  Proceed through House to Room and then to Wall.  However, I wrote the Screen functions as they were needed so that I could see output as I went.

9.2. Beyond the above specifications, how you store the information about the house is up to you.

9.3. fgets() with stdin works well to eat-up the ‘\n’ remaining from previous scanf() calls.

9.4. Adding a new wall can change the ‘-‘ in an old wall!

9.5. My own house.out is in ~davis/40/p2.

9.6. You will find testfile1 in ~davis/40/p2 that can be used to test your program.  It created the example below.  To compare your output with mine you can: 1) redirect testfile1 into my house.out and redirect the output into a file named seanout;  2) redirect testfile1 into your house.out and redirect the output into a file named myout; and 3) diff myout seanout


[@lect2 p2]$ house.out

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                      

18                                                                      

17                                                                       

16                                                                      

15                                                                      

14                                                                      

13                                                                       

12                                                                      

11                                                                      

10                                                                       

 9                                                                      

 8                                                                      

 7                                                                      

 6                                                                       

 5                                                                      

 4                                                                      

 3                                                                       

 2                                                                      

 1                                                                      

 0                                                                      

 

House Editing menu:  0. Done.  1. Add room.

Your choice: 1

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                      

18                                                                       

17                                                                      

16                                                                      

15                                                                      

14                                                                       

13                                                                      

12                                                                      

11                                                                       

10                                                                      

 9                                                                      

 8                                                                      

 7                                                                       

 6                                                                      

 5                                                                      

 4                                                                       

 3                                                                      

 2                                                                      

 1                                                                      

 0                                                                       

 

Starting location (x, y): (5,5)

Wall direction (U D R L) and length: U 10

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                       

18                                                                      

17                                                                      

16                                                                       

15      |                                                               

14      |                                                               

13      |                                                               

12      |                                                                

11      |                                                               

10      |                                                               

 9      |                                                                

 8      |                                                               

 7      |                                                               

 6      |                                                               

 5      |                                                                

 4                                                                      

 3                                                                      

 2                                                                       

 1                                                                      

 0                                                                      

 

Starting location (x, y): (5, 15)

Wall direction (U D R L) and length: R 8

 


   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                      

18                                                                      

17                                                                       

16                                                                      

15      |--------                                                       

14      |                                                               

13      |                                                               

12      |                                                               

11      |                                                               

10      |                                                                

 9      |                                                               

 8      |                                                               

 7      |                                                               

 6      |                                                               

 5      |                                                               

 4                                                                      

 3                                                                       

 2                                                                      

 1                                                                      

 0                                                                       

 

Starting location (x, y): (13,15)

Wall direction (U D R L) and length: D 10

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                      

18                                                                       

17                                                                      

16                                                                      

15      |-------|                                                        

14      |       |                                                       

13      |       |                                                       

12      |       |                                                       

11      |       |                                                        

10      |       |                                                       

 9      |       |                                                       

 8      |       |                                                        

 7      |       |                                                       

 6      |       |                                                       

 5      |       |                                                       

 4                                                                       

 3                                                                      

 2                                                                      

 1                                                                       

 0                                                                      

 

Starting location (x, y): (13, 5)

Wall direction (U D R L) and length: L 8

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                       

18                                                                      

17                                                                      

16                                                                       

15      |-------|                                                       

14      |       |                                                       

13      |       |                                                        

12      |       |                                                       

11      |       |                                                       

10      |       |                                                       

 9      |       |                                                        

 8      |       |                                                       

 7      |       |                                                       

 6      |       |                                                        

 5      |-------|                                                       

 4                                                                      

 3                                                                      

 2                                                                       

 1                                                                      

 0                                                                      

 

House Editing menu:  0. Done.  1. Add room.

Your choice: 1

 

// Edited by Sean


   0123456789012345678901234567890123456789012345678901234567890123456789

19                                                                      

18                                                                      

17                                                                       

16                                                                      

15      |-------|                                                       

14      |       |                                                        

13      |       |                                                       

12      |       |                                                       

11      |       |-------------|                                         

10      |       |             |                                         

 9      |       |             |                                         

 8      |       |             |-----|                                   

 7      |       |                   |                                    

 6      |       |                   |                                   

 5      |-------|                   |                                   

 4              |                   |                                   

 3              |                   |                                   

 2              |                   |                                   

 1              |                   |                                   

 0              |-------------------|                                   

 

House Editing Menu:  0. Done. 1. Add room.

Your choice: 1

// Edited by Sean

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                     |------------------------|                        

18                     |                        |                       

17                     |                        |                       

16                     |                        |                       

15      |-------|      |                        |                       

14      |       |      |                        |                       

13      |       |      |                        |                       

12      |       |      |                        |                        

11      |       |------|------|-----------------|                       

10      |       |             |                                         

 9      |       |             |                                         

 8      |       |             |-----|                                   

 7      |       |                   |                                   

 6      |       |                   |                                   

 5      |-------|                   |      ---------------------        

 4              |                   |                                   

 3              |                   |                                   

 2              |                   |                                   

 1              |                   |                                   

 0              |-------------------|                                   

 

// Edited by Sean

 

Starting location: (60, 16)

Wall direction (U D R L) and length: D 11

 

   0123456789012345678901234567890123456789012345678901234567890123456789

19                     |------------------------|                       

18                     |                        |                       

17                     |                        |                        

16                     |                        |    |---------|        

15      |-------|      |                        |    |         |        

14      |       |      |                        |    |         |        

13      |       |      |                        |    |         |        

12      |       |      |                        |    |         |        

11      |       |------|------|-----------------|    |         |        

10      |       |             |                      |         |        

 9      |       |             |            |---------|         |        

 8      |       |             |-----|      |                   |        

 7      |       |                   |      |                   |        

 6      |       |                   |      |                   |        

 5      |-------|                   |      |-------------------|        

 4              |                   |                                   

 3              |                   |                                    

 2              |                   |                                   

 1              |                   |                                   

 0              |-------------------|                                   

 

House Editing Menu:  0. Done. 1. Add room.

Your choice:  0

[@lect2 p2]$