Saturday, January 12, 2013

INPUT / OUTPUT
 the cornerstone of the theory

Iostream library is the library/libraries that are frequently used in C++. Programs that use iostream library must include (include) files iostream. h.

Iostream library provides a number of operations to handle read and write the types of the data book. Iostream library is an object-based library that provides the functions of input and output using streams.

Stream is an abstraction that represents the media used in the operation of input and output operations. A stream is basically can be represented as a source or destination of characters with an unlimited length. Stream, can be associated with a physical device be the source or destination of the characters, such as disk, keyboard, or display monitor so that characters that are retrieved or written from/to the abstraction called stream, physically is the output/input from/to physical devices.

For example, the filestream object is a C++ object to manipulate and interact with the file. When a file stream is used to open the file, then opreasi-output/input operation on the stream is physically visible on that file. At the lowest level, a file is interpreted as a line or a stream of bytes. At this level the concept of data type does not exist. While at user-level, a file consists of a sequence of data from one or more types of characters, numeric values, and class objects.

Statement/command output/output statement is used to display the data to the output device, e.g. a monitor screen. The argument can be either a string or a variable that has been declared. The command used is cout. Output operations performed by the operator or operator leftshift insertion (<<). The syntax that is used in the output of the command is:


Cout << daftar_keluaran

 
 




Statement/command or enter/input statement is used to memasukkkan an terrentu variables into the price of input devices, such as keyboard. Printah used was cin. Input operations performed by the operator or operator rightshift extraction (>>). The syntax used to enter commands is as follows:




Sin >> daftar_masukan

 
 




III. THE EXPERIMENT
v  Output used stream : Salam
Program III.1


#include<iostream.h>
main()
{
cout<<"Assalaamualaikum.!\nSaya sedang belajar bahasa C++";
}
 
 




Results Program III.1
Program III.2


#include<iostream.h>
main()
{
cout<<"Assalaamualaikum...!"<<endl
<<"Saya sedang belajar bahasa C++";
}
 
 




Results Program III.2
1) results in Program 1 and Program III. III. 2 produces the same result in other words then the function << and function endl \n has the same functionality
2) function endl is to place the character in a new line.


3) Program to use cout to display text that is similar to the Program 1.2 On Practical i. name the Program III. 3


Program III.3


#include<iostream.h>
main()
{
cout<<"Hallo, nama saya Washilul Mustofa"<<endl
<<"Saya sedang belajar bahasa C++"<<endl
<<"Semoga bisa segera mahir"<<endl
<<"amien...";
}
 
 





Results Program III.3
v  Input string use stream : Nama
Program III.4


#include<iostream.h>
main()
{
char nama [80];

cout<<"Masukkan nama: ";
cin>> nama;
cout << "Hallo "<< nama <<endl
<<"Betul kan, namamu" << nama;
}
 
 









Hasil Program III.4
4)      4) Comparison between programs III. 4 with a similar program on practical-II Program II. 1 generate results running the same.
5)      5 Cin) replaces gets while the cout Replace printf.


v  Program input to variable number : Menghitung akar Prgram III.5
Program III.5


#include<iostream.h>
#include<math.h>
main()
{
int a;
float b;

cout << "Masukkan nilai a = ";
cin >> a;
b = sqrt (a);
cout<< "akar dari a = " << b;
}
 
 







6)      6) to generate the unit function cin while the scanf menghasilhan a fractional value.
7)      7) in rapid succession a variable into a real number, there needs to be change as follows:


int a;
float b;


 
Change                                   


float a;
float b;


 
 
to                                            


Results compile Program III.5
Results compile change variable “a”

v  Program with other input : Menghitung Rerata
Program III.6
#include<iostream.h>
#include<math.h>
main()
{
     float a, b, c, rerata;

     cout << "Masukkan nilai a, b,dan c = ";
     cin << a << b << c;
     rerata = (a+b+c)/3;
     cout << "Rerata = "<<rerata;
}
 






8)      8) error on program occurs in the function cin using operator insertion operator or liftshift (<<) should use rightshift Operator or carrier extraction (>>)
9)      9) the correct Program i.e.


cin << a << b << c;
 
Change

cin >> a >> b >> c;
 
            To



Results Program III.6 that right


v  Program combine input-output : Data diri
#include<iostream.h>

main()
{
     char Nama [50], Alamat [40], progStudi [15];
     int angkatan;

     //Mengisikan data
     cout<<"Nama     : ";
     cin>>Nama;
     cout<<"Alamat   : ";
     cin>>Alamat;
     cout<<"Program studi : ";
     cin>>progStudi;
     cout<<"Angkatan: ";
     cin>>Angkatan;

     //Menampilkan data
     cout<<"\nData anda adalah :";
     cout<<"\nNama: "<<Nama;
     cout<<"\nAlamat: "<<Alamat;
     cout<<"\nProgram Studi : "<<progStudi;
     cout<<"\nAngkatan: "<<angkatan;
}
 
the task
















Results running Program combine input-output : Data diri

















I.                   KESIMPULAN

As for the inferences that can be drawn in this lab course III, among others:
1. in carrying out the actual C++ Program is very easy and very easily, it's just that it takes patience and thoroughness when an error occurred (Error) when mengkompile data that we run,
2. the iostream Library the library is often used in C++ programs running, which provides a number of operations to handle read and write types data book,
3. Orders/cout function that outputs/output command is used to display the data to the output device, such as monitor, conducted by operators leftshift operator or insertion (<<), whereas command/function cin, input/input command is used to insert a price into a certain veriabel of input devices, such as keyboards, which are dioprasikan by the operator or operator rightshift extraction (>>).




II.                REFERENSI

ü  Modul Praktikum Dasar Pemrograman Kartika Firdausy, S.T.,M.T
ü  blog.binadarma.ac.id/yantox_ska/
ü  lecturer.eepis-its.edu/~tessy/lecturenotes/
ü  ilmukomputer.com


Author: Unknown