(C++) program to select a day monday-week

program to display the day that we choose the input numbers, For example input 1 it will display the day “Monday”.program switch – case. good luck,.,.

in algorithm:

switch (hari_ke) memilih nomer atau angka hari
case 1:  hari = “Senin”; break;
case 2:  hari = “Selasa”;break;
case 3:  hari = “Rabu”;  break;
case 4:  hari = “Kamis”; break;
case 5:  hari = “Jum’at”;break;
case 6:  hari = “Sabtu”; break;
default: hari = “Minggu”;break; 

write (hari_ke) “hari…”

end;

SOURCE CODE

#include <iostream.h>
#include <conio.h>
class Kalender {
friend ostream& operator<<(ostream&, Kalender&);
friend istream& operator>>(istream&, Kalender&);
public:
Kalender() {};
void adalah();
private:
int hari_ke;
char *hari;
}; 

void Kalender::adalah() {
switch (hari_ke) {
case 1:  hari = “Senin”; break;
case 2:  hari = “Selasa”;break;
case 3:  hari = “Rabu”;  break;
case 4:  hari = “Kamis”; break;
case 5:  hari = “Jum’at”;break;
case 6:  hari = “Sabtu”; break;
default: hari = “Minggu”;break;
}
}

istream& operator>>(istream& in, Kalender& masukan) {
cout << “Masukkan hari ke-“;
in >> masukan.hari_ke;
return in;
}

ostream& operator<<(ostream& out, Kalender& keluaran) {
out << “Hari ke- ” << keluaran.hari_ke  << ” adalah ”
<< keluaran.hari << endl;
return out;
}

main() {
Kalender tanggal;
cin >> tanggal;
tanggal.adalah();
cout << tanggal;
getch();
return 0;
}

TERIMA KASIH TELAH MENGUNJUNGI BLOG saya.semoga bermanfaat.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: