diff --git a/2021_proj_autemn.pdf b/2021_proj_autemn.pdf new file mode 100644 index 0000000..e39b0bf Binary files /dev/null and b/2021_proj_autemn.pdf differ diff --git a/Lect01/CppTutorUkr0.ppt b/Lect01/CppTutorUkr0.ppt index 78789af..57435c1 100644 Binary files a/Lect01/CppTutorUkr0.ppt and b/Lect01/CppTutorUkr0.ppt differ diff --git a/Lect01/Hello/Farenheit.c b/Lect01/Hello/Farenheit.c index b212fb6..145f983 100644 --- a/Lect01/Hello/Farenheit.c +++ b/Lect01/Hello/Farenheit.c @@ -5,9 +5,9 @@ int farenheit(){ // òî÷êà âõîäó float F, C; //âèçíà÷àºìî â³äðàçó äâ³ ä³éñí³ – çì³íí³ ‘F’ òà ‘C’ printf("F="); // âèâîäèìî ï³äêàçêó äëÿ êîðèñòóâà÷à int res = scanf("%f", &F); // ââåäåííÿ çì³ííî¿ ‘F’ - if (res==0){ + if (res==1){ C=(F-32)*5/9; /* Îá÷èñëåííÿ çà ôîðìóëîþ */ - printf("Celsius C=%e\n",C); /* âèâåäåííÿ çíà÷åííÿ çì³ííî¿ ‘C’ â íàóêîâîìó ôîðìàò³ */ + printf("Celsius C=%e\n",C); /* âèâåäåííÿ çíà÷åííÿ çì³ííî¿ ‘C’ â íàóêîâîìó ôîðìàò³ */ x=0.12e02 } return res; } diff --git a/Lect02/ByteBites.java b/Lect02/ByteBites.java new file mode 100644 index 0000000..398b1fd --- /dev/null +++ b/Lect02/ByteBites.java @@ -0,0 +1,20 @@ +// Java програма для типу byte +class ByteBites{ + public static void main(String args[]){ + byte a = 126; + // byte is 8 bit value + System.out.println(a); + a++; + System.out.println(a); + a++; + System.out.println(a); ////Відбудеться циклічний проход по інтервалу + a++; + System.out.println(a); + System.out.printf("%d \n",a); + int b = (a>>2); + int b1 = (a<<2); + int b2 = (a>>>2); + + System.out.printf("%d %d %d",b,b1,b2); + } +} diff --git a/Lect02/Calculator.java b/Lect02/Calculator.java new file mode 100644 index 0000000..4e078ed --- /dev/null +++ b/Lect02/Calculator.java @@ -0,0 +1,35 @@ + class Calculator { + public static void main(String[] args) { + char operator; + Double number1, number2, result; + + Scanner scanner = new Scanner(System.in); + System.out.print("Enter operator (either +, -, * or /): "); + operator = scanner.next().charAt(0); + System.out.print("Enter number1 and number2 respectively: "); + number1 = scanner.nextDouble(); + number2 = scanner.nextDouble(); + + switch (operator) { + case '+': + result = number1 + number2; + System.out.print(number1 + "+" + number2 + " = " + result); + break; + case '-': + result = number1 - number2; + System.out.print(number1 + "-" + number2 + " = " + result); + break; + case '*': + result = number1 * number2; + System.out.print(number1 + "*" + number2 + " = " + result); + break; + case '/': + result = number1 / number2; + System.out.print(number1 + "/" + number2 + " = " + result); + break; + default: + System.out.println("Invalid operator!"); + break; + } + } + } diff --git a/Lect02/CppTutorUkr1.ppt b/Lect02/CppTutorUkr1.ppt index 1130c44..75953b4 100644 Binary files a/Lect02/CppTutorUkr1.ppt and b/Lect02/CppTutorUkr1.ppt differ diff --git a/Lect02/InitialValues2.java b/Lect02/InitialValues2.java new file mode 100644 index 0000000..b5d7b88 --- /dev/null +++ b/Lect02/InitialValues2.java @@ -0,0 +1,69 @@ +public class InitialValuesZ { +boolean bool = true; +char ch = ‘x‘; +byte b = 47; +short 5 = Oxff; +int i = 999; +long lng = 1; +float f = 3.14f; +double d = 3.14159; +} + +// housekeeping/MethodInit.java +public class MethodInit { + int i = f(); + int f() { return 11; } +} + +// housekeeping/MethodInit2.java +public class MethodInit2 { +int i = f(); +int j = g(1); +int f() { return 11; } +int g(int n) { return n * 10; } +} + +public class MethodInit3 { +//- int j = g(i); // Illegal forward reference +int i = f(); +int f() { return 11; } +int g(int n) { return n * 10; } +} + +public class Counter { +int i; +Counter() { i = 7; } +// ... +} + + +class Window { +Window(int marker) { +System.out.println("Window(” + marker + ”)”); +} +} +class House { +Window w1 = new Window(1); // Before constructor +House() { +// Show that we’re in the constructor: +System.out.println("House()"); +w3 = new Window(33); // Reinitialize w3 +} +Window w2 = new Window(2); // After constructor +void f() { System.out.println(”f()”); } +Window w3 = new Window(3); // At end +} +public class OrderOfInitialization { +public static void main($tring[] args) { +House h = new House(); +h.f(); // Shows that construction is done +} +/* Output: +Window(1) +Window(2) +Window(3) +House() +Window(33) +f() +*/ + diff --git a/Lect02/JavaTutorUkr1.ppt b/Lect02/JavaTutorUkr1.ppt new file mode 100644 index 0000000..9e4274a Binary files /dev/null and b/Lect02/JavaTutorUkr1.ppt differ diff --git a/Lect02/JavaTutorUkr1_2.ppt b/Lect02/JavaTutorUkr1_2.ppt new file mode 100644 index 0000000..9c0578b Binary files /dev/null and b/Lect02/JavaTutorUkr1_2.ppt differ diff --git a/Lect02/L2_1_SimpleConstructor.java b/Lect02/L2_1_SimpleConstructor.java new file mode 100644 index 0000000..3452a94 --- /dev/null +++ b/Lect02/L2_1_SimpleConstructor.java @@ -0,0 +1,12 @@ +class Simple { + //no-arg constructor (конструктор по замовченню) + Simple() { // Конструктор + System.out.print("Constructor!"); + } +} +public class L2_1_SimpleConstructor { + public static void main(String[] args) { + for(int i = 0; i < 3; i++) + new Simple(); + } +} diff --git a/Lect02/L2_2NoSimpleTests.java b/Lect02/L2_2NoSimpleTests.java new file mode 100644 index 0000000..68b9d59 --- /dev/null +++ b/Lect02/L2_2NoSimpleTests.java @@ -0,0 +1,17 @@ +class NoSimpleClass { + int m; + NoSimpleClass(int i) {} + NoSimpleClass(double d) {} +} + +public class L2_2NoSimpleTests { + public static void main(String[] args) { + //- NoSimpleClass b = new NoSimpleClass(); // No default + NoSimpleClass b2 = new NoSimpleClass(1); + NoSimpleClass b3 =new NoSimpleClass(1.0); + //NoSimpleClass b4 =new NoSimpleClass(b3);// Немає копіювання + NoSimpleClass b5 =b2; // b2 те саме що b5 (b5.m == b2.m) + b5.m =2; + System.out.printf("B5.m=%d , B2.m=%d", b5.m,b2.m); + } +} diff --git a/Lect02/L2_3OrderOfInitialization.java b/Lect02/L2_3OrderOfInitialization.java new file mode 100644 index 0000000..0733e54 --- /dev/null +++ b/Lect02/L2_3OrderOfInitialization.java @@ -0,0 +1,31 @@ +class Window { + Window(int marker) { + System.out.println("Window(" + marker + ")"); + } +} +class House { + Window w1 = new Window(1); //Перед + House() { + // Конструктор: + System.out.println("House()"); + w3 = new Window(33); //Реініціалізація w3 + } + Window w2 = new Window(2); // Після + void f() { System.out.println("f()"); } + Window w3 = new Window(3); // В кінці +} + +public class L2_3OrderOfInitialization { + public static void main(String[] args) { + House h = new House(); + h.f(); // Виклик методу + } +} +/* Результат: +Window(1) +Window(2) +Window(3) +House() +Window(33) +f() +*/ diff --git a/Lect02/L2_4TerminationCondition.java b/Lect02/L2_4TerminationCondition.java new file mode 100644 index 0000000..fe1c200 --- /dev/null +++ b/Lect02/L2_4TerminationCondition.java @@ -0,0 +1,29 @@ +class Book { + boolean checkedOut = false; + Book(boolean checkOut) { + checkedOut = checkOut; + } + void checkIn() { + checkedOut = false; + } + + @Override + public void finalize() { + if(checkedOut) + System.out.println("Error: checked out"); + // або + //super.finalize(); // Call the base-class version + } +} + +public class L2_4TerminationCondition { + public static void main(String[] args) { + Book novel = new Book(true); + // Коректна очистка + novel.checkIn(); + // Створили посилання, забули прибрати: + new Book(true); + //Викликали збирач мусора: + System.gc(); + } +} diff --git a/Lect02/L2_5StaticInitialization.java b/Lect02/L2_5StaticInitialization.java new file mode 100644 index 0000000..091f06c --- /dev/null +++ b/Lect02/L2_5StaticInitialization.java @@ -0,0 +1,72 @@ +class Bowl { + Bowl(int marker) { + System.out.println("Bowl(" + marker + ")"); + } + void f1(int marker) { + System.out.println("f1(" + marker + ")"); + } +} + +class Table { + static Bowl bowll = new Bowl(1); + Table() { + System.out.println("Table()"); + bowl2.f1(1); + } + void f2(int marker) { + System.out.println("f2(" + marker + ")"); + } + + static Bowl bowl2 = new Bowl(2); +} + +class Cupboard { + Bowl bowl3 = new Bowl(3); + static Bowl bowl4 = new Bowl(4); + Cupboard() { + System.out.println("Cupboard()"); + bowl4.f1(2); + } + void f3(int marker) { + System.out.println("f3(" + marker + ")"); + } + static Bowl bowl5 = new Bowl(5); +} + +public class L2_5StaticInitialization { + + public static void main(String[] args) { + System.out.println("main creating new Cupboard()"); + new Cupboard(); + System.out.println("main creating new Cupboard()"); + new Cupboard(); + table.f2(1); + cupboard.f3(1); + } + static Table table = new Table(); // 1st Table -> Bowl1,Bowl2 + static Cupboard cupboard = new Cupboard(); +} + +/* +2_5StaticInitialization +Bowl(1) +Bowl(2) +Table() +f1(1) +Bowl(4) +Bowl(5) +Bowl(3) +Cupboard() +f1(2) +main creating new Cupboard() +Bowl(3) +Cupboard() +f1(2) +main creating new Cupboard() +Bowl(3) +Cupboard() +f1(2) +f2(1) +f3(1) + +*/ diff --git a/Lect02/L5_6ExplicitStatic.java b/Lect02/L5_6ExplicitStatic.java new file mode 100644 index 0000000..567398c --- /dev/null +++ b/Lect02/L5_6ExplicitStatic.java @@ -0,0 +1,35 @@ + + +class Cup { + Cup(int marker) { + System.out.println("Cup(" + marker + ")"); + } + void f(int marker) { + System.out.println("f(" + marker + ")"); + } +} + +class Cups { + static Cup cup1; + static Cup cup2; + static { + cup1 = new Cup(1); + cup2 = new Cup(2); + } + Cups() { + System.out.println("Cups()"); + } +} + + +public class L5_6ExplicitStatic { + static int i; + static { i = 47;} + public static void main(String[] args) { + System.out.println("Inside main()"); + Cups.cup1.f(99); // [1] + } + static Cups cups1 = new Cups(); + static Cups cups2 = new Cups(); +} + diff --git a/Lect02/Operation.java b/Lect02/Operation.java new file mode 100644 index 0000000..dd296ae --- /dev/null +++ b/Lect02/Operation.java @@ -0,0 +1,16 @@ +class Operation{   +  int data=50;   +    +  void change(int data){   +  data=data+100;//changes will be in the local variable only   + } + + public static void main(String args[]){   + +   Operation op=new Operation();   + +   System.out.println("before change "+op.data);   +   op.change(500);   +   System.out.println("after change "+op.data);   +  }   +} diff --git a/Lect02/Operation2.java b/Lect02/Operation2.java new file mode 100644 index 0000000..79d8b3e --- /dev/null +++ b/Lect02/Operation2.java @@ -0,0 +1,15 @@ +class Operation2{   +  int data=50;   +    +  void change(Operation2 op){   +  op.data=op.data+100;//changes will be in the instance variable   + }   + +  public static void main(String args[]){   +    Operation2 op=new Operation2();   +    System.out.println("before change "+op.data);   +    op.change(op);//passing object   +    System.out.println("after change "+op.data);   +  }   + +} diff --git a/Lect02/PrimitiveTypes.java b/Lect02/PrimitiveTypes.java new file mode 100644 index 0000000..83e6f2e --- /dev/null +++ b/Lect02/PrimitiveTypes.java @@ -0,0 +1,21 @@ +// Java program для роботи з примітивними типами +class PrimitiveTypes{ + public static void main(String args[]){ +char a = 'G'; // визначаємо символ +int i=89; //Цілий тип (used for numeric values )           +byte b = 4; /* можна використати byte або short якщо потрібно заощадити память +Наступне присвоєння–омилка (larger than byte range )*/ +// byte b1 = 7888888955;*/ +short s = 56; +long L1 = 0xFEED1234L; // 64-бітне число в 16-річній формі +double d = 4.355453532; // по замовченню дійсне число - тип double +float f = 4.7333434f; // для типу float вказуємо суфікс 'f' +System.out.println("char: " + a); +System.out.println("integer: " + i); +System.out.println("byte: " + b); +System.out.println("short: " + s); +System.out.println("float: " + f); +System.out.println("double: " + d); +System.out.printf("long: %d, %x" , L1, L1); +} +} diff --git a/Lect02/QuadraticEquation.java b/Lect02/QuadraticEquation.java new file mode 100644 index 0000000..237cb9b --- /dev/null +++ b/Lect02/QuadraticEquation.java @@ -0,0 +1,39 @@ +import java.util.Scanner; +import java.lang.Math; + +class QuadraticEquation{ + public static void main(String[] args){ + double a = 0.5, b = -2.7, c=3.5, d, eps=1e-8; + Scanner in = new Scanner(System.in); + a = in.nextDouble(); + b = in.nextDouble(); + c = in.nextDouble(); + + if (Math.abs(a) < eps) { + if (Math.abs(b) < eps) { + if (Math.abs(c) < eps){ // Всі коефіцієнти рівні нулю + System.out.println("Розвязок —любе число"); + } + else{ + System.out.println("Розвязків немає"); + } + } + else{ + System.out.println("xl = x2 = " +(-c / b) ) ; + } + } + else{ // Коэфіцієнти не рівні нулю + if((d=b*b - 4*a*c)< 0.0){ // Комплексні корені + d = 0.5 * Math.sqrt(-d) / a; + a = -0.5 * b/ a; + System.out.println("xl = " +a+ " +i " +d+ ",x2 = " +a+ " -i " +d); + } + else { + // Дійсні корені + d =0.5 * Math.sqrt(d) / a; + a = -0.5 * b / a; + System.out.println("x1 = " + (a + d) + ", x2 = " +(a - d)); + } + } + } +} diff --git a/Lect02/VarArgs.java b/Lect02/VarArgs.java new file mode 100644 index 0000000..9bf75ba --- /dev/null +++ b/Lect02/VarArgs.java @@ -0,0 +1,18 @@ +class A {} +public class VarArgs { +static void printArray(Object[] args) { +for(Object obj : args) +Systen.out.print(obj + ” ”); +Systen.out.println(); +} +public static void main(String[] args) { +printArray(new Object[]{47,(float) 3.14,11.11}); +printArray(new Object[]{”one", "two”, ”three” }); +printArray(new Object[]{new A(), new A(), new A()}); +} +} +/* Output: +47 3.14 11.11 +one two three +A@15db9742 A@6d06d69c A@7852e922 +*/ diff --git a/Lect02/bool.java b/Lect02/bool.java new file mode 100644 index 0000000..4f4ded9 --- /dev/null +++ b/Lect02/bool.java @@ -0,0 +1,23 @@ +import java.util.Scanner; + +class bool{ + + public static void main(String[] args){ + boolean b1,b2,b3; + boolean b4 = true, b5=(1>2); + + Scanner in = new Scanner(System.in); + b1 = in.nextBoolean(); + + if(b1){ + b2 = (1 !=2) && (3>4); + } + else{ + b2 = !b1||(3==4)&&(5>=2); + } + b3 = (b1==b2)?true:b2; + System.out.println("Bools:"+b1 +' '+ b2 + ' ' + b3); + + } + +} diff --git a/Lect02/staticInit.java b/Lect02/staticInit.java new file mode 100644 index 0000000..cb6b9b8 --- /dev/null +++ b/Lect02/staticInit.java @@ -0,0 +1,188 @@ +class Bowl { +Bowl(int marker) { +System.out.println("Bowl(” + marker + ”)”); +void f1(int marker) { +Systen.out.println("f1(" + marker + ”)”); +} +} +class Table { +static Bowl bowll = new Bowl(1); +Table() { +System.out.println("Table()"); +bowl2.f1(1); +void f2(int marker) { +System.out.println("f2(" + marker + ")")3 +} +static Bowl bowlZ = new Bowl(Z); +} + +class Cupboard { +Bowl bowl3 = new Bowl(3); +static Bowl bowl4 = new Bowl(4); +Cupboard() { +System.out.println("Cupboard()"); +bowl4.f1(2); +} +void f3(int marker) { +System.out.println("f3(" + marker + ")")§ +} +static Bowl bowlS = new Bowl(5); +} +public class StaticInitialization { +public static void main(String[] args) { +System.out.println("main creating new Cupboard()”); +new Cupboard(); +System.out.println("main creating new Cupboard()”); +new Cupboard(); +table.f2(1); +cupboard.f3(1); +} +static Table table = new Table(); +static Cupboard cupboard = new Cupboard(); +} +/* Output: +Bowl(1) +Bowl(2) +Table() +f1(1) +Bowl(4) +Bowl(5) +Bowl(3) +Cupboard() +f1(2) +main creating new Cupboard() +Bowl(3) +Cupboard() +f1(2) +main creating new Cupboard() +BowZ(3) +Cupboard() +f1(2) +f2(1) +f3(1) +*/ + + +To summarize the process of creating an object, consider a class called Dog: +1. Even though it doesn’t explicitly use the static keyword, the constructor is +actually a static method. So the first time you create an object of type Dog, or +the first time you access a static method or static field of class Dog, the Java +interpreter must locate Dog . class, which it does by searching through the +classpath. +2. As Dog . class is loaded (creating a Class object, which you’ll learn about +later), all of its static initializers are run. Thus, static initialization takes +place only once, as the Class object is loaded for the first time. +3. When you create a new Dog( ), the construction process for a Dog object first +allocates enough storage for a Dog object on the heap. +4. This storage is wiped to zero, automatically setting all the primitives in that Dog +object to their default values (zero for numbers and the equivalent for boolean +and char) and the references to null. +5. Any initializations that occur at the point of field definition are executed. +6. Constructors are executed. As you shall see in the m chapter, this might +actually involve a fair amount of activity, especially when inheritance is +involved. + + +public class Spoon { +static int i; +static { +i = 47; +} + + +class Cup { +Cup(int marker) { +System.out.println("Cup(" + marker + ")")§ +} +void f(int marker) { +System.out.println("f(" + marker + ")")$ +} +} + +class Cups { +static Cup cupl; +static Cup cup2; +static { +cupl +cup2 +new Cup(1); +new Cup(2); +} +CUPS() { +System.out.println("Cups()”); +} +} + + +public class ExplicitStatic { +public static void main($tring[] args) { +Systen.out.println("Inside main()"); +Cups.cup1.f(99); // [1] +} +// static Cups cupsl = new Cup5(); +// static Cups cup52 = new Cup5(); +// [2] +// [2] +} +/* Output: +Inside main() +Cup(1) +Cup(2) +f(99) +*/ + +/* +The instance initialization clause looks exactly like the static initialization +clause except for the missing static keyword. This syntax is necessary to +support the initialization of anonymous inner classes (see the Inner Classes +chapter), but you can also guarantee that certain operations occur regardless of +which explicit constructor is called. + +*/ + + + + + +// Instance initialization +class Mug { +Mug(int marker) { +System.out.println("Mug(" + marker + ")")§ +} +} +public class Mugs { +Mug mugl; +Mug mugZ; +{ // [1] +mugl = new Mug(1); +mugZ = new Mug(2); +System.out.println("mugl & mugZ initialized”); +} +MUQS() { +System.out.println("Mugs()”); +} +Mugs(int i) { +System.out.println("Mugs(int)”); +} +public static void main($tring[] args) { +Systen.out.println("Inside main()"); +new Mugs(); +Systen.out.println("new Mugs() completed”); +new Mugs(l); +System.out.println("new Mugs(l) completed”); +} +} +/* Output: +Inside nain() +Mug(1) +Mug(2) +nugI & nugZ initialized +Mug5() +new Mugs() completed +Mug(1) +Mug(2) +nug1 & nugZ initialized +Mugs(int) +new Mugs(l) completed +* +/ diff --git a/Lect02/tasks1_2(1).pdf b/Lect02/tasks1_2(1).pdf deleted file mode 100644 index f1539d0..0000000 Binary files a/Lect02/tasks1_2(1).pdf and /dev/null differ diff --git a/Lect03/tasks3.3.pdf b/Lect03/tasks3.3.pdf new file mode 100644 index 0000000..6f5ecba Binary files /dev/null and b/Lect03/tasks3.3.pdf differ diff --git a/Lect04/CppTutorUkr3.ppt b/Lect04/CppTutorUkr3.ppt index 538d750..ad0d936 100644 Binary files a/Lect04/CppTutorUkr3.ppt and b/Lect04/CppTutorUkr3.ppt differ diff --git a/Lect04/task11.dvi b/Lect04/task11.dvi new file mode 100644 index 0000000..dc6872a Binary files /dev/null and b/Lect04/task11.dvi differ diff --git a/Lect04/task11.pdf b/Lect04/task11.pdf new file mode 100644 index 0000000..31630d9 Binary files /dev/null and b/Lect04/task11.pdf differ diff --git a/Lect04/task4.0.pdf b/Lect04/task4.0.pdf new file mode 100644 index 0000000..31630d9 Binary files /dev/null and b/Lect04/task4.0.pdf differ diff --git a/Lect04/tasks4.pdf b/Lect04/tasks4.pdf deleted file mode 100644 index 96f3428..0000000 Binary files a/Lect04/tasks4.pdf and /dev/null differ diff --git a/Lect05/CPPTutorUkr05_upd.ppt b/Lect05/CPPTutorUkr05_upd.ppt index b51cbde..0adc728 100644 Binary files a/Lect05/CPPTutorUkr05_upd.ppt and b/Lect05/CPPTutorUkr05_upd.ppt differ diff --git a/Lect05/task4.1.pdf b/Lect05/task4.1.pdf new file mode 100644 index 0000000..f797737 Binary files /dev/null and b/Lect05/task4.1.pdf differ diff --git a/Lect05/tasks5.pdf b/Lect05/tasks5.pdf deleted file mode 100644 index d596a56..0000000 Binary files a/Lect05/tasks5.pdf and /dev/null differ diff --git a/Lect06/lect6final.pdf b/Lect06/lect6final.pdf index 1d957de..664ab14 100644 Binary files a/Lect06/lect6final.pdf and b/Lect06/lect6final.pdf differ diff --git a/Lect07/task5.pdf b/Lect07/task5.pdf new file mode 100644 index 0000000..a598fbc Binary files /dev/null and b/Lect07/task5.pdf differ diff --git a/Lect08/Code/Rational.cpp b/Lect08/Code/Rational.cpp new file mode 100644 index 0000000..9aae55c --- /dev/null +++ b/Lect08/Code/Rational.cpp @@ -0,0 +1,92 @@ +#include "Rational.h" + +void Rational::show(){ + std::cout<< nom<< "/"<>nom; + std::cout<<"Input denom:"; + std::cin>>denom; + + reduce(); + + return 0; +} + +Rational Rational::add(const Rational& x){ + int t = (int)(this->nom * x.denom + denom * x.nom); + unsigned y = x.denom * denom; + return Rational(t,y); +} + +Rational Rational::mult(const Rational& x){ + int t = nom * x.nom; + unsigned y = x.denom * denom; + return Rational(t,y); +} + +unsigned Rational::gcd(unsigned x, unsigned y){ + if(y==0||x==0) return x+y; + if(x>=y) return gcd(x%y,y); + return gcd(y%x,x); +} + +void Rational::reduce(){ + + int nsd; + if(nom>=0) + nsd = (int)gcd(nom,denom); + else + nsd = (int)gcd(-nom,denom); + + nom /= nsd; + denom /= nsd; +} + + +Rational Hregory(double eps){ + Rational s; + int sign = -1; + for(int i=2;eps*i*i<1;i++){ + Rational tmp; + tmp.setNom(sign); + sign = -sign; + tmp.setDenom(i*i); + s = s.add(tmp); + } + return s; +} + + +int main(){ + Rational r1,r2(2,3); + r1.input(); + + Rational r3 = r1.add(r2); + Rational r4 = r1.mult(r2); + r3.show(); + r4.show(); + unsigned p = Rational::gcd(60,35); + std::cout< +#include + +class Rational{ + private: + int nom; + unsigned denom; + + public: + Rational(){ + nom = 1; + denom = 1U; + } + Rational(int x, unsigned y):nom(x),denom(y){ + reduce(); + } + + void show(); + int input(); + + int setNom(int x){ + nom = x; + return 0; + } + int setDenom(unsigned y){ + if(y!=0){ + denom = y; + return 0; + } + return -1; + } + + Rational add(const Rational& x); //x.add(y); + Rational mult(const Rational& x); + + bool less(const Rational & x){ + return (nom*x.denom