Thread: Need help with project!

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    1

    Post Need help with project!

    The project description is as follows:

    The task is to develop a program to compute how to produce a sail using standardized sheets of fabric.
    We assume there is a fabric produced in rectangular sheets, the size of the sheet is known (width and height). Next, there is a request to produce a rectangular sail (again, width and height is given). The program reads the dimensions and computes the number of fabric sheets needed to produce the sail.
    The computation is slightly more complicated, we assume there is an overlap needed in the places where the sheets are sewed. Thus the program reads the size of the fabric, the size of the sail and compares them. If the fabric sheets must be sewed, the program further asks for the width of the required overlap.
    We assume the fabric sheets are sewed in a rectangular grid, i.e. all the rectangles are aligned in the same orientation. Moreover, we assume that the extra material (that exceeds the size of the sail) must be discarded (cannot be re-used).

    Need help with project!-index-png

    The input of the program consists of:

    • the dimensions of the fabric sheet,
    • the dimensions of the sail, and
    • the width of the overlap (only if the fabric must be actually sewed).

    The output of the program is the minimal number of the fabric sheets needed to produce the sail. Some combinations of dimensions may cause the sail cannot be produced, an extra output is displayed in such a case (see below).
    The program must validate input data. If the input is invalid, the program must detect it, it shall output an error message (see below) and terminate. If displayed, the error message must be displayed to the standard output (do not send it to the error output) and the error message must be terminated by a newline (\n). The input is considered invalid, if:

    • the width, height, or overlap size is not a decimal number,
    • width or height is missing, is negative or zero,
    • overlap size is negative (i.e. overlap size may be zero),
    • overlap size is missing and the overlap size is needed for the computation.


    The sample program runs as follows:
    Sheet dimensions:
    2.5 3
    Sail dimensions:
    12 5
    Overlap:
    0
    Sheets: 8

    Sheet dimensions:
    2.5 3
    Sail dimensions:
    12 5
    Overlap:
    0.2
    Sheets: 12

    Sheet dimensions:
    4 3
    Sail dimensions:
    5 4
    Overlap:
    0.1
    Sheets: 2

    Sheet dimensions:
    3 4
    Sail dimensions:
    2 2
    Sheets: 1

    Sheet dimensions:
    1e100 1e100
    Sail dimensions:
    3e100 3e100
    Overlap:
    1e99
    Sheets: 16

    Sheet dimensions:
    0.71 1
    Sail dimensions:
    4.91 1.7
    Overlap:
    0.01
    Sheets: 14

    Sheet dimensions:
    2 2
    Sail dimensions:
    5 1
    Overlap:
    1.5
    Sheets: 7

    Sheet dimensions:
    2 1
    Sail dimensions:
    5 1
    Overlap:
    1.5
    Sheets: 7

    Sheet dimensions:
    1 1
    Sail dimensions:
    5 1
    Overlap:
    1.5
    No solution.

    Sheet dimensions:
    3 abcd
    Invalid input.

    Sheet dimensions:
    -5 1
    Invalid input.
    I have already worked on it a bit but I can't figure out how to do the overlap calculation and how to add it to my code. I also still can't figure out how to print Invalid input if the input is a negative number or it is not a number.

    I have attached my .c file here too.
    sails.c
    Code:
    #include <stdio.h>
    
    int main() {
    	float sheetdimh, sheetdimw, sheetarea, saildimh, saildimw, sailarea, overlap, sheets;
    	printf("Sheet dimensions:\n");
    	scanf("%g%g", &sheetdimh,&sheetdimw);
    	printf("Sail dimensions:\n");
    	scanf("%g%g", &saildimh,&saildimw);
    	printf("Overlap:\n");
    	scanf("%g", &overlap);
    	sheetarea = sheetdimh * sheetdimw;
    	sailarea = saildimh * saildimw;
    	sheets = sailarea / sheetarea;
    	printf("Sheets: %g\n", sheets);				
    	return 0;
    }
    Last edited by Salem; 11-03-2016 at 02:49 AM. Reason: Inlined the code for easy reading

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Please do not post links to your code - use the code tag feature of the boards to
    post the code here. It also allows other people to look at your code and learn from it.
    Double Helix STL

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,801
    Perhaps the simple observation that N sheets need N-1 overlaps.

    Try it with a few sheets of paper and measure it out (as a practical experiment).

    As for the error checking, you need to do something like this.
    Code:
    if ( scanf("%g",&var) == 1 ) {
      if ( var > 0 ) {
        // it's good
      } else {
        // it's negative
      }
    } else {
      // it's garbage, throw away the rest of the input line
      int ch;
      while ((ch=getchar()) != EOF && ch != '\n' );
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  3. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  4. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM

Tags for this Thread