First Upload
This commit is contained in:
1773
14 - Struct/PointersLibs.h
Normal file
1773
14 - Struct/PointersLibs.h
Normal file
File diff suppressed because it is too large
Load Diff
120
14 - Struct/ex1.c
Normal file
120
14 - Struct/ex1.c
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "PointersLibs.h"
|
||||
|
||||
#define MAXSIZE 256
|
||||
#define MAT_SIZE 6
|
||||
|
||||
struct study_hours
|
||||
{
|
||||
string teacher;
|
||||
unsigned short subject;
|
||||
int total_students;
|
||||
};
|
||||
|
||||
unsigned int TeachesCountMaxHoursStraightInDay(struct study_hours *ptr_mat_day, unsigned short rows, unsigned short cols)
|
||||
{
|
||||
unsigned short max = ZERO;
|
||||
unsigned short counter = ONE;
|
||||
struct study_hours *ptr_temp = ptr_mat_day + cols;
|
||||
rows--;
|
||||
while (rows--)
|
||||
{
|
||||
if (!StringCompare(&((*ptr_mat_day).teacher), &((*ptr_temp).teacher)))
|
||||
{
|
||||
max = (counter > max) ? counter : max;
|
||||
counter = ZERO;
|
||||
}
|
||||
counter++;
|
||||
ptr_mat_day += cols;
|
||||
ptr_temp += cols;
|
||||
}
|
||||
|
||||
return (max);
|
||||
}
|
||||
|
||||
struct study_hours * TeachesMaxHoursStraightInDay(struct study_hours *ptr_mat_day, unsigned short rows, unsigned short cols)
|
||||
{
|
||||
unsigned short counter = ONE,
|
||||
max = ZERO;
|
||||
struct study_hours *ptr_temp = ptr_mat_day + cols;
|
||||
struct study_hours *ptr_max_teacher = ptr_mat_day;
|
||||
rows--;
|
||||
while (rows--)
|
||||
{
|
||||
if (!StringCompare(&((*ptr_mat_day).teacher), &((*ptr_temp).teacher)))
|
||||
{
|
||||
max = (counter > max) ? counter : max;
|
||||
counter = ZERO;
|
||||
}
|
||||
counter++;
|
||||
ptr_mat_day += cols;
|
||||
ptr_temp += cols;
|
||||
}
|
||||
|
||||
return (ptr_max_teacher);
|
||||
}
|
||||
|
||||
// Ex1
|
||||
struct study_hours * WhoTeachesMoreThanFourHoursStraight(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols)
|
||||
{
|
||||
unsigned short day = cols;
|
||||
while (TeachesCountMaxHoursStraightInDay(ptr_mat++, rows, cols) < FIVE && day--);
|
||||
|
||||
return (TeachesMaxHoursStraightInDay(--ptr_mat, rows, cols));
|
||||
}
|
||||
|
||||
unsigned short TeacherCountOfHoursInDay(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, string teacher)
|
||||
{
|
||||
unsigned short counter = ZERO;
|
||||
rows--;
|
||||
while (rows--)
|
||||
{
|
||||
counter += StringCompare(&((*ptr_mat).teacher), teacher);
|
||||
ptr_mat += cols;
|
||||
}
|
||||
|
||||
return (counter);
|
||||
}
|
||||
|
||||
// Ex2
|
||||
unsigned short TeacherCountOfHoursInWeek(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, string teacher)
|
||||
{
|
||||
unsigned short counter = ZERO;
|
||||
unsigned short day = cols;
|
||||
while (day--)
|
||||
{
|
||||
counter += TeacherCountOfHoursInDay(ptr_mat++, rows, cols, teacher);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
int CountStudentsInSubjectOnDay(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, unsigned short subject)
|
||||
{
|
||||
int counter = ZERO;
|
||||
rows--;
|
||||
while (rows--)
|
||||
{
|
||||
counter += ((*ptr_mat).subject == subject) ? (*ptr_mat).total_students : ZERO;
|
||||
ptr_mat += cols;
|
||||
}
|
||||
|
||||
return (counter);
|
||||
}
|
||||
|
||||
// Ex3
|
||||
int CountStudentsInSubjectOnWeek(struct study_hours *ptr_mat, unsigned short rows, unsigned short cols, unsigned short subject)
|
||||
{
|
||||
int total_students = ZERO;
|
||||
unsigned short days = cols;
|
||||
while (days--)
|
||||
{
|
||||
total_students += CountStudentsInSubjectOnDay(ptr_mat, rows, cols, subject);
|
||||
}
|
||||
|
||||
return (total_students);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
string vec_subjects[MAXSIZE];
|
||||
}
|
||||
67
14 - Struct/ex2.c
Normal file
67
14 - Struct/ex2.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "PointersLibs.h"
|
||||
#include <malloc.h>
|
||||
|
||||
#define TWO_THOUSAND 2000
|
||||
#define NINETEEN 1900
|
||||
|
||||
struct book
|
||||
{
|
||||
string name;
|
||||
string wrtier;
|
||||
string company;
|
||||
int year;
|
||||
int price;
|
||||
int id;
|
||||
};
|
||||
|
||||
void AddBook(struct book *ptr_vec, unsigned short vec_length)
|
||||
{
|
||||
struct book b;
|
||||
// I/O book
|
||||
// Check I/O book - if I/O is ok = do realloc : out from fun
|
||||
ptr_vec = realloc(ptr_vec, ++(vec_length) * sizeof(struct book));
|
||||
*(ptr_vec + (vec_length) - ONE) = b;
|
||||
}
|
||||
|
||||
struct book * SearchByName(struct book *ptr_vec, unsigned short vec_length, string *name)
|
||||
{
|
||||
while (!StringCompare((*(ptr_vec++)).name, *name) && vec_length--);
|
||||
|
||||
return (--ptr_vec);
|
||||
}
|
||||
|
||||
struct book * SearchByWriter(struct book *ptr_vec, unsigned short vec_length, string *writer)
|
||||
{
|
||||
while (!StringCompare((*(ptr_vec++)).wrtier, *writer) && vec_length--);
|
||||
|
||||
return (--ptr_vec);
|
||||
}
|
||||
|
||||
struct book * SearchByNameAndWriter(struct book *ptr_vec, unsigned short *vec_length, string *name, string *writer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
struct book * TwentyCentury(struct book *ptr_vec, unsigned short vec_length, struct book *ptr_new_vec)
|
||||
{
|
||||
ptr_new_vec = malloc(sizeof(struct book));
|
||||
unsigned int length = ONE;
|
||||
unsigned short counter;
|
||||
for (counter = ZERO; counter < vec_length; counter++)
|
||||
{
|
||||
if ((*ptr_vec).year >= 1900 && (*ptr_vec).year >= 2000)
|
||||
{
|
||||
*(ptr_new_vec + (length++)) = *ptr_vec;
|
||||
ptr_new_vec = realloc(ptr_new_vec, sizeof(struct book) * length);
|
||||
}
|
||||
ptr_vec++;
|
||||
}
|
||||
ptr_new_vec = realloc(ptr_new_vec, sizeof(struct book) * (--length));
|
||||
|
||||
return (ptr_new_vec);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user