lesson 17

This commit is contained in:
Alexander Zhirov 2021-08-08 23:43:15 +03:00
parent e280a4648d
commit e6935b471d
1 changed files with 96 additions and 0 deletions

96
lesson_17/main.cpp Normal file
View File

@ -0,0 +1,96 @@
/*
* main.cpp
*
* Created on: 8 авг. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <iomanip>
using namespace std;
void floatType();
void boolType();
int main()
{
// Размер типов данных
cout << "bool:\t\t" << sizeof(bool) << " bytes" << endl;
cout << "char:\t\t" << sizeof(char) << " bytes" << endl;
cout << "wchar_t:\t" << sizeof(wchar_t) << " bytes" << endl;
cout << "char16_t:\t" << sizeof(char16_t) << " bytes" << endl;
cout << "char32_t:\t" << sizeof(char32_t) << " bytes" << endl;
cout << "short:\t\t" << sizeof(short) << " bytes" << endl;
cout << "int:\t\t" << sizeof(int) << " bytes" << endl;
cout << "long:\t\t" << sizeof(long) << " bytes" << endl;
cout << "long long:\t" << sizeof(long long) << " bytes" << endl;
cout << "float:\t\t" << sizeof(float) << " bytes" << endl;
cout << "double:\t\t" << sizeof(double) << " bytes" << endl;
cout << "long double:\t" << sizeof(long double) << " bytes" << endl;
floatType();
boolType();
return 0;
}
void floatType()
{
// Запись числа
int n(5);
double d(5.0);
float f(5.0f);
cout << "n:\t" << n << endl;
cout << "d:\t" << d << endl;
cout << "f:\t" << f << endl;
// Экспоненциальная запись чисел
{
double d1(5000.0);
double d2(5e3);
double d3(0.05);
double d4(5e-2);
cout << "d1:\t" << d1 << endl; // 5000
cout << "d2:\t" << d2 << endl; // 5000
cout << "d3:\t" << d3 << endl; // 0.05
cout << "d4:\t" << d4 << endl; // 0.05
}
// Тест
{
double d1(3.450e1);
double d2(4.000e-3);
double d3(1.23005e2);
double d4(1.46e5);
double d5(1.46000001e5);
double d6(8e-10);
double d7(3.45000e4);
cout << "d1:\t" << setprecision(4) << d1 << endl; // 34.50
cout << "d2:\t" << setprecision(4) << d2 << endl; // 0.004000
cout << "d3:\t" << setprecision(6) << d3 << endl; // 123.005
cout << "d4:\t" << setprecision(3) << d4 << endl; // 146000
cout << "d5:\t" << setprecision(9) << d5 << endl; // 146000.001
cout << "d6:\t" << setprecision(1) << d6 << endl; // 0.0000000008
cout << "d7:\t" << setprecision(6) << d7 << endl; // 34500.0
}
}
void boolType()
{
bool b1 = true; // копирующая инициализация
bool b2(false); // прямая инициализация
bool b3{true}; // uniform-инициализация (C++11)
bool b4 = false; // операция присваивания
cout << b1 << endl;
cout << b2 << endl;
cout << b3 << endl;
cout << b4 << endl;
}