Lecture 1 - Introduction To Computer and Programming Language
Lecture 1 - Introduction To Computer and Programming Language
# include <iostream>
using namespace std;
// Aturcara ini akan mencetak sahaja (Penggunaan arahan cout)
int main ( )
{
cout << “Welcome to KUTKM \n”;
cout << “ MELAKA BANDARAYA BERSEJARAH”;
return 0;
}
Buat aturcara lengkap yang boleh mencetak output berikut
Output
Welcome to KUTKM
MELAKA BANDARAYA BERSEJARAH
Welcome to
KUTKM
MELAKA
BANDARAYA BERSEJARAH
#include <iostream>
#include <iomanip>
#define P 100
using namespace std;
int main()
{
cout << "WELCOME TO KUTKM" << setfill('$') << setw(40);
cout << "MELAKA BANDARAYA BERSEJARAH\n";
cout << " " <<P <<"\n";
cout << "SELAMAT\tMAJU\tJAYA" <<endl <<endl;
return 0;
}
Output
WELCOME TO KUTKM$$$$$$$$$$$$MELAKA BANDARAYA BERSEJARAH
100
SELAMAT MAJU JAYA
Latihan
Buat satu aturcara lengkap untuk mencetak output seperti di bawah :-
SARJANA MUDA KEJURUTERAAN ELEKTRONIK
KOLEJ UNIVERSITI TEKNIKAL
******************MELAKA*******************
Manipulator ( # include <iomanip>
2. endl : Advances the cursor to the beginning of the next line. Forces any
data remaining in the archive buffer to be written to the file.
Same as \n
e.g cout << setw(10) << “567” << setw(30) << "Pearl Harbour";
5. setfill (‘?’) : This parameterized manipulator sets the stream’s fill character. The
default is a space. This setting remains in effect until the next change.
e.g cout << setfill (‘*’) << setw(5) << “567” << setw(20) << “Pearl
Harbour”
Output **567*******Pearl Harbour
Contoh penyelesaian
1 #include <iostream>
2 #include <iostream>
using namespace std;
int main()
{
cout << "SARJANA MUDA KEJURUTERAAN ELEKTRONIK\n" ;
cout << " KOLEJ UNIVERSITI TEKNIKAL";
cout << “\n\n****************MELAKA****************";
return 0;
}
3 #include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "SARJANA MUDA KEJURUTERAAN ELEKTRONIK\n";
cout << setw(30) <<"KOLEJ UNIVERSITI TEKNIKAL\n";
cout << "\n" << setfill('*') << setw(20) <<"MELAKA" << setfill('*') << setw(15) << endl;
return 0;
}
4 #include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "SARJANA MUDA KEJURUTERAAN ELEKTRIK\n";
cout << " KOLEJ UNIVERSITI TEKNIKAL\n\n";
cout << setfill('*') << setw(34) <<"MELAKA**************" << endl;
return 0;
}
Latihan
**********
**INTRO**
**********
2. Buat satu aturcara yang akan mencetak nama dan matrik anda.
Gunakan arahan yang telah dipelajari untuk menghasilkan
output yang menarik