You are on page 1of 4

//stringjet

#include <iostream>

using namespace std;

int main()
{
string Emeri;
Emeri="Korab";
string Mbiemri;
Mbiemri="Shpati";
string nickname= "robi";
string Emeri_i_plote=Emeri+' '+nickname+' '+Mbiemri;
cout << "\n \n Pershendetje " <<Emeri_i_plote<< endl;
return 0;
}

Preciziteti
Për të përcaktuar precizitetin e shtypjes për vlerat reale (me presje dhjetore), përdoret urdhëri për
precizitet:
cout.precision(k); // shtypja me precizitet te caktuar, me k-shifra
ose manipulatori setprecision(x); i cili ndodhet në <iomanip>.

// Programi shtypja me precizitet


#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
int i;
double x=3.1415926534;
for (i=1;i<=10;i++)
{
cout.precision(i);
cout.width(i);
cout << x << "\n";
}
//ose
cout<<"---------------------------\n";
for (i=1;i<=10;i++)
{
cout<< setprecision(i) << setw(i) << x << "\n";
}
return 0;
}
Përndryshe, në kombinim me shtypjen me precizitet mund të definohet formati për shtypjen e bazës së
vlerës në formatin fixed (fiks), scientific (shkencor) ose e papërcaktuar:
// shtypja me format dhe precizitet
#include <iostream>
using namespace std;
int main () {
double a,b,c;
a = 3.1415926534;
b = 2006.0;
c = 1.0e-10;
cout.precision(5); \\preciziteti, shifrat pas presjes dhjetore
cout << a << "\t\t" << b << "\t\t" << c << endl<<endl;
cout << fixed << a << "\t\t" << b << "\t" << c << endl<<endl;
cout << scientific << a << "\t" << b << '\t' << c << endl<<endl;
return 0;
}

/////////////////////////////////////////////////////////////////////////
Write a program in C++ to formatting the output.
T` vendosu ne bibloteken <iomanip>
setprecision(10) # jep fix precisionin
setw(5) # shkruan pas 5 pozitave
fieldLength = 15 # siguron 15 precisione
printf # per te afishuar rresht

#include <iostream>
#include <iomanip> // Needed to do formatted I/O
using namespace std;

int main()
{
cout << "\n\n Formatting the output :\n";
cout << "----------------------------\n";

double pi = 3.14159265; // this is floating point number


cout << fixed << setprecision(4); // number is set to display with
4 decimal places
cout <<" The value of pi : " << pi << endl;
cout << " The value of pi 4 decimal place of total width 8 : |"
<< setw(8) << pi << "|" << endl; // setw() sets the total width
cout << " The value of pi 4 decimal place of total width 10 : |"
<< setw(10) << pi << "|"<< endl;
cout << setfill('-'); // setfill() sets to fill the blanks with
specified character
cout << " The value of pi 4 decimal place of total width 8 : |"
<< setw(8) << pi << "|" << endl;
cout << " The value of pi 4 decimal place of total width 10 : |"
<< setw(10) << pi << "|"<< endl;

cout << scientific; // set value in scientific format with


exponent
cout <<" The value of pi in scientific format is : " << pi << endl;

bool done = false; // this is boolean variable


cout <<" Status in number : " << done << endl;
cout << boolalpha; // set output in alphabet true or false
cout <<" Status in alphabet : " << done << endl;
cout << endl;
return 0;
////////////////////////////////////////////////////////

Set decimal precision


Sets the decimal precision to be used to format floating-point values on output operations.

Behaves as if member precision were called with n as argument on the stream on which it is


inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output
streams).

This manipulator is declared in header <iomanip>.


// setprecision example
#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision

int main () {
double f =3.14159;
std::cout << std::setprecision(5) << f << '\n';
std::cout << std::setprecision(9) << f << '\n';
std::cout << std::fixed;
std::cout << std::setprecision(5) << f << '\n';
std::cout << std::setprecision(9) << f << '\n';
return 0;
}
//////////////////////////////////////////////////
Set field width
Sets the field width to be used on output operations.

Behaves as if member width were called with n as argument on the stream on which it is


inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output
streams).

This manipulator is declared in header <iomanip>.


// setw example
#include <iostream> // std::cout, std::endl
#include <iomanip> // std::setw

int main () {
std::cout << std::setw(10);
std::cout << 77 << std::endl;
return 0;
}
//////////////////////////////////////

avnirexhi-ushtrimet-c faqja 22

You might also like