Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

Lecture 3.4 Structures




Converting numbers to AnsiStrings and vice versa

You have already used in most your projects the following functions dealing with AnsiStrings as arguments or as return values:

StrToInt

StrToFloat

IntToStr

FloatToStr

In cases when the formatted conversion of real numbers to text strings is desired, you can substitute FloatToStr for more refined function FloatToStrF. It has the following parameters:

FloatToStrF(aReal, aFormat, aPrecision, aFraction)

The parameter aReal can be a number of an arbitrary type. It will be converted to a text string using aFormat and aFraction parameters. The parameter aPrecision tells what precision (in digits after decimal point) must be used while aReal number converting.

Here is one example of FloatToStr call:

Edit1->Text=FloatToStrF(R, ffFixed, 7, 2);

Here a number contained in the variable R is converted to the text form X. YY where X is an integer part of R and YY is its fraction rounded to hundredth. The format constant ffFixed defines the X. YY…Y representation; the precision 7 means that seven digits of R’s fraction must be considered while R is rounding; and the last parameter causes rounding to hundredth. You can get more information about FloatToStrF parameters using HELP of C++-Builder.

 

Structures are aggregate data types built using elements of other types, including other structs. Consider the structure definition of:

struct Calendar //keyword = struct, identifier = Calendar (used later to declare variables of the struct type

{

int day; //structure member 1 – with a name unique for that structure, values 0-31

int month; //struct member 2 – cannot be instance of Calendar, value 0-12

int year; //0-3333

}; //each structure definition must end with;

 

Properties of structures:

-They do not reserve any space in memory,

-They are used to declare data types.

 

Declaring structures’ variables:

Calendar CalendarObject; //declares CalendarObject variable;

Calendar CalendarArray[10]; //declares Calendar Array object;

Calendar *CalendarPointer; //declares CalendarPointer to a Calendar object;

Calendar &CalendarRef; //declares &CalendarRef as a reference to a Calendar object.

 

Accessing Members of structures:

We use the member access operator – the dot operator(.), and the arrow operator (->).

The dot operator accesses a structure or a class member via the variable name for the object. For example, this prints member day of structure CalendarObject:

cout << CalendarObject.day;

The arrow operator (->) accesses a structure member or class member via a pointer to the object. For example:

CalendarPointer = &CalendarObject

(this assigns address of structure CalendarObject to CalendarPointer)

To write member day of the structure CalendarObject referenced by CalendarPointer we need to write:

cout << CalendarPointer->day;

 

Note that:

CalendarPointer->day is equivalent to (*CalendarPointer).day.

 




Поделиться с друзьями:


Дата добавления: 2014-01-11; Просмотров: 477; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.01 сек.