Программирование на C++

Типы данных 02

Техническое задание:

Типы данных

Код программы:

//#include "stdafx.h"					//использование Visual C++
//#include <vcl.h>					//использование C++ Builder
#include <iostream>						
#include <iomanip>					//ф-ия setw()
using namespace std;
//----------------------------------------------------------------------------------------------------------
void starline();
//----------------------------------------------------------------------------------------------------------
int main()
{
	bool a0 = 0;				//1//	0 - 255
	char a1 = 'a';			//1//   0 - 255
	short int a2 = 44;			//2//	-32 768 - 32 767
	unsigned short int a3 = 10;		//2//	0 - 65 535
	int a4 = 100;				//4//	-2 147 483 648 - 2 147 483 647
	unsigned int a5 = 11;		//4//	0 - 4 294 967 295
	long int a6 = 22;			//4//	-2 147 483 648 - 2 147 483 647
	unsigned long int a7 = 10;		//4//	0 - 4 294 967 295
	float a8 = 20;			//4//	-2 147 483 648.0 - 2 147 483 647.0
	string a9 = "vasya";			//24//
	char a10[] = "xxxxx";		//6//
	double a11 = 20.2;			//8//	-9 223 272 036 854 775 808.0
						//	 9 223 272 036 854 775 807.0
 
	starline();				//вызов ф-ии табуляции
	cout << "Ishodnue dannue" << endl	//вывод заголовка
		<< " a0: " << a0 << endl	//вывод значения переменой а0
		 << " a1: " << a1 << endl
		 << " a2: " << a2 << endl
		 << " a3: " << a3 << endl
		 << " a4: " << a4 << endl
		 << " a5: " << a5 << endl
		 << " a6: " << a6 << endl
		 << " a7: " << a7 << endl
		 << " a8: " << a8 << endl
//		 << " a9: " << a9 << endl
		 << " a10: " << a10 << endl
		 << " a11: " << a11 << endl;
 
	starline();
	cout << "Razmer Tipa sizeof() " << endl
		<< setw(22) << "bool = " << sizeof(a0) << endl
		<< setw(22) << "char = " << sizeof(a1) << endl
		<< setw(22) << "short int = " << sizeof(a2) << endl
		<< setw(22) << "unsigned short int = " << sizeof(a3) << endl
		<< setw(22) << "int = " << sizeof(a4) << endl
		<< setw(22) << "unsigned int = " << sizeof(a5) << endl
		<< setw(22) << "long int = " << sizeof(a6) << endl
		<< setw(22) << "unsigned long int = " << sizeof(a7) << endl
		<< setw(22) << "float = " << sizeof(a8) << endl
		<< setw(22) << "string = " << sizeof(a9) << endl
		<< setw(22) << "char = " << sizeof(a10) << endl
		<< setw(22) << "double = " << sizeof(a10) << endl;
	starline();	
	system("pause");
	return 0;
}
//---------------------------------------------------------------------------------------------------
void starline()			//определение ф-ии табуляции
{
	for (int j = 0; j < 45; j++)
		cout << "*"; cout << endl;
}
 

Результат выполнения программы:

*********************************************
Ishodnue dannue
 a0: 0
 a1: a
 a2: 44
 a3: 10
 a4: 100
 a5: 11
 a6: 22
 a7: 10
 a8: 20
 a10: xxxxx
 a11: 20.2
*********************************************
Razmer Tipa sizeof() 
               bool = 1
               char = 1
          short int = 2
 unsigned short int = 2
                int = 4
       unsigned int = 4
           long int = 8
  unsigned long int = 8
              float = 4
             string = 24
               char = 6
             double = 6
*********************************************
sh: pause: command not found
 

Добавить комментарий