Gabungan Program lengkap C++

Gabungan Program lengkap C++

Berikut adalah gabungan beberapa contoh program lengkap dengan menggunakan bahasa pemprogramman C++, salah satunya ada Penjumlahan Array 2 Dimensi, deret bilangan, Bilangan Prima dan Structures.

C++
#include <iostream>
#include<stdlib.h>
using namespace std;
struct data
{
	int id_students[5],id_lecturer [5],mid[5],final[5],ass[5],nilai[5];
	char name_students [5][30],study_program [5][30],subject[5][30],name_lecturer[5][30],grade[5];
};
data a;
void satu();
void dua();
void tiga ();
void empat ();
void lima();
void a1();
void a2();
void a3();
void a4();
main()
{
	system ("cls");
	int pilih;
	cout<<"********MENU PROGRAM**********"<<endl;
	cout<<"1. Penjumlahan Array 2 Dimensi"<<endl;
	cout<<"2. Deret"<<endl;
	cout<<"3. Bilangan Prima"<<endl;
	cout<<"4. Structures"<<endl;
	cout<<"5. Exit" <<endl <<endl;
	cout<<"Masukan Pilihan Anda [1..5] =";
	cin>>pilih;
	if(pilih==1)
	{
		satu();	
	}
	if(pilih==2)
	{
		dua();	
	}
	if(pilih==3)
	{
		tiga();	
	}
	if(pilih==4)
	{
		empat();	
	}
	if(pilih==5)
	{
		lima();	
	}
}
void satu()
{
	system ("cls");
	cout<<"==================================================="<<endl;
	cout<<" Anda memilih program Penjumlahan Array 2 Dimensi  "<<endl;
	cout<<"==================================================="<<endl;
	int r,s,t,u;
	cout<<"Matrix A"<<endl;
	cout<<"Masukan Baris: ";
	cin>>r;
	cout<<"Masukan Kolom: ";
	cin>>s;
	int matrikA[r][s];
	for(int bar=0;bar<r;bar++)
	{
		for(int kol=0;kol<s;kol++)
		{
			cout<<"A["<<bar+1<<"]["<<kol+1<<"] = ";
			cin>>matrikA [bar][kol];
		}
	}
	cout<<endl;
	for(int bar=0;bar<r;bar++)
	{
		for(int kol=0;kol<s;kol++)
		{	
			cout<<matrikA[bar][kol]<<"\t";
		}
		cout<<endl<<endl;
	}

	cout<<"Matrix B"<<endl;
	cout<<"Masukan Baris: ";
	cin>>t;
	cout<<"Masukan Kolom : ";
	cin>>u;
	int matrikB[t][u];
	for(int bar=0;bar<t;bar++)
	{
		for(int kol=0;kol<u;kol++)
		{
			cout<<"B["<<bar+1<<"]["<<kol+1<<"] = ";
			cin>>matrikB[bar][kol];
		}
	}
	cout<<endl;
	for(int bar=0;bar<t;bar++)
	{
		for(int kol=0;kol<u;kol++)
		{
			cout<<matrikB[bar][kol]<<"\t";
		}
		cout<<endl<<endl;
	}
	if(r == t,s == t)
	{
		cout<<"Hasil Jumlah MatrikA dan MatrikB"<<endl;
		int matrikC[t][u];
		for(int bar=0;bar<t;bar++)
		{
			for(int kol=0;kol<u;kol++)
			{
				matrikC[bar][kol]=matrikA[bar][kol]+matrikB[bar][kol];
			}
		}
		cout<<endl;
		for(int bar=0;bar<t;bar++)
		{
			for(int kol=0;kol<u;kol++)
			{
				cout<<matrikC[bar][kol]<<"\t";
			}
			cout<<endl<<endl;
		}
	}
	else
	{
		cout<<"matriks tidak dapat dijumlakan"<<endl<<endl;
	}
	a1();
}
void a1()
{
	char kembali ;
	cout<<"Apakah Anda ingin kembali [Y/T]";
	cin>>kembali;
	if(kembali=='y')
	{
		satu();
	}
	else if (kembali=='t')
	{
		main();
	}
}
void dua()
{
	system ("cls");
	cout<<"============================"<<endl;
	cout<<" Anda memilih program deret "<<endl;
	cout<<"============================"<<endl;
	int batas,bil,jumlah=0;
	cout<<"masukan batas bilangan = ";
	cin>>batas;
	for(int a=batas;a>=1;a--)
	{
		jumlah=jumlah+(a*2)-1;
		for(int b=1;b<=a;b++)
		{
			bil=(b*2)-1;
			cout<<bil <<" ";
			if (a>b)
			{
				cout<<"+";
			}
			else
			{
				cout<<"=";
			}	
		}	
		cout<<jumlah;
		cout<<endl;
	}
	for(int a=batas-1;a>=1;a--)
	{
		jumlah=jumlah-(((a+1)*2)-1);
		for(int b=1;b<=a;b++)
		{
			cout<<(b*2)-1<<" ";
			if (b<a)
			{
				cout<<"+";
			}
			else
			{
				cout<<"=";
			}
		}
		cout<<jumlah;
		cout<<endl;
		
	}
	a2();
}
void a2()
{
	char kembali ;
	cout<<"Apakah Anda ingin kembali [Y/T]";
	cin>>kembali;
	if(kembali=='y')
	{
		dua();
	}
	else if (kembali=='t')
	{
		main();
	}
}
void tiga()
{
	system ("cls");
	int batas,cek,b,jumlah=0;
	cout<<"====================================="<<endl;
	cout<<" Anda memilih program bilangan prima "<<endl;
	cout<<"====================================="<<endl;
	cout<<"Masukan Batas bilangan = ";
	cin>>batas;
	for (int a=2;a<=batas;a++)
	{
		cek=0;
		for(b=2;b<a;b++)
		{
			if (a%b==0)
			{
				cek=1;
			}
		}
		if (cek==0)
		{
			cout<<a<<" ";
		}
		jumlah=jumlah+a;
		cout<<"+";

	}
	cout<<"=" <<jumlah <<endl;
	a3();
}
void a3()
{
	char kembali ;
	cout<<"Apakah Anda ingin kembali [Y/T]";
	cin>>kembali;
	if(kembali=='y')
	{
		tiga();
	}
	else if (kembali=='t')
	{
		main();
	}
}
void empat()
{
	system ("cls");
	int bts;
	cout<<"==============================="<<endl;
	cout<<" Anda memilih program structers"<<endl;
	cout<<"==============================="<<endl;
	cout<<"masukan batas =";
	cin>>bts;
	cout<<endl <<endl;
	for(int d=1;d<=bts;d++)
	{
		cout<<"\tdata kampus"<<d <<endl;
		cout<<"\nID students = ";cin>>a.id_students[d];
		cout<<"Name students = ";cin>>a.name_students[d];
		cout<<"Study program = ";cin>>a.study_program[d];
		cout<<endl;
		cout<<"ID lecturer = ";cin>>a.id_lecturer[d];
		cout<<"Name lecturer = ";cin>>a.name_lecturer[d];
		cout<<"Subject = ";cin>>a.subject[d];
		cout<<endl;
		cout<<"MID Score = ";cin>>a.mid[d];
		cout<<"Final Score = ";cin>>a.final[d];
		cout<<"Assign Score = ";cin>>a.ass[d];
		a.nilai[d]=(a.mid[d]+a.final[d]+a.ass[d])/3;
		cout<<"Nilai Akhir =" <<a.nilai[d];
		{
			if(a.nilai[d]>=80)
			{
				a.grade[d]='A';
			}
			else if(a.nilai[d]>=70)
			{
				a.grade[d]='B';
			}
			else if(a.nilai[d]>=60)
			{
				a.grade[d]='C';
			}
			else if(a.nilai[d]>=50)
			{
				a.grade[d]='D';	
			}
			else
			{
				a.grade[d]='E';	
			}
			cout<<endl;
			cout<<"Grade ="<< a.grade[d];
		}
	}
	cout<<endl;
	cout<<"ID STUDENTS"<<"\t"<<"STUDENTS NAME"<<"\t"<<"SUBJECT"<<"\t"<<"ID LECTURER"<<"\t"<<"NAMA LECTURER";
	for(int d=1;d<=bts;d++)
	{
		cout<<"\t"<<"\t"<<a.id_students[d]<<"\t"<<a.name_students[d]<<"\t"<<a.subject[d]<<"\t"<<a.id_lecturer[d]<<"\t"<<a.name_lecturer[d];
		cout<<endl<<endl;
	}
	a4();
}
void a4()
{
	char kembali ;
	cout<<"Apakah Anda ingin kembali [Y/T]";
	cin>>kembali;
	if(kembali=='y')
	{
		empat();
	}
	else if (kembali=='t')
	{
		main();
	}
}
void lima()
{
	system ("cls");
	cout<<endl;
	cout<<"__________________________________________________________"<<endl;
	cout<<"      :)Terima kasih atas kunjungan di program ini:)      "<<endl;
	cout<<"__________________________________________________________"<<endl;
	cout<<endl;
	cout<<" ***********************TERIMA KASIH********************* "<<endl;
}
C++

Semoga bermanfaat