Pages

Minggu, 25 Januari 2015

Menampilkan NAMA dan NIM menggunakan array 2 dimensi (FILE.TXT)



[ sourcecode language=”css” ] { color: #000; font-size: 15px; font-weight: bold; margin: 0 0 .8125em; 1.  Menggunakan C#


using System;
using System.IO;

namespace Menampilkan_NAMA_dan_NIM_menggunakan_array_2_dimensi__FILE.TXT_
{
    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);
        }
    }
}



} [/sourcecode] OUTPUT  :




2.  Menggunakan C++

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream input;

input.open("text.txt");



cout << "                           Text File I/O " << endl;

cout << "                       Dengan Array 2 dimensi " << endl;

cout << " "  << endl;



int x;

cout << "Masukkan Jumlah Mahasiswa : ";

cin >> x;



string dataArray1 [x][1];

string dataArray2 [x][1];

for(int i=0; i<x; i++)

{

for(int j=0; j<1; j++)

{

cout << "NIM Mahasiswa ke  " << (i+1) << " = ";

cin >> dataArray1[i][j];

cout << "Nama Mahasiswa ke " << (i+1) << " = ";

cin >> dataArray2[i][j];

}

}



cout << " " << endl;

string data="";

for(int i=0; i<x; i++)

{

for(int j=0; j<1; j++)

{

cout << "NIM = "<< dataArray1[i][j]<< " # "<< "Nama = " << dataArray2[i][j]<< "\r\n";

}

}


input.close();



ofstream output;

output.open("text.txt");

for(int i=0; i<x; i++)

{

for(int j=0; j<1; j++)

{

output << "NIM = " << dataArray1[i][j]<< " # "<< "Nama = " << dataArray2[i][j]<< "\r\n";

}

cout << " " << endl;

}

    return 0;
}





3.  Menggunakan JAVA


1 komentar:

 

Blogger news

Blogroll

About