Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit7104c90385c02473bba9880b0fcd28ffbf1940bc (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-17 21:47:35 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-17 21:47:35 +0200
Files851a0e7f75b2cc097715ef74b2584e582524eb45
Introduction_to_programming_FMI-7104c90385c02473bba9880b0fcd28ffbf1940bc.tar
Introduction_to_programming_FMI-7104c90385c02473bba9880b0fcd28ffbf1940bc.tar.gz
Introduction_to_programming_FMI-7104c90385c02473bba9880b0fcd28ffbf1940bc.zip
Parent97b4d62734acf7533a96b08bcc6044eb94847931 (diff)
Add Struct tasks.
6 files changed, 152 insertions, 0 deletions
-rw-r--r--pract_SI/Pract. 10/README.md23
-rw-r--r--pract_SI/Pract. 10/task1/Student.cpp18
-rw-r--r--pract_SI/Pract. 10/task1/Student.h17
-rw-r--r--pract_SI/Pract. 10/task1/main.cppbin0 -> 3064 bytes
-rw-r--r--pract_SI/Pract. 10/task2/ListofPoints.h71
-rw-r--r--pract_SI/Pract. 10/task2/main.cpp23
diff --git a/pract_SI/Pract. 10/README.md b/pract_SI/Pract. 10/README.md
new file mode 100644
index 0000000..d76aefb
--- /dev/null
+++ b/pract_SI/Pract. 10/README.md
@@ -0,0 +1,23 @@
+## Задачи - структори.
+
+1.Даден е списък на ученици от 10 клас, съдържащ име, година на раждане,адрес, успех от I срок, успех от II срок.
+Напишете програма, която:
+- въвежда година и проверява дали в класа има ученик с такава рождена година;
+- извежда имената и адресите на всички ученици, родени преди определена година.
+- отпечатва името на ученика с най-слаб успех за първи срок;
+- отпечатва името на ученика с най-висок среден успех за годината.
+
+2.Напишете структрура ListofPoints, който да съдържа обекти от тип Point(точки в декартовата с-ма (х;у)).
+Структурата да има следните член-данни:
+- масив от точки
+- размер
+
+Структурата да има следните функционалности:
+- Да може да добавя точка - addPoint
+- Да може да се оразмерява - resize
+- Да може да се занулява - clear
+- Да може да премахва последен елемент - pop
+- Да може да отпечатва всички свои елементи - print
+
+*Mоже да добавяте член-данни и функционалности по ваше желание*
+
diff --git a/pract_SI/Pract. 10/task1/Student.cpp b/pract_SI/Pract. 10/task1/Student.cpp
new file mode 100644
index 0000000..06cf89a
--- /dev/null
+++ b/pract_SI/Pract. 10/task1/Student.cpp
@@ -0,0 +1,18 @@
+#include "pch.h"
+#include "Student.h"
+#include <iostream>
+
+float Student::calculateFinalGrade() //среден успех за годината.
+{
+ return (GradeFirstTerm + GradeSecondTerm) / 2;
+}
+
+bool Student::checkBirthdate(unsigned _year) // роден преди определена година.
+{
+ return year < _year;
+}
+
+void Student::enterData()
+{
+ std::cin >> name >> adress >> year >> GradeFirstTerm >> GradeSecondTerm;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 10/task1/Student.h b/pract_SI/Pract. 10/task1/Student.h
new file mode 100644
index 0000000..11da143
--- /dev/null
+++ b/pract_SI/Pract. 10/task1/Student.h
@@ -0,0 +1,17 @@
+#pragma once
+#include <string>
+
+struct Student
+{
+ //variable Student
+ std::string name;
+ std::string adress;
+ unsigned year;
+ float GradeFirstTerm, GradeSecondTerm;
+
+ float calculateFinalGrade(); //среден успех за годината.
+
+ bool checkBirthdate(unsigned _year); // роден преди определена година.
+
+ void enterData();
+}; \ No newline at end of file
diff --git a/pract_SI/Pract. 10/task1/main.cpp b/pract_SI/Pract. 10/task1/main.cpp
new file mode 100644
index 0000000..0fb5841
--- /dev/null
+++ b/pract_SI/Pract. 10/task1/main.cpp
Binary files differ
diff --git a/pract_SI/Pract. 10/task2/ListofPoints.h b/pract_SI/Pract. 10/task2/ListofPoints.h
new file mode 100644
index 0000000..79ab3b6
--- /dev/null
+++ b/pract_SI/Pract. 10/task2/ListofPoints.h
@@ -0,0 +1,71 @@
+#pragma once
+#include <iostream>
+struct Point
+{
+ int x;
+ int y;
+
+ void Print()
+ {
+ std::cout << x <<"; "<< y << std::endl;
+ }
+};
+
+struct ListofPoints
+{
+ const int RESIZE = 5;
+ int size=10;
+ int currentSize=0;
+ Point* arr = new Point[size];
+
+ void addPoint(const Point& point)
+ {
+ if (currentSize>=size)
+ resize();
+ arr[currentSize] = point;
+ currentSize++;
+ }
+
+ void resize()
+ {
+ int totalSize = RESIZE + size;
+ Point* arrTemp = new Point[totalSize];
+ for (size_t i = 0; i < size; i++)
+ {
+ arrTemp[i] = arr[i];
+ }
+ Free();
+ size = totalSize;
+ arr = arrTemp;
+ arrTemp = nullptr;
+ }
+
+ void clear()
+ {
+ Free();
+ currentSize = 0;
+ size = 0;
+ }
+
+ void pop()
+ {
+ int LastElement = currentSize - 1;
+ arr[LastElement].x = arr[LastElement].y = 0;
+ currentSize--;
+ }
+
+ void Free()
+ {
+ delete[] arr;
+ arr = nullptr;
+ }
+
+
+ void Print()
+ {
+ for (unsigned i = 0; i < currentSize; i++)
+ {
+ arr[i].Print();
+ }
+ }
+};
diff --git a/pract_SI/Pract. 10/task2/main.cpp b/pract_SI/Pract. 10/task2/main.cpp
new file mode 100644
index 0000000..0fcc55c
--- /dev/null
+++ b/pract_SI/Pract. 10/task2/main.cpp
@@ -0,0 +1,23 @@
+#include "ListofPoints.h"
+
+int main()
+{
+ ListofPoints list;
+ Point A;
+ Point B;
+ A.x = A.y = 9;
+ B.x = B.y = 4;
+
+ for (size_t i = 0; i < 10; i++)
+ {
+ list.addPoint(A);
+ }
+ list.addPoint(B);
+ list.Print();
+ std::cout << list.size<<std::endl;
+ list.pop();
+ list.Print();
+ list.clear();
+ std::cout << list.size;
+
+} \ No newline at end of file