Im new here and asking for help.

This is a discussion on Im new here and asking for help. within the C Programming forums, part of the General Programming Boards category; Hi all Its my first time here. I need to write a C program that uses a board of size ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    9

    Im new here and asking for help.

    Hi all
    Its my first time here.

    I need to write a C program that uses a board of size height x width, and a set of rectangles ri=(heighti x widthi), and I want to find a solution how to cover the whole board with all or with a part of the pieces of the puzzle., in each level, , in each level, I need to check first the horizontal option then the vertical option.

    I already wrote part of the functions but still Im missing the recursive functions I need two recursive calls, one to check the horizontal option and one to the vertical option.

    the output should look like that:

    piece #: 0 1 2 3 4 5
    -----------------------------------
    piece heights: 4 2 2 1 2 1
    piece widths: 6 6 5 6 3 4

    +-------+
    |0000003|
    |0000003|
    |0000003|
    |0000003|
    |5222223|
    |5222223|
    |5111111|
    |5111111|
    +-------+

    each piece is represnted by a different number.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Fascinating, I'm sure, but I don't see any of your code or your attempt. On that note:

    Quote Originally Posted by kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

    It appears that you are posting a homework assignment or other project.

    Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

    Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.


    On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

    Feel free to PM me with any questions.

    Good Luck,

    Kermi3

    Read and follow the above instructions, and try your post (in the same thread) again.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    9

    I have got something but its still a mess so...

    Code:
    #include <stdio.h>
    #define max_Size 19
    #define max_pieces 10
    
    void arrange(int width[], int height[], int size);
    
    int check_full(int table[], int size);
    
    void intial_table(int table[], int size);
    
    int find_empty_cell(int table[], int size, int pos);
    
    void structure_of_puzzle(int width_of_puzzle, int height_of_puzzle, int size);
    
    void pieces(int height_of_puzzle,int width_of_puzzle,int width_of_piece,
    			int height_of_piece,int position);
    
    void main() {
    		
    	int width[max_pieces], // the array of the pieces' heights
    		height[max_pieces], // the array of the pieces' widths
    		i, // index
    		numH,numW,numP;//heights widths and number of pieces
    	printf("Enter puzzle height( < 20 ) width( < 20 ) number of pieces( <= 10 )\n");
    	scanf("%d%d%d",&numH,&numW,&numP);
    	printf("Enter array of size %d of piece heights:\n",numP);
    	for (i=0; i<numP; i++)
    	scanf("%d",&height[i]);
    	printf("Enter array of size %d of piece widths:\n",numP);
    	for (i=0; i<numP; i++)
    	scanf("%d",&width[i]);
    	arrange(width, height,numP);
        for (i=0; i<numP; i++) printf("%3d", i);
    	putchar('\n');
    	for (i=0; i<numP; i++) printf("%3d", height[i]);
    	putchar('\n');
    	for (i=0; i<numP; i++) printf("%3d", width[i]);
    	putchar('\n');
    	pieces(numH,numW,width[0],height[0],0);
        structure_of_puzzle(numH,numW,numH*numW);
    }//main
    
    
    void arrange(int width[], int height[], int size) { // arranges the arrays in descending fashion
    	int i, j, tmp1, tmp2;
    	
    	for (i=0; i<size; i++) {
    		if (width[i]>height[i]) {
    			tmp1=width[i];
    			tmp2=height[i];
    		}//if width
    		else {
    			tmp1=height[i];
    			tmp2=width[i];
    		}//else
    		for (j=i; (tmp1*tmp2)>=(width[j-1]*height[j-1]) && j>0; j--) {
    			height[j]=height[j-1];
    			width[j]=width[j-1];
    		}//for j
    		width[j]=tmp1;
    		height[j]=tmp2;
    	}//for i
    }//arrange
    
    void intial_table(int table[], int size) {//gives initial value to all the array
    	int i;
    	for (i=0; i<size; i++) table[i]=-10;
    }//intial_table
    
    int check_full(int table[], int size) {//checks wether the array is full
    	int i; //index
    	for (i=0; i<size; i++)
    		if (table[i]==-10) return 0;
    	return 1;
    }//check_full
    
    
    int find_empty_cell(int table[], int size, int pos) {//finds and marks free cells
    	int i;
    	for (i=0; i<size && table[i]!=-10; i++);
    	return i;
    }//find_empty_cell
    
    void structure_of_puzzle(int height_of_puzzle, int width_of_puzzle, int size){//gives the dimantions of the puzzle
    	int row,col,index;
    	for(index=0;index<=size;index++){
    		row=index/width_of_puzzle;
    		col=index%width_of_puzzle;
    	}//for
    }//structure_of_puzzle
    
    void pieces(int height_of_puzzle,int width_of_puzzle,int width_of_piece[],
    			int height_of_piece[],int position){
    	int i,j;
    	for (i=0;i<=width_of_puzzle;i++)
    		for(j=0;j<=height_of_puzzle;j++);
    
    
    
    
    
    
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21