Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатика
ИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханика
ОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторика
СоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансы
ХимияЧерчениеЭкологияЭкономикаЭлектроника

Структуры. // structur.cpp -- a simple structure

Читайте также:
  1. I. Организационные структуры управления.
  2. IV.I. Организационные структуры управления.
  3. IV.II. Производственные структуры управления.
  4. Адхократические (гибкие структуры) управления
  5. Анализ источников формирования, структуры и динамики собственного капитала
  6. Анализ организационной структуры
  7. Анализ состояния социальной инфраструктуры

 

 

// structur.cpp -- a simple structure

#include <iostream>

struct inflatable // structure declaration

{

char name[20];

float volume;

double price;

};

int main()

{

using namespace std;

inflatable guest =

{

"Glorious Gloria", // name value

1.88, // volume value

29.99 // price value

}; // guest is a structure variable of type inflatable

// It's initialized to the indicated values

inflatable pal =

{

"Audacious Arthur",

3.12,

32.99

}; // pal is a second variable of type inflatable

// NOTE: some implementations require using

// static inflatable guest =

 

cout << "Expand your guest list with " << guest.name;

cout << " and " << pal.name << "!\n";

// pal.name is the name member of the pal variable

cout << "You can have both for $";

cout << guest.price + pal.price << "!\n";

getchar();

return 0;

}

 

 

 

 

// assgn_st.cpp -- assigning structures

#include <iostream>

struct inflatable

{

char name[20];

float volume;

double price;

};

int main()

{

using namespace std;

inflatable bouquet =

{

"sunflowers",

0.20,

12.49

};

inflatable choice;

cout << "bouquet: " << bouquet.name << " for $";

cout << bouquet.price << endl;

 

choice = bouquet; // assign one structure to another

cout << "choice: " << choice.name << " for $";

cout << choice.price << endl;

getchar();

return 0;

}

 

того же типа.

// arrstruc.cpp -- an array of structures

#include <iostream>

struct inflatable

{

char name[20];

float volume;

double price;

};

int main()

{

using namespace std;

inflatable guests[2] = // initializing an array of structs

{

{"Bambi", 0.5, 21.99}, // first structure in array

{"Godzilla", 2000, 565.99} // next structure in array

};

 

cout << "The guests " << guests[0].name << " and " << guests[1].name

<< "\nhave a combined volume of "

<< guests[0].volume + guests[1].volume << " cubic feet.\n";

getchar();

return 0;

}

 

 


Дата добавления: 2015-08-09; просмотров: 69 | Нарушение авторских прав


Читайте в этой же книге: Массивы. | Правила инициализации массивов. | Построчное чтение ввода |
<== предыдущая страница | следующая страница ==>
Введение в класс String| Указатели и свободное хранилище

mybiblioteka.su - 2015-2024 год. (0.008 сек.)