Not seeing a Scroll to Top Button? Go to our FAQ page for more info. [C++] Graph | -

My Imaginations

-
Follow Me

[C++] Graph



By  Galeh Fatma Eko Ardiansa     Mei 25, 2014     
Assalamu'alaikum....
Kali ini saya akan membuat sebuah program graph di C++ dimana didalamnya terdapat dua buah inputan yang mewakili suatu koordinat di graph yang nantinya akan membentuk matriks...ini dia source codenya.....

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int ordo[5][5];
void masukkan(int a, int b, int c){
for (int i = 1; i <= 4; i++){
for (int j = 1; j <= 4; j++)
if (i == a && j == b){
ordo[a][b] = ordo[i][j];
ordo[a][b] = c;
}
}
}
void tampilkan(int a, int b, int c){
for (int i = 1; i <= 4; i++){
for (int j = 1; j <= 4; j++)
cout << ordo[i][j] << " ";
cout << endl;
}
}
void inisialisasi(){
for (int i = 1; i <= 4; i++){
for (int j = 1; j <= 4; j++)
ordo[i][j] = 0;
}
}
void menu(){
cout << "-----------------MENU-----------------\n";
cout << "1. Masukkan Data\n";
cout << "2. Tampilkan\n";
cout << "0. Keluar\n";
cout << "Masukkan Pilihan Anda: ";
}
int main(){
inisialisasi();
int a, b, c;
int m;
do{
system("cls");
menu();
cin >> m;
switch (m){
case 1:
system("cls");
cout << "\nMasukkan Koordinat x : ";
cin >> a;
cout << "Masukkan Koordinat y : ";
cin >> b;
cout << "Masukkan Isi : ";
cin >> c;
if (a <= 4 && b <= 4){
masukkan(a, b, c); 
}
else{
cout << "\nIndeks harus kurang dari 4\n";
}break;
system("pause");
case 2:system("cls");
  tampilkan(a, b, c); break;
  system("pause");
}system("pause");
} while (m != 0); 
}
untuk Outputnya bisa dicoba sendiri
Oke sekian dulu, semoga bermanfaat, Wassalamu'alaikum

About Galeh Fatma Eko Ardiansa

If you can dream it, you can do it | Genius is one percent inspiration and ninety-nine percent perspiration | If you don’t make mistakes, you’re not working on hard enough problems | The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart | I can't change the direction of the wind, but I can adjust my sails to always reach my destination.

2 komentar:

  1. Kak mau nanya, hasil output akhirnya gimana. Soalnya saya udah coba tapi gak ngerti

    BalasHapus


Formulir Kontak

Nama

Email *

Pesan *

Advertisement

Disqus Shortname