3.5 Konversi Hari
a. Algoritma {Membaca masukkan nilai d
lalu mencetak hasil outputnya}
b. Deklarasi
d :Integer
c. Deskripsi
read (d)
if (d==1) then write ( ‘senin’)
else if (d==2)then write (‘selasa’)
else if (d==3)then write (‘rabu’)
else if (d==4)then write (‘kamis’)
else if (d==5)then write (‘jumat’)
else if (d==6)then write(‘sabtu’)
else if (d==7)then write(‘minggu’)
else write (‘no day’)
end if
B. Flowchart
C. Bahasa C++
#include <iostream>
#include <cstdlib>
using namespace std;
class Konversi{
friend ostream& operator<<(ostream&, Konversi&);
friend istream& operator>>(istream&, Konversi&);
public:
Konversi(){};
void day(){
if (d==1){
cout << "monday" << endl; }
else if (d==2){
cout << "tuesday" << endl; }
else if (d==3){
cout << "wednesday" << endl; }
else if (d==4){
cout << "thursday" << endl; }
else if (d==5){
cout << "friday" << endl; }
else if (d==6){
cout << "saturday" << endl; }
else if (d==7){
cout << "sunday" << endl; }
else{
cout << "no day" << endl; }}
private:
int d;
};
istream& operator>>(istream& in, Konversi& input){
cout<<"Program tentang Konversi Hari"<<endl;
cout<<"Input day :";in>>input.d;
return in;
}
ostream& operator<<(ostream& out, Konversi& output){
out<<"day"<<output.d<<"is"<<output.d;
return out;
}
int main()
{ Konversi x;
cin>>x;
x.day();
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <cstdlib>
using namespace std;
class Konversi{
friend ostream& operator<<(ostream&, Konversi&);
friend istream& operator>>(istream&, Konversi&);
public:
Konversi(){};
void day(){
if (d==1){
cout << "monday" << endl; }
else if (d==2){
cout << "tuesday" << endl; }
else if (d==3){
cout << "wednesday" << endl; }
else if (d==4){
cout << "thursday" << endl; }
else if (d==5){
cout << "friday" << endl; }
else if (d==6){
cout << "saturday" << endl; }
else if (d==7){
cout << "sunday" << endl; }
else{
cout << "no day" << endl; }}
private:
int d;
};
istream& operator>>(istream& in, Konversi& input){
cout<<"Program tentang Konversi Hari"<<endl;
cout<<"Input day :";in>>input.d;
return in;
}
ostream& operator<<(ostream& out, Konversi& output){
out<<"day"<<output.d<<"is"<<output.d;
return out;
}
int main()
{ Konversi x;
cin>>x;
x.day();
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Mengerjakan Alpro sungguh-sungguh sangat menyita waktu dan tenaga saya, sumpah laah !!
hampir matakuliah lain tidak terlirik, tiap hati hanya ALPRO ALPRO DAN ALPRO. Terimakasih :*
Tidak ada komentar:
Posting Komentar