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; } |
Tidak ada komentar:
Posting Komentar