Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Labs - val / Lab4_2

.cpp
Скачиваний:
5
Добавлен:
15.06.2014
Размер:
2.73 Кб
Скачать
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>

struct DATE
{
    int day;
    int month;
    int year;
};

struct STUDENT
{
    char first_name[256];
    char last_name[256];
    struct DATE birthday;
    STUDENT *next;
};

DATE makeBirthday (int day, int month, int year)
{
    DATE birthday;
    birthday.day = day;
    birthday.month = month;
    birthday.year = year;
    return birthday;
}

void addNewStudent (STUDENT **s, char *first_name, char *last_name, DATE birthday)
{
    STUDENT *new_s;
    new_s=(STUDENT *) malloc(sizeof(STUDENT));
    strcpy(new_s->first_name, first_name);
    strcpy(new_s->last_name, last_name);
    new_s->birthday = birthday;
    new_s->next = *s;
    *s  = new_s;
}

void YearSearch(int year, STUDENT **s)
{
    STUDENT *new_s;
    new_s = *s;
    int result = 0;
    while (new_s != NULL)
    {
        if (new_s->birthday.year == year){
            printf("%s %s \n", new_s->first_name, new_s->last_name);
            result++;
        }
        new_s = new_s->next;
    }
    if (result) printf("There were %d records found. \n", result);
    else printf("There were no records found. \n");
}

void MonthSearch(int month, STUDENT **s)
{
    STUDENT *new_s;
    new_s = *s;
    int result = 0;
    printf("Search results: \n");
    while (new_s != NULL)
    {
        if (new_s->birthday.month == month){
            printf("%s %s \n", new_s->first_name, new_s->last_name);
            result++;
        }
        new_s = new_s->next;
    }
    if (result) printf("There were %d records found. \n", result);
    else printf("There were no records found. \n");
}

void PrintAllStudents(STUDENT **s)
{
    STUDENT *new_s;
    new_s = *s;
    while (new_s != NULL)
    {
        printf("%s %s. Birthday: %d/%d/%d.\n",
            new_s->first_name,
            new_s->last_name,
            new_s->birthday.day,
            new_s->birthday.month,
            new_s->birthday.year);
        new_s = new_s->next;
    }
}

int main()
{
    STUDENT *s_0 = NULL, *new_s, *old_s;
    new_s = s_0;
    int year, month;

    addNewStudent(&new_s,"Valentin","Schitov",makeBirthday(10,2,1984));
    addNewStudent(&new_s,"Alexey","Gadalin",makeBirthday(13,5,1984));
    addNewStudent(&new_s,"Vladimir","Garvardt",makeBirthday(20,4,1983));

    printf("All students: \n");
    PrintAllStudents(&new_s);

    printf("Please input a year for search: ");
    scanf("%d",&year);
    YearSearch(year,&new_s);

    printf("Please input a month for search: ");
    scanf("%d",&month);
    MonthSearch(month,&new_s);

    getchar(); getchar();
}
Соседние файлы в папке Labs - val
  • #
    15.06.201493.46 Кб5Lab3.obj
  • #
    15.06.20142.47 Кб5Lab3.~cpp
  • #
    15.06.20141.31 Кб6Lab4.cpp
  • #
    15.06.20148.53 Кб5Lab4.obj
  • #
    15.06.20141.51 Кб6Lab4.~cpp
  • #
    15.06.20142.73 Кб5Lab4_2.cpp
  • #
    15.06.201410.4 Кб5Lab4_2.obj
  • #
    15.06.20142.73 Кб6Lab4_2.~cpp
  • #
    15.06.2014828 б5Lab5.cpp
  • #
    15.06.20146.93 Кб6Lab5.obj
  • #
    15.06.2014828 б5Lab5.~cpp