Von Koch c++

Hello everyone.
I realize the Von Koch curve in C + + (using the graphics.h) but I'm stuck and I can not continue.
the main must draw the curve in points decided by the user
This is the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//main

#include <graphics.h>
#include "VonKoch.h"
#include "Grafica.h"
#include <stdio.h>
#include <math.h>


int main(){
    float xa, ya, xb, yb, xc, yc, xd, yd, segmento;
    printf("Inserisci la x del punto a->");
    scanf("%f",&xa);
    printf("Inserisci la y del punto a->");
    scanf("%f",&ya);
    printf("Inserisci la x del punto b->");
    scanf("%f",&xb);
    printf("Inserisci la y del punto b->");
    scanf("%f",&yb);
   // Punto A(xa,ya);
    //Punto B(xb,yb);
    printf("\nxa: %f", xa);
    printf("\nya: %f", ya);
    printf("\nxb: %f", xb);
    printf("\nyb: %f", yb);
    segmento=sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
    printf("\nIl segmento e' lungo: %f", segmento);
    xc=xa+ 0.33333 * (xb-xa);
    yc=ya- 0.33333 * (yb-ya);
    printf("\nxc: %f", xc);
    printf("\nyc: %f", yc);
    xd=xa+ 0.66666 * (xb-xa);
    yd=ya- 0.66666 * (yb-ya);
    printf("\nxd: %f", xd);
    printf("\nyd: %f", yd);
    Punto A(xa,ya);
    Punto B(xb,yb);
    Punto C(xc,yc);
    Punto D(xd,yd);
    system("PAUSE");

    return 0;
}


1
2
3
4
5
6
7
8
9
//punto
#include "Punto.h"

Punto::Punto(float a, float b){
    x=a;
    y=b;
}

Punto::~Punto(){}


1
2
3
4
5
// Grafica
#include "Grafica.h"
Grafica(float, float, float, float, float, float);
        float DrawLine(float, float);
closed account (o3hC5Di1)
Hi there,

Welcome to the forums. Small remark: Your program is mostly C, aside fromthe int main().
As graphics.h is a windows header file, I would suggest you move this topic to the "windows programming" forum. Also, if you could clarify what it is you are stuck on, which part of the program you don't know how to continue, that would help others to help you better.

All the best,
NwN
I have to make a program in C + + that simulates the Von Koch curve (using the graphics.h).
I can not communicate to the main with the class Von Koch, in the main asks the user to enter the x and y of the points A and B and then go into the class Von Koch and let him calculate CDE then become fali points which must from the lines to draw the curve

This is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <graphics.h>
#include "VonKoch.h"
#include "Grafica.h"
#include <stdio.h>
#include <math.h>


int main(){
    float xa,xb,ya,yb;
    printf("Inserisci la x del punto a->");
    scanf("%f",&xa);
    printf("Inserisci la y del punto a->");
    scanf("%f",&ya);
    printf("Inserisci la x del punto b->");
    scanf("%f",&xb);
    printf("Inserisci la y del punto b->");
    scanf("%f",&yb);
    printf("\nxa: %f", xa);
    printf("\nya: %f", ya);
    printf("\nxb: %f", xb);
    printf("\nyb: %f", yb);
    VonKoch a;
    system("PAUSE");

    return 0;
}
Class Punto

[code]
class Punto{
    public:
        float x;
        float y;
        Punto(float a, float b);
        ~Punto();
};


file .cpp class Punto

1
2
3
4
5
6
7
8
9
10
#include "Punto.h"
#include "VonKoch.h"

Punto :: Punto(float a, float b){
    x = a;
    y = b;
}

Punto::~Punto(){}


class VonKoch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Punto.h"

class VonKoch{
    private:
    Punto a;
    Punto b;
    float n;
    public:
    VonKoch(Punto, Punto);
    VonKoch(Punto, Punto, float);
    VonKoch();
    float calcolaPunti(float,float,float,float);
    void draw();

};


file.cpp class VonKoch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "VonKoch.h"
#include <math.h>
#define PI 3,14159

VonKoch::VonKoch(Punto X, Punto Y){

}

VonKoch::VonKoch(Punto X, Punto Y, float n){

}

VonKoch :: VonKoch(){
    a=0;
    b;
    n;

}

Punto VonKoch::calcolaPunti(float xa,float ya,float xb,float yb){
    float xc, yc, xd, yd, xe, ye, segmento;
    float beta, alpha;
    segmento=sqrt((xb - xa)*(xb - xa)+(yb - ya)*(yb - ya));
    printf("\nIl segmento e' lungo: %f", segmento);
    xc = xa + 0.33333 * (xb - xa);
    yc = ya - 0.33333 * ( yb - ya);
    printf("\nxc: %f", xc);
    printf("\nyc: %f", yc);
    xd = xa + 0.66666 * (xb - xa);
    yd = ya - 0.66666 * (yb - ya);
    printf("\nxd: %f", xd);
    printf("\nyd: %f", yd);
    float a = ya-yb;
    float b = xb-xa;
    alpha = atan2(a,b);
    beta = (PI/3) - alpha;
    xe = xc + 0.33333 * segmento * cos(beta);
    ye = yc + 0.33333 * segmento * sin(beta);
    printf("\nxe: %f", xe);
    printf("\nye: %f", ye);
    Punto A(xa,xb);
}

void VonKoch :: draw(){
    if(segmento < n){
        drawVonKoch(A,B);
    }else{
        drawVonKoch(A, C);
        drawVonKoch(C, E);
        drawVonKoch(E, D);
        drawVonKoch(D, B);
    }
    }
void drawVonKoch(){
    //should draw the line between the points
}
Here you can find relevant documentation about the graphics.h library:
http://www.cs.colorado.edu/~main/bgi/doc/

And it seems that the line() function is what you want:
http://www.cs.colorado.edu/~main/bgi/doc/line.html

That said, the graphics.h library is very old, and probably your current compiler is very old as well if it supports it.

Therefore I suggest that you get a modern C++ IDE and compiler, such as Visual Studio Express, then use a modern library for 2D graphics such as SFML.

http://www.microsoft.com/visualstudio/eng/downloads
http://www.sfml-dev.org/

Then drawing things should become relatively easy:
http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php
Could you help me with the program? I do not know how to operate it, it is not for libraries or lines does not work
What exactly do you need help with?
Did you check the links in my previous post?
I can not do the program, I do not know if this code is fine and I to be delivered Wednesday.
They were able to communicate with classes, but several errors in the class point and do not understand why.
Last edited on
Topic archived. No new replies allowed.