0% found this document useful (0 votes)
3 views

LAB4(PF)

The document contains a series of C++ programming tasks that demonstrate various features of input and output, including formatting, boolean values, and numerical representations. Each task includes code snippets that illustrate specific concepts such as using manipulators, setting precision, and displaying different number formats. The tasks are structured to progressively build understanding of C++ output functionalities.

Uploaded by

Ninja TitanMoxie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

LAB4(PF)

The document contains a series of C++ programming tasks that demonstrate various features of input and output, including formatting, boolean values, and numerical representations. Each task includes code snippets that illustrate specific concepts such as using manipulators, setting precision, and displaying different number formats. The tasks are structured to progressively build understanding of C++ output functionalities.

Uploaded by

Ninja TitanMoxie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

LAB 4

Task 1:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world 1" << endl;
cout << "Hello world 2\n";

system("pause");
return 0;
}

Task 2:
#include <iostream>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{

cout << "*" << -17 << "*" << endl;


cout << "*" << setw(6) << -17 << "*" << endl
<< endl;
cout << "*" << "Hi there!" << "*" << endl;
cout << "*" << setw(20) << "Hi there!" << "*" << endl;
cout << "*" << setw(3) << "Hi there!" << "*" << endl;
return 0;
}

Task 3:
#include <iostream>
using namespace std;

int main()
{

bool bt = true, bf = false;

cout << "bt: " << bt << " bf: " << bf << endl;
cout << boolalpha;
cout << "bt: " << bt << " bf: " << bf << endl;
cout << noboolalpha;
cout << "bt: " << bt << " bf: " << bf << endl;

system("pause");
return 0;
}
Task 4:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setw(9) << -3.25 << endl;
cout << internal << setw(9) << -3.25 << endl;

system("pause");
return 0;
}
Task 5:
#include <iostream>
using namespace std;
int main()
{
int pos_int = 4, neg_int = -2, zero_int = 0;
double pos_f = 3.5, neg_f = -31.2, zero_f = 0.0;
cout << "pos_int: " << pos_int << " neg_int: " << neg_int;
cout << " zero_int: " << zero_int << endl;
cout << "pos_f: " << pos_f << " neg_f: " << neg_f;
cout << " zero_f: " << zero_f << endl
<< endl;
cout << showpos;
cout << "pos_int: " << pos_int << " neg_int: " << neg_int;
cout << " zero_int: " << zero_int << endl;
cout << "pos_f: " << pos_f << " neg_f: " << neg_f;
cout << " zero_f: " << zero_f << endl
<< endl;

system("pause");
return 0;
}
Task 6:
#include <iostream>
using namespace std;
int main()
{
long int pos_value = 12345678;
long int neg_value = -87654321;
float value = 2.71828;
cout << "The decimal value 12345678 is printed out as" << endl;
cout << "decimal: " << pos_value << endl;
cout << "octal: " << oct << pos_value << endl;
cout << "hexadecimal: " << hex << pos_value << endl
<< endl;
cout << "The decimal value -87654321 is printed out as" << endl;
cout << "decimal: " << dec << neg_value << endl;
cout << "octal: " << oct << neg_value << endl;
cout << "hexadecimal: " << hex << neg_value << endl
<< endl;
cout << "The decimal value 2.71828 is printed out as" << endl;
cout << "decimal: " << dec << value << endl;
cout << "octal: " << oct << value << endl;
cout << "hexadecimal: " << hex << value << endl
<< endl;

system("pause");
return 0;
}
Task 7:
#include <iostream>
using namespace std;
int main()
{
long int value = 12345678;
cout << "The decimal value 12345678 is printed out with showbase as" << endl;
cout << showbase;
cout << "decimal: " << value << endl;
cout << "octal: " << oct << value << endl;
cout << "hexadecimal: " << hex << value << endl
<< endl;
cout << "The decimal value 12345678 is printed out without showbase as" << endl;
cout << noshowbase;
cout << "decimal: " << dec << value << endl;
cout << "octal: " << oct << value << endl;
cout << "hexadecimal: " << hex << value << endl
<< endl;

system("pause");
return 0;
}
Task 8:
#include <iostream>
using namespace std;
int main()
{
long int value = 12345678;
float value_f = 6020000000.0;
cout << "Some values without the uppercase manipulator" << endl;
cout << showbase << hex;
cout << "hexadecimal: " << value << endl;
cout << "exponential: " << value_f << endl
<< endl;
cout << uppercase;
cout << "Some values with the uppercase manipulator" << endl;
cout << "hexadecimal: " << value << endl;
cout << "exponential: " << value_f << endl
<< endl;

system("pause");
return 0;
}
Task 9:
#include <iostream>
using namespace std;
int main()
{
float small = 3.1415926535897932384626;
float large = 6.0234567e17;
float whole = 2.000000000;
cout << "Some values in general format" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << scientific;
cout << "The values in scientific format" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << fixed;
cout << "The same values in fixed format" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout.unsetf(ios::fixed | ios::scientific);
cout << "Back to general format" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
system("pause");
return 0;
}

Task 10:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float small = 3.1415926535897932384626;
float large = 6.0234567e17;
float whole = 2.000000000;
cout << "Some values in general format (default precision: 6)" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << "Some values in general format (with setprecision(4)" << endl;
cout << setprecision(4);
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << scientific;
cout << "The values in scientific format (default precision: 6)" << endl;
cout << setprecision(6);
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << "The values in scientific format with setprecision(4)" << endl;
cout << setprecision(4);
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << fixed;
cout << "The same values in fixed format (default precision: 6)" << endl;
cout << setprecision(6);
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout << "The same values in fixed format with setprecision(4)" << endl;
cout << setprecision(4);
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;
cout.unsetf(ios::fixed | ios::scientific);
cout << "Back to general format (with setprecision(4))" << endl;
cout << "small: " << small << endl;
cout << "large: " << large << endl;
cout << "whole: " << whole << endl
<< endl;

system("pause");
return 0;
}

Task 11:
#include <iostream>
using namespace std;
int main()
{
float lots = 3.1415926535;
float little1 = 2.25;
float little2 = 1.5;
float whole = 4.00000;
cout << "Some values with noshowpoint (the default)" << endl
<< endl;
cout << "lots: " << lots << endl;
cout << "little1: " << little1 << endl;
cout << "little2: " << little2 << endl;
cout << "whole: " << whole << endl;
cout << endl
<< endl;
cout << "The same values with showpoint" << endl
<< endl;
cout << showpoint;
cout << "lots: " << lots << endl;
cout << "little1: " << little1 << endl;
cout << "little2: " << little2 << endl;
cout << "whole: " << whole << endl;

system("pause");
return 0;
}

You might also like