Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Агафонов И.Д. Задание 6 С #947

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions AgafonovID/Practice5/Practice5.sln

This file was deleted.

22 changes: 0 additions & 22 deletions AgafonovID/Practice5/Practice5/Practice5.vcxproj.filters

This file was deleted.

195 changes: 0 additions & 195 deletions AgafonovID/Practice5/Practice5/main.c

This file was deleted.

31 changes: 31 additions & 0 deletions AgafonovID/prac1/prac1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prac1", "prac1\prac1.vcxproj", "{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Debug|x64.ActiveCfg = Debug|x64
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Debug|x64.Build.0 = Debug|x64
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Debug|x86.ActiveCfg = Debug|Win32
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Debug|x86.Build.0 = Debug|Win32
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Release|x64.ActiveCfg = Release|x64
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Release|x64.Build.0 = Release|x64
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Release|x86.ActiveCfg = Release|Win32
{2F990793-BEDF-4C8A-BEE3-D14CC5A87E99}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3EA4EE6C-068F-4842-A633-17647EA97D27}
EndGlobalSection
EndGlobal
90 changes: 90 additions & 0 deletions AgafonovID/prac1/prac1/StoresLib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "StoresLib.h"

void alloc_lib(StoresLib* storelib, int k) {
storelib->count = k;
storelib->stores = (store*)malloc(sizeof(store) * storelib->count);
if (storelib->stores == NULL) {
printf("memory allocation error\n");
return 0;
}
}

void dealloc_stores(StoresLib* lib) {
for (int i = 0; i < lib->count; i++) {
dealloc(&(lib->stores[i]));
}
free(lib->stores);

}

void read_stores(const char* infilename, StoresLib* storelib) {
FILE* infile = fopen(infilename, "r");
if (infile == NULL) {
printf("failed to open infile\n");
return 0;
}
fscanf(infile, "%d", &(storelib->count));
storelib->stores = (store*)malloc(sizeof(store) * storelib->count);
if (storelib->stores == NULL) {
printf("memory allocation error\n");
return 0;
}
for (int i = 0; i < storelib->count; i++) {
read(infile, &(storelib->stores[i]));
}
fclose(infile);
}

void print_storelib(const char* outfilename, StoresLib* storelib) {
FILE* outfile = fopen(outfilename, "w");
if (outfile == NULL) {
printf("failed to open infile\n");
return 0;
}
for (int i = 0; i < storelib->count; i++) {
write(outfile, &(storelib->stores[i]));
}
fclose(outfile);
}

int is24(store* s) {
for (int i = 0; i < 7; i++) {
if (around_the_clock(&(s->store_worktime[i])) != 1) {
return 0;
}
}
return 1;
}

int count_24h(StoresLib* storelib) {
int count = 0;
for (int i = 0; i < storelib->count; i++) {
if (is24(&(storelib->stores[i])) == 1) {
count++;
}
}
return count;
}

void create_lib24(StoresLib* storelib, StoresLib* lib24) {
int count = count_24h(storelib);
alloc_lib(lib24, count);
int ind = 0;
for (int i = 0; i < storelib->count; i++) {
if (is24(&(storelib->stores[i])) == 1) {
alloc(&(lib24->stores[ind]));
strcpy(lib24->stores[ind].name, storelib->stores[i].name);
strcpy(lib24->stores[ind].store_address.street, storelib->stores[i].store_address.street);
lib24->stores[ind].store_address.house = storelib->stores[i].store_address.house;
strcpy(lib24->stores[ind].phone, storelib->stores[i].phone);
strcpy(lib24->stores[ind].specialization, storelib->stores[i].specialization);
strcpy(lib24->stores[ind].type, storelib->stores[i].type);
for (int j = 0; j < 7; j++) {
strcpy(lib24->stores[ind].store_worktime[j].workdays, storelib->stores[i].store_worktime[j].workdays);
lib24->stores[ind].store_worktime[j].workhours_start = storelib->stores[i].store_worktime[j].workhours_start;
lib24->stores[ind].store_worktime[j].workhours_end = storelib->stores[i].store_worktime[j].workhours_end;
}
ind++;
}
}
}
19 changes: 19 additions & 0 deletions AgafonovID/prac1/prac1/StoresLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string.h>
#include <stdlib.h>
#include "store.h"

typedef struct
{
store* stores;
int count;
} StoresLib;

void read_stores(const char* infilename, StoresLib* storelib);
void print_storelib(const char* outfilename, StoresLib* storelib);
void alloc_lib(StoresLib* storelib, int k);
void dealloc_stores(StoresLib* lib);
void create_lib24(StoresLib* storelib, StoresLib* lib24);
int count_24h(StoresLib* storelib);
int is24(store* s);
Loading