Skip to content

Instantly share code, notes, and snippets.

@vermiculus
Last active December 13, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vermiculus/4973618 to your computer and use it in GitHub Desktop.
Save vermiculus/4973618 to your computer and use it in GitHub Desktop.
Marissa's Classes -- a transcription a Facebook chat with an extraordinarily clever girl who deserves a higher level of self-esteem and confidence.
#include <stdlib.h>
#include "Line.h"
int getLength (Line *l) {
return l->p2->x - l->p1->x;
}
Line* NewLine(void) {
Line *l = (Line*) malloc (sizeof (Line));
l->p1 = NewPoint();
l->p2 = NewPoint();
l->p1->x = 0;
l->p2->x = 0;
return l;
}
void KillLine(Line *l) {
KillPoint(l->p1);
KillPoint(l->p2);
free(l);
}
#include "Point.h"
typedef struct {
Point *p1, *p2;
} Line;
int getLength (Line *l);
Line* NewLine(void);
void KillLine(Line *l);
#include <stdio.h>
#include <stdlib.h>
#include "Line.h" // Line.h already includes Point
int main(int argc, const char * argv[]) {
printf("Hi. \n");
Line *l = NewLine();
l->p1->x = -1;
l->p2->x = 1;
printf("Length: %d\n", getLength(l));
return 0;
}
#include "Point.h"
#include <stdlib.h>
int getDistance(Point *p) {
return p->x;
}
Point * NewPoint(void) {
Point *p = (Point *) malloc (sizeof (Point));
p->x = 0;
return p;
}
void KillPoint(Point *p) {
free(p);
}
// Marissa wrote all of this.
// Copied and pasted right from Facebook chat.
typedef struct {
int x;
} Point;
int getDistance(Point *p);
Point* NewPoint(void);
void KillPoint(Point *p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment