GithubHelp home page GithubHelp logo

struktur-data-algoritma-adt-tugas-individu's Introduction

Struktur Data & Algoritma

Tugas Individu implementasi program dengan ADT dengan bahasa C untuk kasus menghitung keliling dan luas bangun datar: lingkaran, persegi, trapesium, segi lima.

Lingkaran

  • Define constanta PHI = 3.14
const float PHI = 3.14;
  • Buat struct lingkaran yang berisi jari-jari
struct Lingkaran
{
  float r;
};
  • Buat constructor untuk membuat sebuah lingkaran
struct Lingkaran initLingkaran(float r)
{
  struct Lingkaran *l = (struct Lingkaran *)malloc(sizeof(struct Lingkaran));
  l->r = r;
  return *l;
}
  • Buat fungsi untuk menghitung luas lingkaran PHI x r2
float getLuasLingkaran(struct Lingkaran l)
{
  return PHI * l.r * l.r;
}
  • Buat fungsi untuk menghitung keliling lingkaran 2 x PHI x r
float getKelilingLingkaran(struct Lingkaran l)
{
  return 2 * PHI * l.r;
}
  • Buat fungsi untuk mengubah data lingkaran
void ubahLingkaran(struct Lingkaran *l, float r)
{
  l->r = r;
}

Persegi

  • Buat struct Persegi yang berisi sisi
struct Persegi
{
  float s;
};
  • Buat constructor untuk membuat persegi
struct Persegi initPersegi(float s)
{
  struct Persegi *p = (struct Persegi *)malloc(sizeof(struct Persegi));
  p->s = s;
  return *p;
}
  • Buat fungsi menghitung luas persegi sisi x sisi
float getLuasPersegi(struct Persegi p)
{
  return p.s * p.s;
}
  • Buat fungsi menghitung keliling persegi 4 x sisi
float getKelilingPersegi(struct Persegi p)
{
  return 4 * p.s;
}
  • Buat fungsi mengubah data persegi
void ubahPersegi(struct Persegi *p, float s)
{
  p->s = s;
}

Trapesium

  • Buat struct Trapesium yang berisi tiap sisi trapesium dan tinggi
struct Trapesium
{
  float ab, bc, cd, ad, t;
};
  • Buat constructor untuk membuat sebuah Trapesium
struct Trapesium initTrapesium(float ab, float bc, float cd, float ad, float t)
{
  struct Trapesium *tr = (struct Trapesium *)malloc(sizeof(struct Trapesium));
  tr->ab = ab;
  tr->bc = bc;
  tr->cd = cd;
  tr->ad = ad;
  tr->t = t;
  return *tr;
}
  • Buat fungsi untuk menghitung luas trapesium 1/2 x (ab + cd) x tinggi
float getLuasTrapesium(struct Trapesium tr)
{
  return 1 / 2.0 * (tr.ab + tr.cd) * tr.t;
}
  • Buat fungsi menghitung keliling trapesium ab + bc + cd + ad
float getKelilingTrapesium(struct Trapesium tr)
{
  return tr.ab + tr.bc + tr.cd + tr.ad;
}
  • Buat fungsi untuk mengubah data trapesium
void ubahTrapesium(struct Trapesium *tr, float ab, float bc, float cd, float ad, float t)
{
  tr->ab = ab;
  tr->bc = bc;
  tr->cd = cd;
  tr->ad = ad;
  tr->t = t;
}

Segilima

  • Buat struct segilima yang berisi sisi
struct Segilima
{
  float s;
};
  • Buat constructor untuk membuat sebuah segilima
struct Segilima initSegilima(float s)
{
  struct Segilima *sl = (struct Segilima *)malloc(sizeof(struct Segilima));
  sl->s = s;
  return *sl;
}
  • Buat fungsi untuk menghitung luas segilima sisi2/4 x $\sqrt{25 + 10 * \sqrt{5}}$

    Membutuhkan #inlude <math.h>

float getLuasSegilima(struct Segilima sl)
{
  return pow(sl.s, 2) / 4.0 * sqrt(25 + 10 * sqrt(5));
}
  • Buat fungsi untuk menghitung keliling segilima 5 x sisi
float getKelilingSegilima(struct Segilima sl)
{
  return 5 * sl.s;
}
  • Buat fungsi megubah data segilima
float ubahSegilima(struct Segilima *sl, float s)
{
 sl->s = s;
}

struktur-data-algoritma-adt-tugas-individu's People

Contributors

rhnadi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.