Last active
March 5, 2016 12:10
-
-
Save EugenyB/c31cd244de5db1ef0c10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <windows.h> | |
using namespace std; | |
struct date //создаем еще одну структуру, чтобы вложить ее в структуру building // дата постройки | |
{ | |
char month[4]; // Месяц постройки дома | |
int year; // Год | |
}; | |
struct building | |
{ | |
char owner[20]; | |
char city[15]; | |
int amountRooms; | |
float price; | |
date built; //вкладываем одну структуру в определение второй | |
}; | |
void show(building object) //создаем функцию, которая принимает структуру, как параметр | |
{ | |
cout << "Владелец квартиры: " << object.owner << endl; | |
cout << "Квартира находится в городе: " << object.city << endl; | |
cout << "Количество комнат: " << object.amountRooms << endl; | |
cout << "Стоимость: " << object.price << " $" << endl; | |
cout << "Дата постройки: " << object.built.month << ' ' << object.built.year << endl; | |
} | |
int main() | |
{ | |
SetConsoleOutputCP(1251); | |
SetConsoleCP(1251); | |
building apartment1; | |
strcpy(apartment1.owner,"Ivan"); | |
strcpy(apartment1.city, "Nikolaev"); | |
apartment1.amountRooms = 2; | |
apartment1.price = 2500; | |
strcpy(apartment1.built.month, "january"); | |
apartment1.built.year = 2010; | |
struct building *pApartment; //это указатель на структуру | |
pApartment = &apartment1; | |
//Обратите внимание, как нужно обращаться к элементу структуры через указатель | |
//используем оператор -> | |
cout << "Владелец квартиры: " << pApartment->owner << endl; | |
cout << "Квартира находится в городе: " << pApartment->city << endl; | |
cout << "Количество комнат: " << pApartment->amountRooms << endl; | |
cout << "Стоимость: " << pApartment->price << " $" << endl; | |
cout << "Дата постройки: " << pApartment->built.month << ' ' << pApartment->built.year << "\n\n\n"; | |
building apartment2; //создаем и заполняем второй объект структуры | |
strcpy(apartment2.owner,"Igor"); | |
strcpy(apartment2.city,"Kiev"); | |
apartment2.amountRooms = 4; | |
apartment2.price = 300000; | |
strcpy(apartment2.built.month,"march"); | |
apartment2.built.year = 2012; | |
building apartment3 = apartment2; //создаем третий объект структуры и присваиваем ему данные объекта apartment2 | |
show(apartment3); | |
cout << endl << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment