nilai_mahasiswa

import java.io.*;

public class nilai_mahasiswa {
public static void main(String[]args)throws IOException
{
String[] nama=new String[3];
String[] nim=new String[3];
int[] uts= new int[3];
int[] uas= new int[3];
int[] tugas=new int[3];
char[] grade=new char[3];
double[] akhir=new double[3];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<3;i++){
System.out.print("nama:");nama[i]=br.readLine();
System.out.print("nim:");nim[i]=br.readLine();
System.out.print("Uts:");uts[i]=Integer.parseInt(br.readLine());
System.out.print("uas:");uas[i]=Integer.parseInt(br.readLine());
System.out.print("tugas:");tugas[i]=Integer.parseInt(br.readLine());
}
for (int a=0;a<3;a++){
akhir[a]=(uts[a]+uas[a]+tugas[a])/3;
if(akhir[a]>=85){
grade[a]='a';}
else if(akhir[a]>=75){
grade[a]='b';}
else if(akhir[a]>=50)
{grade[a]='c';}
else if(akhir[a]>=25)
{grade[a]='d';}
else {grade[a]='e';}
}
for(int i=0;i<3;i++){
System.out.println("======================================");
System.out.println("Nama :"+nama[i]);
System.out.println("NIM :"+nim[i]);
System.out.println("UTS :"+uts[i]);
System.out.println("UAS :"+uas[i]);
System.out.println("TUGAS :"+tugas[i]);
System.out.println("Nilai Akhir:"+akhir[i]);
System.out.println("Grade :"+grade[i]);
}
}
}

Konversi dari infix ke prefix dengan c++

Konversi dari infix ke prefix,,,, berikut sourcodenya...

#include <iostream.h>

#include <string.h>

#include <ctype.h>

const int MAX = 50 ;

class infix

{

private :

char target[MAX], stack[MAX] ;

char *s, *t ;

int top, l ;

public :

infix( ) ;

void setexpr ( char *str ) ;

void push ( char c ) ;

char pop( ) ;

void convert( ) ;

int priority ( char c ) ;

void show( ) ;

} ;

infix :: infix( )

{

top = -1 ;

strcpy ( target, "" ) ;

strcpy ( stack, "" ) ;

l = 0 ;

}

void infix :: setexpr ( char *str )

{

s = str ;

strrev ( s ) ;

l = strlen ( s ) ;

* ( target + l ) = '\0' ;

t = target + ( l - 1 ) ;

}

void infix :: push ( char c )

{

if ( top == MAX - 1 )

cout << "\nStack is full\n" ;

else

{

top++ ;

stack[top] = c ;

}

}

char infix :: pop( )

{

if ( top == -1 )

{

cout << "Stack is empty\n" ;

return -1 ;

}

else

{

char item = stack[top] ;

top-- ;

return item ;

}

}

void infix :: convert( )

{

char opr ;



while ( *s )

{

if ( *s == ' ' || *s == '\t' )

{

s++ ;

continue ;

}



if ( isdigit ( *s ) || isalpha ( *s ) )

{

while ( isdigit ( *s ) || isalpha ( *s ) )

{

*t = *s ;

s++ ;

t-- ;

}

}



if ( *s == ')' )

{

push ( *s ) ;

s++ ;

}



if ( *s == '*' || *s == '+' || *s == '/' ||

*s == '%' || *s == '-' || *s == '$' )

{

if ( top != -1 )

{

opr = pop( ) ;



while ( priority ( opr ) > priority ( *s ) )

{

*t = opr ;

t-- ;

opr = pop( ) ;

}

push ( opr ) ;

push ( *s ) ;

}

else

push ( *s ) ;

s++ ;

}



if ( *s == '(' )

{

opr = pop( ) ;

while ( ( opr ) != ')' )

{

*t = opr ;

t-- ;

opr = pop ( ) ;

}

s++ ;

}

}



while ( top != -1 )

{

opr = pop( ) ;

*t = opr ;

t-- ;

}

t++ ;

}

int infix :: priority ( char c )

{

if ( c == '$' )

return 3 ;

if ( c == '*' || c == '/' || c == '%' )

return 2 ;

else

{

if ( c == '+' || c == '-' )

return 1 ;

else

return 0 ;

}

}

void infix :: show( )

{

while ( *t )

{

cout << " " << *t ;

t++ ;

}

}



void main( )

{

char expr[MAX] ;

infix q ;



cout << "\nMasukan Sebuah Ekspresi infix : " ;

cin.getline ( expr, MAX ) ;



q.setexpr( expr ) ;

q.convert( ) ;



cout << "Hasil konversi kedalam notasi prefix adalah: " ;

q.show( ) ;

}

konversi dari infix ke posfix dengan c++

lagi-lagi saya tidak akan menjelaskan teori tentang ini. langsung ke program konversi dari infix ke postfix,


#include <iostream.h>

#include <string.h>

#include <ctype.h>

const int MAX = 50 ;

class infix

{

private :

char target[MAX], stack[MAX] ;

char *s, *t ;

int top ;

public :

infix( ) ;

void setexpr ( char *str ) ;

void push ( char c ) ;

char pop( ) ;

void convert( ) ;

int priority ( char c ) ;

void show( ) ;

} ;

infix :: infix( )

{

top = -1 ;

strcpy ( target, "" ) ;

strcpy ( stack, "" ) ;

t = target ;

s = "" ;

}

void infix :: setexpr ( char *str )

{

s = str ;

}

void infix :: push ( char c )

{

if ( top == MAX )

cout << "\nStack is full\n" ;

else

{

top++ ;

stack[top] = c ;

}

}

char infix :: pop( )

{

if ( top == -1 )

{

cout << "\nStack is empty\n" ;

return -1 ;

}

else

{

char item = stack[top] ;

top-- ;

return item ;

}

}

void infix :: convert( )

{

while ( *s )

{

if ( *s == ' ' || *s == '\t' )

{

s++ ;

continue ;

}

if ( isdigit ( *s ) || isalpha ( *s ) )

{

while ( isdigit ( *s ) || isalpha ( *s ) )

{

*t = *s ;

s++ ;

t++ ;

}

}

if ( *s == '(' )

{

push ( *s ) ;

s++ ;

}

char opr ;

if ( *s == '*' || *s == '+' || *s == '/' || *s == '%' || *s == '-' || *s == '$' )

{

if ( top != -1 )

{

opr = pop( ) ;

while ( priority ( opr ) >= priority ( *s ) )

{

*t = opr ;

t++ ;

opr = pop( ) ;

}

push ( opr ) ;

push ( *s ) ;

}

else

push ( *s ) ;

s++ ;

}

if ( *s == ')' )

{

opr = pop( ) ;

while ( ( opr ) != '(' )

{

*t = opr ;

t++ ;

opr = pop( ) ;

}

s++ ;

}

}

while ( top != -1 )

{

char opr = pop( ) ;

*t = opr ;

t++ ;

}

*t = '\0' ;

}

int infix :: priority ( char c )

{

if ( c == '$' )

return 3 ;

if ( c == '*' || c == '/' || c == '%' )

return 2 ;

else

{

if ( c == '+' || c == '-' )

return 1 ;

else

return 0 ;

}

}

void infix :: show( )

{

cout << target ;

}

void main( )

{

char expr[MAX] ;

infix q ;



cout << "\nMasukan Notasi Infix: " ;

cin.getline ( expr, MAX ) ;



q.setexpr ( expr ) ;

q.convert( ) ;



cout << "\nHasil Konversi Ke Dalam postfix adalah: " ;

q.show( ) ;

}

program semua sorting lengkap

ini adalah contoh sorting lengkap yang saya copy dari tetangga saya,hehehehe


#include <iostream.h>

#include <conio.h>



int data[100],data2[100];

int n;



void tukar(int a,int b)

{

int t;

t = data[b];

data[b] = data[a];

data[a] = t;

}



void bubble_sort()

{

for(int i=1;i<n;i++)

{

for(int j=n-1;j>=i;j--)

{

if(data[j]<data[j-1]) tukar(j,j-1);

}

}

cout<<"bubble sort selesai!"<<endl;

}



void exchange_sort()

{

for (int i=0; i<n-1; i++)

{

for(int j = (i+1); j<n; j++)

{

if (data [i] > data[j]) tukar(i,j);

}

}

cout<<"exchange sort selesai!"<<endl;

}



void selection_sort()

{

int pos,i,j;

for(i=0;i<n-1;i++)

{

pos = i;

for(j = i+1;j<n;j++)

{

if(data[j] < data[pos]) pos = j;

}

if(pos != i) tukar(pos,i);

}

cout<<"selection sort selesai!"<<endl;

}



void insertion_sort()

{

int temp,i,j;

for(i=1;i<n;i++)

{

temp = data[i];

j = i -1;

while(data[j]>temp && j>=0)

{

data[j+1] = data[j];

j--;

}

data[j+1] = temp;

}

cout<<"insertion sort selesai!"<<endl;

}



void QuickSort(int L, int R) //the best sort i've ever had :)

{

int i, j;

int mid;



i = L;

j = R;

mid = data[(L+R) / 2];



do

{

while (data[i] < mid) i++;

while (data[j] > mid) j--;



if (i <= j)

{

tukar(i,j);

i++;

j--;

};

} while (i < j);



if (L < j) QuickSort(L, j);

if (i < R) QuickSort(i, R);

}





void Input()

{

cout<<"Masukkan jumlah data = "; cin>>n;

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

{

cout<<"Masukkan data ke-"<<(i+1)<<" = "; cin>>data[i];

data2[i] = data[i];

}

}



void Tampil()

{

cout<<"Data : "<<endl;

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

{

cout<<data[i]<<" ";

}

cout<<endl;

}



void AcakLagi()

{

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

{

data[i] = data2[i];

}

cout<<"Data sudah teracak!"<<endl;

}



void main()

{

int pil;

clrscr();

do

{

clrscr();

cout<<"Program Sorting Komplit!!!"<<endl;

cout<<"*********************************************"<<endl;

cout<<" 1. Input Data"<<endl;

cout<<" 2. Bubble Sort"<<endl;

cout<<" 3. Exchange Sort"<<endl;

cout<<" 4. Selection Sort"<<endl;

cout<<" 5. Insertion Sort"<<endl;

cout<<" 6. Quick Sort"<<endl;

cout<<" 7. Tampilkan Data"<<endl;

cout<<" 8. Acak Data"<<endl;

cout<<" 9. Exit"<<endl;

cout<<" Pilihan Anda = "; cin>>pil;

switch(pil)

{

case 1:Input(); break;

case 2:bubble_sort(); break;

case 3:exchange_sort(); break;

case 4:selection_sort(); break;

case 5:insertion_sort(); break;

case 6:QuickSort(0,n-1);

cout<<"quick sort selesai!"<<endl;

break;

case 7:Tampil(); break;

case 8:AcakLagi(); break;

}

getch();

}while(pil!=9);

}

selection sort menggunakan subprogram

ini adalah contoh program selection sort menggunakan subprogram atau prosedur atau function yang telah saya buat
langsung copy aja gun

/*contoh sub program dengan parameter

program pengurutan data selection sort*/

#include<iostream.h>

#include<conio.h>

int n,data[20];

void input()

{

cout<<"masukan banyaknya data yang akan diurutkan:";cin>>n;

for(int i=1;i<=n;i++){

cout<<"data ke-"<<i<<":";cin>>data[i];

data[i];

}

}

void tukar(int a,int b)

{

int t;

t = data[b];

data[b] = data[a];

data[a] = t;

}



void selection_sort()

{

int pos,i,j;

for(i=1;i<=n-1;i++)

{

pos = i;

for(j = i+1;j<=n;j++)

{

if(data[j] < data[pos]) pos = j;

}

if(pos != i) tukar(pos,i);

}

}



void Tampil()

{

cout<<"Data : "<<endl;

for(int i=1;i<=n;i++)

{

cout<<data[i]<<" ";

}

cout<<endl;

}



void main()

{

input();

selection_sort();

Tampil();

}

/*program by agus Waluyo

10.01.53.0188

salam aguswaluyo27.blogspot.com*/