Question: PROGRAMMING IN C LANGUAGE Please try to give multiple files DESCRIPTION Files to submit: all .c and .h files that make up your program paint.out.

PROGRAMMING IN C LANGUAGE

Please try to give multiple files

DESCRIPTION

Files to submit: all .c and .h files that make up your program paint.out. A Makefile to compile those files into paint.out

Requirements

  • Program must compile with both -Wall and -Werror options enabled
  • Submit only the files requested
  • Use doubles to store real numbers
  • Print all doubles to 2 decimal points unless stated otherwise
  • NEW: You must submit at least two .c files and one .h file

Restrictions

  • No global variables may be used
  • Your main function may only declare variables and call other functions
  • NEW: You must use at least 1 struct in your solution

Description

For your final project you will be implementing a text based version of paint called paint.out. This program exercises all of the topics that we have covered in class except for recursion and has an extreme emphasis on pointers and realloc.

Additional Details

Command Line Arguments

  • Your program should accept optional command line parameters specifying the size of the canvas to create
    • The first parameter is the number of rows
    • The second parameter is the number of columns
  • Since the number of rows and columns are optional your program should be able to be called like
    • ./paint.out
    • ./paint.out num_rows num_columns
  • Either both the number of rows and columns should be specified or neither should
  • The number of rows and columns should both be positive integers >= 1
  • If no command line arguments are given, an incorrect number of command line arguments are given, or their are incorrect values for any of the command line arguments the canvas should default to be 10 X 10

Commands

  • Your program must be capable of executing the following commands. The bolded letter inside the parenthesis is the letter used to specify the command
    • (q)uit
      • Cease the execution of the program and free any dynamically allocated memory that is in use
    • (h)elp
      • Display the help information
        • I've already implemented that prints the help information so you can just copy it to your code and then call it from there
    • (w)rite start_row start_column end_row end_column
      • Draw a line from start_row, start_column to end_row, end_column
        • Horizontal lines are drawn using -
        • Vertical lines are drawn using |
        • Right diagonal lines are drawn using \
        • Left diagonal lines are drawn using /
        • If the line you are drawing intersects another line a + should be displayed at the intersection
          • The exception to this if a line drawn using the same direction overlaps another line going the same direction
            • For example a horizontal line overlapping a horizontal line should continue to be drawn using -
      • Lines should be able to be drawn from either direction. For example a horizontal line should be able to be drawn as either
        • Left to right: w 0 0 0 5
        • Right to left: w 0 5 0 0
      • Lines that are one cell big should be drawn using -
      • If the coordinates given do not form a straight line you should inform the user and not draw the line
    • (e)rase row col
      • Erase the character at row col reverting it back to a blank space
        • Blank spaces are represented as a * to help us better visualize them
    • (r)esize num_rows num_cols
      • Resize the canvas to be num_rows by num_cols big
      • The smallest a board can be resized to is 1 X 1
      • New rows are added to the top of the canvas
      • New columns are added to the right of the canvas
      • New rows/columns are empty
      • The canvas can be resized to be smaller than it is
        • If it is the lower left portion of the canvas is what is kept
    • (a)dd [r | c] position
      • Add a new row or column at the specified position
      • r stands for row and c stands for column so
        • A command to add a new row at position 5 looks like: add r 5
        • A command to add a new column at position 7 looks like: add c 7
      • Valid values for position are between 0 and num_rows/num_cols + 1 based on whether a row or column is specified
      • If adding a row, the row at that position and all rows above are moved up 1
      • If addina column, the column at that position and all columns to the right are moved to the right by 1
    • (d)elete [r | c] position
      • Delete a row or column at the specified position
      • Valid values for position are between 0 and the number of rows/columns
      • If deleting a row, all the rows above the one deleted are shifted down by 1
      • If deleting a column, all the columns to the right of the one deleted are shifted to the left by 1
    • (s)ave file_name
      • Save the current canvas to the file named file_name
      • How you save the file is up to you
    • (l)oad file_name
      • Load a canvas from the file with file_name
      • The structure of these files is the one that you came up with in save

Input

  • Input will not always be valid.
    • If input is invalid you should inform the user and then ask for another command

Hints

  • This is a really big program and you are going to want to break it down into many functions.
    • Trying to do too much in one function will lead lots of confusion and make the problem even harder
    • In total my answer consisted of about 857 lines of C code broken up into 43 functions contained in 7 files
    • I used 4 structs and 1 enum in my answer
  • Take this problem apart piece by piece and test each piece as you add it in.
    • This will help a lot in finding bugs and smooth out the development of your program
    • First start with creating and displaying your canvas
    • After you get that working add in commands one by one
      • This will involve reading the command
      • Then executing the command
      • You might try adding in commands in the following order
        • quit
        • help
        • write
        • add
        • delete
        • resize
        • save
        • load
  • Proper use of structs can greatly simplify this problem

Example

User input has been underlined to help you differentiate between what is user input and what is program output. You do not have to underline anything.

./paint.out 9 * * * * * * * * * * 8 * * * * * * * * * * 7 * * * * * * * * * * 6 * * * * * * * * * * 5 * * * * * * * * * * 4 * * * * * * * * * * 3 * * * * * * * * * * 2 * * * * * * * * * * 1 * * * * * * * * * * 0 * * * * * * * * * * 0 1 2 3 4 5 6 7 8 9 Enter your command: w 0 0 9 9 9 * * * * * * * * * / 8 * * * * * * * * / * 7 * * * * * * * / * * 6 * * * * * * / * * * 5 * * * * * / * * * * 4 * * * * / * * * * * 3 * * * / * * * * * * 2 * * / * * * * * * * 1 * / * * * * * * * * 0 / * * * * * * * * * 0 1 2 3 4 5 6 7 8 9 Enter your command: w 9 0 0 9 9 \ * * * * * * * * / 8 * \ * * * * * * / * 7 * * \ * * * * / * * 6 * * * \ * * / * * * 5 * * * * \ / * * * * 4 * * * * / \ * * * * 3 * * * / * * \ * * * 2 * * / * * * * \ * * 1 * / * * * * * * \ * 0 / * * * * * * * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: w 4 2 4 4 9 \ * * * * * * * * / 8 * \ * * * * * * / * 7 * * \ * * * * / * * 6 * * * \ * * / * * * 5 * * * * \ / * * * * 4 * * - - + \ * * * * 3 * * * / * * \ * * * 2 * * / * * * * \ * * 1 * / * * * * * * \ * 0 / * * * * * * * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: w 4 6 4 1 9 \ * * * * * * * * / 8 * \ * * * * * * / * 7 * * \ * * * * / * * 6 * * * \ * * / * * * 5 * * * * \ / * * * * 4 * - - - + + - * * * 3 * * * / * * \ * * * 2 * * / * * * * \ * * 1 * / * * * * * * \ * 0 / * * * * * * * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: w 8 6 0 6 9 \ * * * * * * * * / 8 * \ * * * * | * / * 7 * * \ * * * | / * * 6 * * * \ * * + * * * 5 * * * * \ / | * * * 4 * - - - + + + * * * 3 * * * / * * + * * * 2 * * / * * * | \ * * 1 * / * * * * | * \ * 0 / * * * * * | * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: a r 3 10 \ * * * * * * * * / 9 * \ * * * * | * / * 8 * * \ * * * | / * * 7 * * * \ * * + * * * 6 * * * * \ / | * * * 5 * - - - + + + * * * 4 * * * / * * + * * * 3 * * * * * * * * * * 2 * * / * * * | \ * * 1 * / * * * * | * \ * 0 / * * * * * | * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: a c 6 10 \ * * * * * * * * * / 9 * \ * * * * * | * / * 8 * * \ * * * * | / * * 7 * * * \ * * * + * * * 6 * * * * \ / * | * * * 5 * - - - + + * + * * * 4 * * * / * * * + * * * 3 * * * * * * * * * * * 2 * * / * * * * | \ * * 1 * / * * * * * | * \ * 0 / * * * * * * | * * \ 0 1 2 3 4 5 6 7 8 9 10 Enter your command: d r 10 9 * \ * * * * * | * / * 8 * * \ * * * * | / * * 7 * * * \ * * * + * * * 6 * * * * \ / * | * * * 5 * - - - + + * + * * * 4 * * * / * * * + * * * 3 * * * * * * * * * * * 2 * * / * * * * | \ * * 1 * / * * * * * | * \ * 0 / * * * * * * | * * \ 0 1 2 3 4 5 6 7 8 9 10 Enter your command: d c 5 9 * \ * * * * | * / * 8 * * \ * * * | / * * 7 * * * \ * * + * * * 6 * * * * \ * | * * * 5 * - - - + * + * * * 4 * * * / * * + * * * 3 * * * * * * * * * * 2 * * / * * * | \ * * 1 * / * * * * | * \ * 0 / * * * * * | * * \ 0 1 2 3 4 5 6 7 8 9 Enter your command: r 4 5 3 * * * * * 2 * * / * * 1 * / * * * 0 / * * * * 0 1 2 3 4 Enter your command: e 1 1 3 * * * * * 2 * * / * * 1 * * * * * 0 / * * * * 0 1 2 3 4 Enter your command: r 7 7 6 * * * * * * * 5 * * * * * * * 4 * * * * * * * 3 * * * * * * * 2 * * / * * * * 1 * * * * * * * 0 / * * * * * * 0 1 2 3 4 5 6 Enter your command: s ex.txt 6 * * * * * * * 5 * * * * * * * 4 * * * * * * * 3 * * * * * * * 2 * * / * * * * 1 * * * * * * * 0 / * * * * * * 0 1 2 3 4 5 6 Enter your command: r 1 1 0 / 0 Enter your command: l ex.txt 6 * * * * * * * 5 * * * * * * * 4 * * * * * * * 3 * * * * * * * 2 * * / * * * * 1 * * * * * * * 0 / * * * * * * 0 1 2 3 4 5 6 Enter your command: q

So all we need to do is do this project by creating multiple files and not just one file. we need to upload multiple .c and.h files. Also we need to make a "makefile".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!