Главная » 2018 » Апрель » 13 » Структура. Массив. Средний возраст
10:54
Структура. Массив. Средний возраст

#include <iostream>
using namespace std;
struct person 
{
    char surname[20];
    char name[20];
    int age;
};
void vvod(person &x);
void vivod(person &x);
void vvod_mas(person *x, int k);
void vivod_mas(person *x, int k);
double srednee_znach(person *x, int k);
int main()
{
    setlocale(LC_ALL, "Russian");  
    const int n=3;
    person people[n];
    vvod_mas(people,n);
    cout<<"------- ***Begin БД *** -------"<<endl;
    vivod_mas(people,n);
    cout<<"------- *** End  БД *** -------"<<endl;
    cout<<"Средний возраст "<<srednee_znach(people,n)<<endl;
    system("pause");
    return 0;
}
void vvod(person &x)
{
    cout<<"Введите фамилию ";cin>>x.surname;
    cout<<"Введите имя ";cin>>x.name;
    cout<<"Введите возраст ";cin>>x.age;
}
void vivod(person &x)
{
    cout<<" "<<x.surname;
    cout<<" "<<x.name;
    cout<<" "<<x.age<<endl;
}
void vvod_mas(person *x, int k)
{
    for (int i=0;i<k;i++)
    {
        cout<<"----------------------------"<<endl;
        cout<<"Введите данные "<<(i+1)<<" человека из "<<k<<endl;
        vvod(x[i]);
    }
}
void vivod_mas(person *x, int k)
{
    for (int i=0;i<k;i++)
    {
        cout<<(i+1)<<") ";
        vivod(x[i]);
    }
}
double srednee_znach(person *x, int k)
{
    double s=0;
    for (int i=0;i<k;i++)
        s=s+x[i].age;
    return s/k;
}

Просмотров: 240 | Добавил: denjes | Рейтинг: 0.0/0
Всего комментариев: 0
avatar