Pages

Subscribe:

Selamat Datang

Terima Kasih telah Mengunjungi Blog saya

Minggu, 25 Januari 2015

Program Matrik

C++ :


#include 
#include 
using namespace std;

class matrix
{
public :
    int matrik [4][4];
    void hitung_matrix()
    {
        int baris, kolom;
        for (baris = 0; baris < 4; baris++)
        {
            for (kolom = 0; kolom < 4; kolom++)
            {
                cout <<"Masukkan baris ke " << baris << " dan kolom ke " << kolom << " : ";
                cin >> matrik[baris][kolom];
            }
        }
        for (baris = 0; baris < 4; baris++)
        {
            for (kolom = 0; kolom < 4; kolom++)
            {
                cout << matrik[baris][kolom] << " ";
            }
            cout<<"\n";
        }
    }
};

int main()
{
    matrix mkn;
    mkn.hitung_matrix();
    getch();
    return 0;
}


CSharp :

Menampilkan "Nama" Dengan Array 2 Dimensi (File.Txt

CSharp :


using System;
using System.IO;
namespace nama_nim_filetxt
{
    class Program
    {
        public static void tulis_file()
        {
            Console.WriteLine("             Text File I/O ");
            Console.WriteLine("        Menggunakan Array 2 Dimensi ");
            Console.WriteLine();

            Console.Write("Masukkan Jumlah Mahasiswa : ");
            int x = Convert.ToInt32(Console.ReadLine());
            string [,] dataArray1 = new string[x,1];
            string [,] dataArray2 = new string[x,1];
      
            for(int i=0; i < x ; i++)
            {
                for(int j=0; j < 1; j++)
                {
                    Console.Write("NIM Mahasiswa ke – " + (i+1).ToString() + " = ");
                    dataArray1[i,j]=Console.ReadLine();
                    Console.Write("Nama Mahasiswa ke – " + (i+1).ToString()+" = ");
                    dataArray2[i,j]=Console.ReadLine();
                }

            }
      
            string data="";
            for(int i=0 ; i < x ; i++)
            {

                for(int j=0; j < 1 ; j++)
                {
              
                    data +="NIM = " +dataArray1[i,j]+" # "+"Nama = "+dataArray2[i,j]+"\r\n";

                }

            }
                StreamWriter sw = new StreamWriter("test.txt");
                sw.WriteLine(data);
                sw.Close();
                Console.WriteLine("Sukses menuliskan data ke file test.txt");
        }

        public static void baca_file()
        {
            StreamReader sr = new StreamReader("test.txt");
            string data = sr.ReadToEnd();
            sr.Close();
            Console.WriteLine("Baca file.txt");
            Console.WriteLine(data);
      
        }
  
    public static void Main(string[] args)
    {
            tulis_file();
            baca_file();
      
      
            Console.ReadKey(true);
        }
    }
}

C++ :


Menampilkan "Nama" Dengan Array 1 Dimensi (File.Txt)

CSharp :


using System;
using System.IO;
namespace tampilan_nama_n_nim_filetxt
{
    class Program
    {
        public static void tulis_file(){

        Console.WriteLine("            Text File I/O ");
        Console.WriteLine("      Menggunakan Array 1 dimensi ");
        Console.WriteLine();

        Console.Write(" Masukkan Jumlah Mahasiswa = ");
        int jumlah = Convert.ToInt32(Console.ReadLine());

        string [] dataArray = new string[jumlah];

        for(int y=0; y < jumlah ; y++)
        {
        Console.Write(" Mahasiswa ke " +(y+1).ToString()+" = ");
        dataArray[y] = Console.ReadLine();
        }

        string data = " ";
        for(int i=0; i < jumlah ; i++)
        {
            data += dataArray[i]+" \r\n ";
        }

            Console.WriteLine();

        StreamWriter sw = new StreamWriter("test.txt");
        sw.WriteLine(data);
        sw.Close();
        Console.WriteLine(" Sukses Menuliskan Data ke File test.txt");
    }

        public static void baca_file(){
        StreamReader sr = new StreamReader("test.txt");
        string data = sr.ReadToEnd();
        sr.Close();
            Console.WriteLine(" Baca File test.txt");
            Console.WriteLine(data);
    }

        public static void Main(string[] args)
    {
        tulis_file();
        baca_file ();

            Console.ReadKey(true);
        }
    }
}

C++ :

NIM & Nama

CSharp :

 
# Main Program

using System;

namespace Csharp
{
 class Program
 {
  public static void Main(string[] args)
  {
   biodata b = new biodata();
   b.nim = "1113101088";
   b.nama = "Aris Sugiarto";
   b.tampilkan();
   
   Console.ReadKey(true);
  }
 }
}

# Method

using System;

namespace Csharp
{
 
 public class biodata
 {
  public string nim;
  public string nama;
  
  public void tampilkan()
  {
   Console.WriteLine("Nim : "+nim);
   Console.WriteLine("Nama : "+nama);
  }
 }
}