Thread for Programming and Realeted Topics

madurax86

Member
Jun 29, 2006
4,385
88
0
This is how you use it,
the example is done to get you started with out trouble
* the numbers in yellow show the steps in which the coordinates are entered to the program
recommended way of entering coordinates is "4 5" (without "") if you want to enter the coordinate (4,5)
* numbers in red gives the limits of the default console dialog
* numbers in white are the ones you need to enter *according to the steps* inorder to draw the picture shown in the image

zzsd.jpg

Screenshot

AND REPORT ERRORS/BUGS IF YOU FIND ANY :D
TRY TO FIX THEM TOO!
Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <math.h>

using namespace std;

void gotoxy(int x, int y)
{
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
float round(float n,int place)// taken from http://forums.devshed.com/c-programming-42/round-up-a-decimal-number-in-c-69908.html
{
    float d;
    int    i;
    /* rescale 123.45678 to 12345.678 */
    d = n * pow(10,place);
    /* round off: 12345.678 + 0.5 = 12346.178 -> 12346 */
    i = d + 0.5;
    /* restore to its original scale: 12346 -> 123.46 */
    d = (float)i / pow(10,place);

    return d;
}

int DrawLine(COORD p1,COORD p2)
{
    int i,j,w,h,iStart,iEnd;
    short k,l;
    //p1 should be on the left of p2
    if (p1.X>p2.X){
        k=p2.X;
        l=p2.Y;
        p2.X=p1.X;
        p2.Y=p1.Y;
        p1.X=k;
        p1.Y=l;
    }
    double c,r;
    h=abs(p1.Y-p2.Y);
    w=abs(p1.X-p2.X);
    
    iStart=p1.X; //set all to defaults
    iEnd=0;
    gotoxy(0,0); 
       if ((h==0) || (w==0))
        {
            if (h==0) {
                    for (i=0;i<=w;i++){
                            gotoxy(i+p1.X,p1.Y);
                            cout<<"*";
                        }
                    goto end;
                }
            if (w==0) {
                if (p1.Y>p2.Y){
                    for (j=0;j<=h;j++){
                            gotoxy(p1.X,p1.Y-j);
                            cout<<"*";
                        }
                    goto end;
                    }
                else
                {
                    for (j=0;j<=h;j++){
                            gotoxy(p1.X,p1.Y+j);
                            cout<<"*";
                        }
                    goto end;
                }
            }
        }
        else
        {
            r=h%w;
            r=r/w;
            c=round(h/w,0);
            if (p1.Y>p2.Y){
                for (i=0;i<=w;i++){
                    iStart=iEnd;
                    iEnd=-(int)(c*(i+1) + r*i);
                    if (i==w){
                        iStart=iEnd;
                        iEnd=h;
                    }
                    for (j=iStart;j>=iEnd;j--){
                        gotoxy(i+p1.X,j+p1.Y);
                        cout<<"*";
                    }
                }
            }
            else
            {
                for (i=0;i<=w;i++){
                    iStart=iEnd;
                    iEnd=(int)(c*(i+1) + r*i);
                    if (i==w){
                        iStart=iEnd;
                        iEnd=h;
                    }
                    for (j=iStart;j<=iEnd;j++){
                        gotoxy(i+p1.X,j+p1.Y);
                        cout<<"*";
                    }
                }
            }
        }
    end:
    return 0;
}
main()
{
    int t;
    COORD p1,p2,p3;
    t=1;
    cout<<"Enter 1st point : ";
    cin>>p1.X>>p1.Y;
    system("CLS");
    p3=p1;
    while (t=1){
        gotoxy(0,0);
        cout<<"                                              ";
        gotoxy(0,0);
        cout<<"("<<p3.X<<","<<p3.Y<<")"<<"Enter next point : ";
        cin>>p2.X>>p2.Y;
        p3=p2;
        DrawLine(p1,p2);
        p1=p3;
    }
}
 
Last edited:

rclakmal

Active member
  • May 8, 2008
    698
    183
    43
    In a galaxy far far away
    Sry guys couldnt post much in the thread coz i was really busy this work with my works and also undergoing some treatments for an injury !!!! Will be back soon with new algorithms !!!!!! But u guys keep posting !!!!!!!!
     

    rclakmal

    Active member
  • May 8, 2008
    698
    183
    43
    In a galaxy far far away
    Hey Guys a small Programme test ur calculation speed !!! Download it ,extract and simply run the exe file .....Ill post the source code after u test it !!!

    When u run the .exe file u will get a message called "This executable was created using ....."

    simply press OK and continue .....the reason is i have used a un registered SW to convert my .jar file in to an exe file ......

    And there are some erros ....check whether u can find them and Check ur brain and most important thing

    POST UR RESULT HERE !!!!!! here is the link
    :lol::):rofl:
    DOWNLOAD IT HERE!!!
     
    Last edited:

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Matrix Multiplier
    Code:
    Test Case, you can change these accordingly
    
    C = |12| * |256| 
        |34|   |563|
    
    A = |12| 
        |34|
    
    B = |256| 
        |563|
    r = A's row count
    c = A's and B's column count
    d = B's column count
    
    C will contain the resulting matrix.
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
        int r,c,d,x,y,i;
        r=2;
        c=2;
        d=3;
        float A[r][c], B[c][d], C[r][d],D;
        A[0][0]=1;
        A[0][1]=2;
        A[1][0]=3;
        A[1][1]=4;
    
        B[0][0]=2;
        B[0][1]=5;
        B[0][2]=6;
        B[1][0]=5;
        B[1][1]=6;
        B[1][2]=3;
    
        for (y=0;y<r;y++){
            for (x=0;x<d;x++){
                D=0;
                for (i=0;i<c;i++){
                        D=D+A[y][i]*B[i][x];
                    }
                C[y][x]=D;
                printf("%f ",C[y][x]);
                }
            printf("\n");
            }
        getch();
        return 0;
    }
     

    Jack_Sparrow

    Well-known member
  • Jun 16, 2008
    42,524
    1
    16,931
    113
    Black Pearl
    mara cn eka meee
    1 pharmcay ekaka access podi magulak dala tiyanawa :P
    eeke hadaopu ekata podi deyak amataka wela :D

    den pharmacy ekata aluthen stock gattama price wenas ne :D
    bt ee item ekeee price eka wenas karanna beeene mokada parana price ekee stock tawa itiri wela tiyanawanee so ee wage welawal walata mokada karanna honda :)
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    mara cn eka meee
    1 pharmcay ekaka access podi magulak dala tiyanawa :P
    eeke hadaopu ekata podi deyak amataka wela :D

    den pharmacy ekata aluthen stock gattama price wenas ne :D
    bt ee item ekeee price eka wenas karanna beeene mokada parana price ekee stock tawa itiri wela tiyanawanee so ee wage welawal walata mokada karanna honda :)

    හොද ප්‍රශ්නයක් !
    මේකට විසදුමක් විදියට Items Reference File එකට අලුත් entry එකක් දාන්න හැදුවානම් හරි

    Code:
    ITEM_CODE     ITEM_NAME        PRICE_OF_ONE_UNIT     UNIT_TYPE
    00164         Panadol Box      50                    BOX
    00165         New Panadol Box  52                    BOX

    දැන් New Panadol Box කියල තමා පාවිච්චි කරන්න වෙන්නේ :P