Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <iostream>
- //#include <string>
- //#include <cctype>
- //
- //int main()
- //{
- // using namespace std;
- //
- // char ch;
- // while (cin.get(ch) && ch != '@')
- // {
- // if (isdigit(ch))
- // continue;
- // else if (islower(ch))
- // ch = toupper(ch);
- // else if (isupper(ch))
- // ch = tolower(ch);
- // cout << ch;
- // }
- //
- // return 0;
- //} //задача 1
- //#include <iostream>
- //#include <string>
- //#include <cctype>
- //
- //int main()
- //{
- // using namespace std;
- //
- // double arr[10];
- // int i = 0;
- // double middle = 0;
- // while (i < 10 && cin >> arr[i])
- // middle += arr[i++];
- // middle /= i;
- // cout << endl << middle << endl;
- // for (int j = 0; j < i; ++j)
- // if (arr[j] > middle)
- // cout << arr[j] << "\t";
- //
- // return 0;
- //}
- //#include <iostream>
- //
- //int main()
- //{
- // using namespace std;
- // cout << "Please enter one of the following choices: \n";
- // cout << "c) carnivore \t p) pianist\n";
- // cout << "t) tree \t g) game \n";
- //
- // char ch;
- //
- // while(!(cin >> ch) || (ch != 'c' && ch != 't' && ch != 'p' && ch != 'g'))
- // {
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // cout << "Please enter a, c, p, t or g: ";
- // }
- // switch (ch)
- // {
- // case 'c': cout << "Dinosaur" << endl; break;
- // case 't': cout << "Tree" << endl; break;
- // case 'p': cout << "Plant" << endl; break;
- // case 'g': cout << "Game" << endl; break;
- // }
- //}
- //#include <iostream>
- //
- //const int strsize = 50;
- //const int numOfLoxs = 3;
- //
- //struct bop {
- // char fullname[strsize];
- // char title[strsize];
- // char bopname[strsize];
- // int preference;
- //};
- //
- //char getChoiceForMenu();
- //void showLoxByName(bop arr[]);
- //void showLoxByTitle(bop arr[]);
- //void showLoxByBopname(bop arr[]);
- //void showLoxByPreference(bop arr[]);
- //
- //using namespace std;
- //
- //int main()
- //{
- // struct bop arr[numOfLoxs] = { {"Wimp Macho", "Junior Programmer", "WIMP", 0},
- // {"Raki Rhodes", "Trainee", "TIMP", 1}, {"Hoppy Hitman", "Senior", "SIMP", 2} };
- //
- // cout << "Benevolent Order of Programmers Report\n";
- // cout << "a. display by name b. display by title\n";
- // cout << "c. display by bopname d. display by preference\n";
- // cout << "q. quit" << endl << "Enter your choice: ";
- //
- // char choice;
- // while ((choice = getChoiceForMenu()) != 'q')
- // {
- // switch (choice)
- // {
- // case 'a': showLoxByName(arr); break;
- // case 'b': showLoxByTitle(arr); break;
- // case 'c': showLoxByBopname(arr); break;
- // case 'd': showLoxByPreference(arr); break;
- // }
- // cout << "Next choice: ";
- // }
- // cout << "Bye";
- //
- // return 0;
- //}
- //
- //char getChoiceForMenu()
- //{
- // char ch = 0;
- // while ((!(cin >> ch) || ch < 'a' || ch > 'd') && ch != 'q')
- // {
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // cout << "Enter the new letter: ";
- // }
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // return ch;
- //}
- //
- //void showLoxByName(bop arr[])
- //{
- // for (int i = 0; i < numOfLoxs; ++i)
- // cout << arr[i].fullname << endl;
- //}
- //
- //void showLoxByTitle(bop arr[])
- //{
- // for (int i = 0; i < numOfLoxs; ++i)
- // cout << arr[i].title << endl;
- //}
- //
- //void showLoxByBopname(bop arr[])
- //{
- // for (int i = 0; i < numOfLoxs; ++i)
- // cout << arr[i].bopname << endl;
- //}
- //
- //void showLoxByPreference(bop arr[])
- //{
- // for (int i = 0; i < numOfLoxs; ++i)
- // {
- // if (arr[i].preference == 0)
- // cout << arr[i].fullname << endl;
- // else if (arr[i].preference == 1)
- // cout << arr[i].title << endl;
- // else if (arr[i].preference == 2)
- // cout << arr[i].bopname << endl;
- // }
- //}
- //
- //#include <iostream>
- //
- //using namespace std;
- //
- //int main()
- //{
- // const int sumForTax4 = 35000;
- // const int sumForTax3 = 20000;
- // const int sumForTax2 = 10000;
- // const int sumForTax1 = 5000;
- // const float tax1 = 0;
- // const float tax2 = 0.10;
- // const float tax3 = 0.15;
- // const float tax4 = 0.20;
- //
- // int salary = 0;
- // double taxes = 0;
- // while (cin >> salary && salary > 0)
- // {
- // if (salary >= sumForTax4)
- // taxes = sumForTax1 * tax1 + sumForTax2 * tax2 + sumForTax3 * tax3 + (salary - sumForTax4) * tax4;
- // else if (salary >= sumForTax2 + sumForTax1)
- // taxes = sumForTax1 * tax1 + sumForTax2 * tax2 + (salary - sumForTax2 - sumForTax1) * tax3;
- // else if (salary >= sumForTax1)
- // taxes = sumForTax1 * tax1 + (salary - sumForTax1) * tax2;
- // else
- // taxes = salary * tax1;
- // cout << "Taxes = " << taxes << endl;
- // cout << "Enter new salary = ";
- // }
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //
- //using namespace std;
- //
- //const int bigDonate = 10000;
- //
- //struct patron
- //{
- // string name;
- // float donation;
- //};
- //
- //int main()
- //{
- // int numOfDonators = 0;
- // cout << "Enter the number of donators: ";
- // cin >> numOfDonators;
- //
- // patron* donatorsArray = new patron[numOfDonators];
- //
- // for (int i = 0; i < numOfDonators; ++i)
- // {
- // cout << "Enter info about #" << i << " donator\n";
- // cout << "Enter name: ";
- // cin >> donatorsArray[i].name;
- // cout << "Enter donate sum: ";
- // cin >> donatorsArray[i].donation;
- // cout << endl;
- // }
- // int count = 0;
- // cout << "\t\tGrand Patrons\n";
- // for (int i = 0; i < numOfDonators; ++i)
- // {
- // if (donatorsArray[i].donation > bigDonate)
- // {
- // cout << donatorsArray[i].name << endl;
- // count++;
- // }
- // }
- // if (count == 0)
- // cout << "None\n";
- // count = 0;
- // cout << "\t\tPatrons\n";
- // for (int i = 0; i < numOfDonators; ++i)
- // {
- // if (donatorsArray[i].donation < bigDonate)
- // {
- // cout << donatorsArray[i].name << endl;
- // count++;
- // }
- // }
- // if (count == 0)
- // cout << "None\n";
- //
- // delete[] donatorsArray;
- // donatorsArray = 0;
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //#include <cctype>
- //
- //int main()
- //{
- // using namespace std;
- // string str{};
- // int vowel = 0, consonants = 0, other = 0;
- //
- // while (cin >> str && str != "q")
- // {
- // if (tolower(str[0]) == 'a' || tolower(str[0]) == 'e' || tolower(str[0]) == 'o' || tolower(str[0]) == 'y'
- // || tolower(str[0]) == 'u' || tolower(str[0]) == 'i')
- // ++vowel;
- // else if (isalpha(str[0]))
- // ++consonants;
- // else
- // ++other;
- // }
- //
- // cout << "Vowel = " << vowel << endl;
- // cout << "Consonants = " << consonants << endl;
- // cout << "Other = " << other << endl;
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //
- //int main()
- //{
- // using namespace std;
- // ifstream in;
- // in.open("in.txt");
- // if (!in.is_open())
- // exit(EXIT_FAILURE);
- // int count = 0;
- // while (in.get() && in.good())
- // ++count;
- // cout << count;
- // in.close();
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //
- //using namespace std;
- //
- //const int maxSize = 256;
- //
- //struct donator
- //{
- // string name;
- // float donation;
- //};
- //
- //int main()
- //{
- // ifstream in;
- // in.open("in.txt");
- // if (!in.is_open())
- // exit(EXIT_FAILURE);
- // int numOfDonators = 0;
- // in >> numOfDonators;
- //
- // donator* arr = new donator[numOfDonators];
- // for (int i = 0; i < numOfDonators; ++i)
- // {
- // in >> arr[i].name;
- // in >> arr[i].donation;
- // }
- //
- // for (int i = 0; i < numOfDonators; ++i)
- // cout << arr[i].name << " = " << arr[i].donation;
- //
- // delete[] arr;
- //
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //float harmony(int a, int b)
- //{
- // return 2.0 * a * b / (a + b);
- //}
- //
- //int main()
- //{
- // int a, b;
- // while (cin >> a >> b && a != 0 && b != 0)
- // cout << "Harmony of " << a << " and " << b << " = " << harmony(a, b);
- //
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //const int maxSize = 10;
- //
- //int getResults(int result[])
- //{
- // int i = 0;
- // while (i < maxSize && cin >> result[i] && result[i] > 0)
- // ++i;
- // return i;
- //}
- //
- //void showResults(int res[], int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << res[i];
- //}
- //
- //float calcMiddle(int res[], int size)
- //{
- // float middle = 0;
- // for (int i = 0; i < size; ++i)
- // middle += res[i];
- // return middle / size;
- //}
- //
- //int main()
- //{
- // int result[maxSize];
- // int numOfRes = getResults(result);
- // showResults(result, numOfRes);
- // float middle = calcMiddle(result, numOfRes);
- // cout << endl << middle;
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //const int numOfBoxes = 4;
- //
- //struct box
- //{
- // char maker[40];
- // float height;
- // float width;
- // float length;
- // float volume;
- //};
- //
- //void showBoxes(const box boxArr[])
- //{
- // for (int i = 0; i < numOfBoxes; ++i)
- // cout << "Box #" << i << "\t" << boxArr[i].height << "\t" << boxArr[i].width << "\t" <<
- // boxArr[i].length << "\t" << boxArr[i].volume << "\t" << boxArr[i].maker << endl;
- //}
- //
- //void changeBox(box boxArr[])
- //{
- // boxArr[0].height = boxArr[1].height + boxArr[2].height + boxArr[3].height;
- // boxArr[0].width = boxArr[1].width + boxArr[2].width + boxArr[3].width;
- // boxArr[0].length = boxArr[1].length + boxArr[2].length + boxArr[3].length;
- // boxArr[0].volume = boxArr[1].volume + boxArr[2].volume+ boxArr[3].volume;
- //}
- //
- //int main()
- //{
- // box boxArr[numOfBoxes]{ {"SIMP", 1, 1, 1, 1}, {"DIMP", 2, 2, 2, 2}, {"VIMP", 3, 3, 3, 3}, {"LIMP", 4, 4, 4, 4} };
- // showBoxes(boxArr);
- // changeBox(boxArr);
- // showBoxes(boxArr);
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //unsigned long long f(int n)
- //{
- // unsigned long long q;
- // if (n == 1)
- // q = 1;
- // else
- // q = n * f(n - 1);
- // return q;
- //}
- //
- //int main()
- //{
- // unsigned long long n;
- // cin >> n;
- // cout << f(n);
- // return 0;
- //}
- //
- //#include <iostream>
- //
- //using namespace std;
- //
- //void fillArray(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // cout << "Enter #" << i + 1 << ": ";
- // cin >> arr[i];
- // }
- //}
- //
- //void showArray(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << arr[i];
- // cout << endl;
- //}
- //
- //void reverseArray(int* arr, int size)
- //{
- // int temp = 0;
- // for (int i = 0; i < size / 2; ++i)
- // {
- // temp = arr[i];
- // arr[i] = arr[size - i - 1];
- // arr[size - i - 1] = temp;
- // }
- //}
- //
- //int main()
- //{
- // int numOfElem = 0;
- // cout << "Enter the num of elements: ";
- // cin >> numOfElem;
- // int* arr = new int[numOfElem];
- // fillArray(arr, numOfElem);
- // showArray(arr, numOfElem);
- // reverseArray(arr, numOfElem);
- // showArray(arr, numOfElem);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //const int SLEN = 30;
- //struct student
- //{
- // char fullname[SLEN];
- // char hobby[SLEN];
- // int ooplevel;
- //};
- //
- //int getinfo(student pa[], int n)
- //{
- // int i;
- // for (i = 0; i < n; ++i)
- // {
- // cout << "Enter full name: ";
- // cin.getline(pa[i].fullname, SLEN, '\n');
- // if (!strcmp(pa[i].fullname, ""))
- // break;
- // cout << "Enter hobby: ";
- // cin.getline(pa[i].hobby, SLEN, '\n');
- // cout << "Enter ooplevel: ";
- // cin >> pa[i].ooplevel;
- // while (cin.get() != '\n')
- // continue;
- // }
- // return i;
- //}
- //
- //void display1(student st)
- //{
- // cout << "Name: " << st.fullname << "\t";
- // cout << "Hobby: " << st.hobby << "\t";
- // cout << "Ooplevel: " << st.ooplevel << endl;
- //}
- //
- //void display2(const student* ps)
- //{
- // cout << "Name: " << ps->fullname << "\t";
- // cout << "Hobby: " << ps->hobby << "\t";
- // cout << "Ooplevel: " << ps->ooplevel << endl;
- //}
- //
- //void display3(const student pa[], int n)
- //{
- // for (int i = 0; i < n; ++i)
- // {
- // cout << "Name: " << pa[i].fullname << "\t";
- // cout << "Hobby: " << pa[i].hobby << "\t";
- // cout << "Ooplevel: " << pa[i].ooplevel << endl;
- // }
- //}
- //
- //int main()
- //{
- // cout << "Enter class size: ";
- // int class_size;
- // cin >> class_size;
- // while (cin.get() != '\n')
- // continue;
- // student* ptr_stu = new student[class_size];
- // int entered = getinfo(ptr_stu, class_size);
- // for (int i = 0; i < entered; ++i)
- // {
- // display1(ptr_stu[i]);
- // display2(&ptr_stu[i]);
- // }
- // display3(ptr_stu, entered);
- // delete[]ptr_stu;
- // cout << "Done\n";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //const int Max = 5;
- //double * fill_array(double ar[], int limit);
- //void show_array(const double ar[], double *end );
- //void revalue(double r, double ar[], double *end);
- //int main()
- //{
- // double properties[Max];
- // double * end = fill_array(properties, Max);
- // show_array(properties, end);
- // if (end != 0)
- // {
- // cout << "Enter revaluation factor: ";
- // double factor;
- // while (!(cin >> factor))
- // {
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // cout << "Bad input; Please enter a number: ";
- // }
- // revalue(factor, properties, end);
- // show_array(properties, end);
- // }
- // cout << "Done.\n";
- // cin.get();
- // return 0;
- //}
- //
- //double * fill_array(double ar[], int limit)
- //{
- // double temp;
- // int i = 0;
- // for (i = 0; i < limit; ++i)
- // {
- // cout << "Enter value #" << (i + 1) << ": ";
- // cin >> temp;
- // if (!cin)
- // {
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // cout << "Bad input; input process terminated. \n";
- // break;
- // }
- // else if (temp < 0)
- // break;
- // ar[i] = temp;
- // }
- // return ar + i;
- //}
- //
- //void show_array(const double ar[], double *end)
- //{
- // int i = 0;
- // for (; ar != end; ++ar, ++i)
- // {
- // cout << "Property #" << (i + 1) << ": $";
- // cout << *ar << endl;
- // }
- //}
- //
- //void revalue(double r, double ar[], double *end)
- //{
- // for (; ar != end; ++ar)
- // (*ar) *= r;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //double calculate(double x, double y, double (*f)(double m, double n))
- //{
- // return f(x, y);
- //}
- //
- //double add(double x, double y)
- //{
- // return x + y;
- //}
- //
- //double substract(double x, double y)
- //{
- // return x - y;
- //}
- //
- //double divide(double x, double y)
- //{
- // if (y == 0)
- // return 0;
- // return x / y;
- //}
- //
- //double multiplicate(double x, double y)
- //{
- // return x * y;
- //}
- //
- //int main()
- //{
- // double (*pf[4])(double x, double y) { add, substract, divide, multiplicate };
- // char choice;
- // double x, y;
- // cout << "Choose operation: \n";
- // cout << "a. add; b. substract; c. divide; d. multiplicate;\nYour choice: ";
- // while (cin >> choice && choice >= 'a' && choice <= 'd')
- // {
- // cout << "Enter two numbers: ";
- // cin >> x >> y;
- // cout << "Result = ";
- // switch (choice)
- // {
- // case 'a': cout << calculate(x, y, pf[0]); break;
- // case 'b': cout << calculate(x, y, pf[1]); break;
- // case 'c': cout << calculate(x, y, pf[2]); break;
- // case 'd': cout << calculate(x, y, pf[3]); break;
- // }
- // cout << "\nChoose another operatior or press 'q' to quit: ";
- // }
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //void showStr(const char* str)
- //{
- // cout << str << endl;
- //}
- //
- //void showStr(const char* str, int &n)
- //{
- // for (int i = 0; i < n; ++i)
- // cout << str << "\t";
- // cout << endl;
- // ++n;
- //}
- //int main()
- //{
- // const char* str = "Millenium";
- // int n = 1;
- // showStr(str);
- // showStr(str);
- // showStr(str, n);
- // showStr(str, n);
- // showStr(str, n);
- // showStr(str);
- // showStr(str, n);
- // showStr(str, n);
- // showStr(str, n);
- // showStr(str);
- // return 0;
- //}
- //#include <iostream>
- //
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //using namespace std;
- //
- //const int maxSize = 64;
- //
- //struct CandyBar
- //{
- // char name[maxSize];
- // double weigth;
- // int calories;
- //};
- //
- //void setCandyBar(CandyBar& bar, const char* str = "Millennium Munch", double we = 2.85, int ca = 350);
- //
- //void showCandyBar(const CandyBar& bar)
- //{
- // cout << endl;
- // cout << "Name: " << bar.name << "\t";
- // cout << "Weigth: " << bar.weigth << "\t";
- // cout << "Calories: " << bar.calories << "\t";
- //}
- //
- //int main()
- //{
- // CandyBar X, Y;
- // setCandyBar(X, "Roshen", 3.00, 400);
- // showCandyBar(X);
- // setCandyBar(X);
- // showCandyBar(X);
- // return 0;
- //}
- //
- //void setCandyBar(CandyBar& bar, const char* str, double we, int ca)
- //{
- // strncpy(bar.name, str, maxSize);
- // bar.weigth = we;
- // bar.calories = ca;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //void showString(const string& str)
- //{
- // cout << str << endl;
- //}
- //
- //void changeStr(string& str)
- //{
- // int i = 0;
- // while (str[i] != '\0')
- // {
- // if (islower(str[i]))
- // str[i] = toupper(str[i]);
- // ++i;
- // }
- // showString(str);
- //}
- //
- //int main()
- //{
- // string userStr;
- // cout << "Enter a string (q to quit): ";
- // cin >> userStr;
- // while (userStr != "q")
- // {
- // changeStr(userStr);
- // cout << "Next string (q to quit): ";
- // cin >> userStr;
- // }
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //#include <cstring>
- //
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //struct stringy
- //{
- // char* str;
- // int ct;
- //};
- //
- //void set(stringy& beany, const char* testing);
- //void show(const stringy& beany, int n = 1);
- //void show(const char* str, int n = 1);
- //
- //int main()
- //{
- // stringy beany;
- // char testing[] = "Reality ins't what it used to be.";
- // set(beany, testing);
- // show(beany);
- // cout << endl;
- // show(beany, 2);
- // testing[0] = 'D';
- // testing[1] = 'u';
- // show(testing);
- // cout << endl;
- // show(testing, 3);
- // show("Done!");
- // return 0;
- //}
- //
- //void set(stringy& beany, const char* testing)
- //{
- // beany.ct = strlen(testing);
- // beany.str = new char[beany.ct + 1];
- // strncpy(beany.str, testing, beany.ct + 1);
- //}
- //
- //void show(const stringy& beany, int n)
- //{
- // for (int i = 0; i < n; ++i)
- // cout << beany.str << endl;
- //}
- //
- //void show(const char* str, int n)
- //{
- // for (int i = 0; i < n; ++i)
- // cout << str << endl;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //const int numOfElem = 5;
- //
- //template <typename T>
- //T max5(T arr[])
- //{
- // T max = arr[0];
- // for (int i = 0; i < numOfElem; ++i)
- // if (max < arr[i])
- // max = arr[i];
- // return max;
- //}
- //
- //int main()
- //{
- // int arr1[numOfElem]{ 4, 3, 5, 1, 2 };
- // double arr2[numOfElem]{ 2.5, 5.2, 6.1, 6.04, 0.2 };
- // cout << max5(arr1) << endl;
- // cout << max5(arr2) << endl;
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //template <typename T>
- //T maxn(const T arr[], int n)
- //{
- // T max = arr[0];
- // for (int i = 0; i < n; ++i)
- // if (max < arr[i])
- // max = arr[i];
- // return max;
- //}
- //
- //template <> string maxn<string>(const string arr[], int n)
- //{
- // size_t max = arr[0].size();
- // int index = 0;
- // for (int i = 0; i < n; ++i)
- // if (max < arr[i].size())
- // {
- // max = arr[i].size();
- // index = i;
- // }
- // return arr[index];
- //}
- //
- //int main()
- //{
- // const int arr1[6]{ 4, 3, 1, 6, 3, 2 };
- // const double arr2[4]{ 2.3, 4.2, 1.5, 0.3 };
- // const string arr3[5]{ "Aba", "a", "Qwerty", "Alla", "q" };
- //
- // cout << maxn(arr1, 6) << endl;
- // cout << maxn(arr2, 4) << endl;
- // cout << maxn(arr3, 5) << endl;
- //
- // return 0;
- //}
- //#include <iostream>
- //
- //template <typename T>
- //T ShowArray(T arr[], int n);
- //
- //template <typename T>
- //T ShowArray(T* arr[], int n);
- //
- //struct debts
- //{
- // char name[50];
- // double amount;
- //};
- //
- //int main()
- //{
- // using namespace std;
- // int things[6]{ 13, 31, 103, 301, 310, 130 };
- // struct debts mr_E[3]
- // {
- // {"Ima Wolfe", 2400.0},
- // {"Ura Foxe", 1300.0},
- // {"Iby Stour", 1800.0}
- // };
- // double* pd[3];
- //
- // for (int i = 0; i < 3; ++i)
- // pd[i] = &mr_E[i].amount;
- // cout << "Listing Mr. E's counts of things: \n";
- //
- // cout << ShowArray(things, 6);
- // cout << "Listing Mr. E's debts: \n";
- //
- // cout << ShowArray(pd, 3);
- //
- // return 0;
- //}
- //
- //template <typename T>
- //T ShowArray(T arr[], int n)
- //{
- // using namespace std;
- // cout << "template A\n";
- // T sum = 0;
- // for (int i = 0; i < n; ++i)
- // sum += arr[i];
- // cout << endl;
- // return sum;
- //}
- //
- //template <typename T>
- //T ShowArray(T* arr[], int n)
- //{
- // using namespace std;
- // cout << "template B\n";
- // T sum = 0;
- // for (int i = 0; i < n; ++i)
- // sum += (*arr[i]);
- // cout << endl;
- // return sum;
- //}
- //#include <iostream>
- //#include <string>
- //
- //class BankAccount
- //{
- // std::string clientName;
- // std::string accNum;
- // float balance;
- // static int numOfClients;
- //
- //public:
- // BankAccount();
- // BankAccount(std::string clientName_, std::string accNum_, float balance_ = 0);
- // ~BankAccount();
- //
- // static int getHowManyClients();
- //
- // const std::string& getClientName() const;
- // const std::string& getAccNum() const;
- // float getBalance() const;
- //
- // void setClientName(const std::string& clientName_);
- // void setAccNum(const std::string& accNum_);
- // void setBalance(const float balance_);
- //
- // void deposit(const float cash);
- // void withdraw(const float cash);
- //
- // friend std::ostream& operator<<(std::ostream& os, const BankAccount &acc);
- // friend std::istream& operator>>(std::istream& is, BankAccount& acc);
- //};
- //
- //int BankAccount::numOfClients = 0;
- //
- //BankAccount::BankAccount()
- //{
- // clientName = "";
- // accNum = "";
- // balance = 0.0f;
- // ++numOfClients;
- //}
- //
- //BankAccount::BankAccount(std::string clientName_, std::string accNum_, float balance_)
- //{
- // clientName = clientName_;
- // accNum = accNum_;
- // balance = balance_;
- // ++numOfClients;
- //}
- //
- //BankAccount::~BankAccount()
- //{
- // clientName = "";
- // accNum = "";
- // balance = 0;
- // --numOfClients;
- //}
- //
- //int BankAccount::getHowManyClients()
- //{
- // return numOfClients;
- //}
- //
- //
- //const std::string& BankAccount::getClientName() const
- //{
- // return clientName;
- //}
- //
- //const std::string& BankAccount::getAccNum() const
- //{
- // return accNum;
- //}
- //
- //float BankAccount::getBalance() const
- //{
- // return balance;
- //}
- //
- //void BankAccount::setClientName(const std::string& clientName_)
- //{
- // clientName = clientName_;
- //}
- //
- //void BankAccount::setAccNum(const std::string& accNum_)
- //{
- // accNum = accNum_;
- //}
- //
- //void BankAccount::setBalance(const float balance_)
- //{
- // balance = balance_;
- //}
- //
- //void BankAccount::deposit(const float cash)
- //{
- // balance += cash;
- //}
- //
- //void BankAccount::withdraw(const float cash)
- //{
- // balance -= cash;
- //}
- //
- //std::ostream& operator<<(std::ostream& os, const BankAccount& acc)
- //{
- // os << std::endl << "Client name: " << acc.clientName << std::endl <<
- // "Account num: " << acc.accNum << std::endl <<
- // "Balance: " << acc.balance << std::endl;
- // return os;
- //
- //}
- //
- //std::istream& operator>>(std::istream& is, BankAccount& acc)
- //{
- // std::cout << std::endl << "Enter client name: ";
- // is >> acc.clientName;
- // std::cout << std::endl << "Enter account num: ";
- // is >> acc.accNum;
- // std::cout << std::endl << "Enter balance: ";
- // is >> acc.balance;
- // return is;
- //}
- //
- //int main()
- //{
- // {
- // BankAccount Acc1("Mark", "01", 23.56);
- // std::cout << std::endl << BankAccount::getHowManyClients();
- // BankAccount Acc2("Vol", "02");
- // std::cout << std::endl << BankAccount::getHowManyClients();
- // BankAccount Acc3;
- // std::cout << std::endl << BankAccount::getHowManyClients();
- // std::cin >> Acc3;
- // std::cout << Acc1 << Acc2 << Acc3;
- // Acc1.setAccNum("04");
- // Acc2.setClientName("Volodia");
- // Acc3.setBalance(500.0f);
- // std::cout << Acc1.getAccNum();
- // std::cout << Acc2.getClientName();
- // std::cout << Acc3.getBalance();
- // Acc3.deposit(500.0f);
- // std::cout << Acc3.getBalance();
- // Acc3.withdraw(500.0f);
- // std::cout << Acc3.getBalance();
- // std::cout << std::endl << BankAccount::getHowManyClients();
- // }
- // std::cout << std::endl << BankAccount::getHowManyClients();
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //using namespace std;
- //
- //class Person
- //{
- //private:
- // static const int LIMIT = 25;
- // string lname;
- // char fname[LIMIT];
- //public:
- // Person() { lname = ""; fname[0] = '\0'; }
- // Person(const string& ln, const char* fn = "Heyyou");
- //
- // void Show() const;
- // void FormalShow() const;
- //};
- //
- //
- //Person::Person(const string& ln, const char* fn)
- //{
- // lname = ln;
- // strncpy(fname, fn, LIMIT);
- //}
- //
- //void Person::Show() const
- //{
- // cout << fname << " " << lname;
- //}
- //
- //void Person::FormalShow() const
- //{
- // cout << lname << " " << fname;
- //}
- //
- //
- //int main()
- //{
- // Person one;
- // Person two("Smythecraft");
- // Person three("Dimwiddy", "Sam");
- //
- // one.Show();
- // cout << endl;
- // one.FormalShow();
- //
- // two.Show();
- // cout << endl;
- // two.FormalShow();
- //
- // three.Show();
- // cout << endl;
- // three.FormalShow();
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //const int Len = 40;
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //class Golf
- //{
- // char fullname[Len];
- // int handicap;
- //public:
- // Golf();
- // Golf(const char* name, int hc);
- // void setgolf();
- // void changeHandicap(int hc);
- // void showgolf() const;
- //};
- //
- //Golf::Golf()
- //{
- // fullname[0] = '\0';
- // handicap = 0;
- //}
- //
- //Golf::Golf(const char* name, int hc)
- //{
- // strncpy(fullname, name, Len);
- // handicap = hc;
- //}
- //
- //void Golf::setgolf()
- //{
- // char fn[Len];
- // int hc;
- // cout << "Enter fullname: ";
- // cin >> fn;
- // cout << "Enter handicap: ";
- // cin >> hc;
- // *this = Golf(fn, hc);
- //}
- //
- //void Golf::changeHandicap(int hc)
- //{
- // handicap = hc;
- //}
- //
- //void Golf::showgolf() const
- //{
- // cout << "Fullname: " << fullname;
- // cout << "Handicap: " << handicap;
- //}
- //
- //int main()
- //{
- // Golf G1("Andriy", 6);
- // G1.showgolf();
- // Golf G2;
- // G2.setgolf();
- // G2.showgolf();
- // G1.changeHandicap(5);
- // G1.showgolf();
- //
- // return 0;
- //}
- //#include <iostream>
- //namespace SALES
- //{
- // const int QUARTERS = 4;
- // class Sales
- // {
- // double sales[QUARTERS];
- // double average;
- // double max;
- // double min;
- // public:
- // Sales(const double ar[], int n);
- // Sales();
- // void setSales();
- // void showSales();
- // };
- //}
- //
- //SALES::Sales::Sales()
- //{
- // for (int i = 0; i < SALES::QUARTERS; ++i)
- // sales[i] = 0;
- // average = max = min = 0;
- //}
- //
- //SALES::Sales::Sales(const double ar[], int n)
- //{
- // double av = 0, min_ = ar[0], max_ = ar[n - 1];
- // for (int i = 0; i < n; ++i)
- // {
- // SALES::Sales::sales[i] = ar[i];
- // av += SALES::Sales::sales[i];
- // if (min_ > SALES::Sales::sales[i])
- // min_ = SALES::Sales::sales[i];
- // else if (max_ < SALES::Sales::sales[i])
- // max_ = SALES::Sales::sales[i];
- // }
- // av /= n;
- // for (int i = n; i < SALES::QUARTERS; ++i)
- // SALES::Sales::sales[i] = 0;
- // SALES::Sales::average = av;
- // SALES::Sales::min = min_;
- // SALES::Sales::max = max_;
- //}
- //
- //void SALES::Sales::setSales()
- //{
- // double sale[QUARTERS];
- // std::cout << "Enter " << SALES::QUARTERS << " sales: ";
- // for (int i = 0; i < SALES::QUARTERS; ++i)
- // std::cin >> sale[i];
- // *this = SALES::Sales::Sales(sale, SALES::QUARTERS);
- //}
- //
- //void SALES::Sales::showSales()
- //{
- // std::cout << std::endl << "Min = " << min << " Max = " << max << " Av = " << average << std::endl;
- //}
- //
- //int main()
- //{
- // const double arr[SALES::QUARTERS]{ 1.0, 1.2, 1.4 };
- // SALES::Sales S1(arr, 3);
- // SALES::Sales S2;
- // S1.showSales();
- // S2.setSales();
- // S2.showSales();
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //
- //struct Customer
- //{
- // std::string name;
- // std::string surname;
- // float payment;
- //
- //};
- //
- //
- //class Stack
- //{
- // struct Node
- // {
- // Customer cus;
- // Node* next;
- // Node* prev;
- // };
- //
- // Node* top;
- // int numOfNodes;
- // const int maxSize = 10;
- // static float totalPayment;
- //public:
- // Stack();
- // bool isFull() const;
- // bool isEmpty() const;
- // void addNode(const Customer &cus);
- // void popNode();
- // void show();
- // static int getTotal();
- //};
- //
- //float Stack::totalPayment = 0.0;
- //
- //int Stack::getTotal()
- //{
- // return totalPayment;
- //}
- //
- //Stack::Stack() : top(nullptr), numOfNodes(0)
- //{
- //}
- //
- //bool Stack::isFull() const
- //{
- // return numOfNodes == maxSize;
- //}
- //
- //bool Stack::isEmpty() const
- //{
- // return numOfNodes == 0;
- //}
- //
- //void Stack::addNode(const Customer& buyer)
- //{
- // if (numOfNodes == maxSize)
- // {
- // std::cout << std::endl << "Max num of nodes " << std::endl;
- // }
- // else if (top == nullptr)
- // {
- // Node* temp = new Node;
- // temp->cus = buyer;
- // temp->prev = nullptr;
- // temp->prev = nullptr;
- // top = temp;
- // ++numOfNodes;
- // }
- // else
- // {
- // Node* temp = new Node;
- // temp->cus = buyer;
- // temp->prev = top;
- // temp->next = nullptr;
- // top->next = temp;
- // top = temp;
- // ++numOfNodes;
- // }
- //}
- //
- //void Stack::popNode()
- //{
- // if (top == nullptr)
- // return;
- // else if (top->prev == nullptr)
- // {
- // totalPayment += top->cus.payment;
- // delete top;
- // top = nullptr;
- // numOfNodes = 0;
- // }
- // else
- // {
- // Node* temp = top->prev;
- // totalPayment += top->cus.payment;
- // delete top;
- // top = temp;
- // --numOfNodes;
- // }
- //}
- //
- //void Stack::show()
- //{
- // using std::cout;
- // using std::endl;
- // Node* temp = top;
- // while (temp != nullptr)
- // {
- // cout << endl << temp->cus.name << "\t" << temp->cus.surname << "\t" << temp->cus.payment;
- // temp = temp->prev;
- // }
- //}
- //
- //int main()
- //{
- // using std::cout;
- // using std::cin;
- // using std::endl;
- // Stack stack;
- // Customer buyer{ "A", "b", 50.0f };
- // cout << endl << stack.isEmpty() << endl;
- // cout << endl << stack.isFull() << endl;
- // stack.addNode(buyer);
- // stack.show();
- // cout << stack.isEmpty() << endl;
- // cout << stack.isFull() << endl;
- // stack.addNode(buyer);
- // cout << stack.isEmpty() << endl;
- // cout << stack.isFull() << endl;
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.addNode(buyer);
- // stack.show();
- // cout << endl << stack.isEmpty() << endl;
- // cout << endl << stack.isFull() << endl << endl << endl;
- //
- // cout << stack.getTotal();
- //
- // stack.popNode();
- // stack.popNode();
- //
- // cout << stack.getTotal();
- //
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- // stack.popNode();
- //
- // cout << stack.getTotal();
- // stack.popNode();
- // stack.popNode();
- // cout << stack.isEmpty() << endl;
- // cout << stack.isFull() << endl;
- //
- // return 0;
- //}
- //
- //#include <iostream>
- //
- //class Move
- //{
- //private:
- // double x;
- // double y;
- //public:
- // Move(double a = 0, double b = 0);
- // void showmove() const;
- // Move add(const Move& m) const;
- // void reset(double a = 0, double b = 0);
- //};
- //
- //Move::Move(double a, double b)
- //{
- // x = a;
- // y = b;
- //}
- //
- //void Move::showmove() const
- //{
- // using std::cout;
- // cout << "X = " << x << "\t" << "Y = " << y << std::endl;
- //}
- //
- //void Move::reset(double a, double b)
- //{
- // x = a;
- // y = b;
- //}
- //
- //Move Move::add(const Move& m) const
- //{
- // Move temp(x + m.x, y + m.y);
- // return temp;
- //}
- //
- //int main()
- //{
- // using std::cout;
- // using std::endl;
- //
- // Move A;
- // A.showmove();
- // Move B(1, 2);
- // B.showmove();
- // A.reset(2, 3);
- // A.showmove();
- // Move C = B.add(A);
- // C.showmove();
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //using namespace std;
- //class Plorg
- //{
- // string name;
- // int CI;
- //public:
- // Plorg(const string& n = "Plorga", int ci = 50);
- // void show() const;
- // void changeCI(int ci);
- //};
- //
- //Plorg::Plorg(const string& n, int ci)
- //{
- // name = n;
- // CI = ci;
- //}
- //
- //void Plorg::show() const
- //{
- // cout << endl << "Name: " << name << "\t" << "CI = " << CI;
- //}
- //
- //void Plorg::changeCI(int ci)
- //{
- // CI = ci;
- //}
- //
- //int main()
- //{
- // Plorg A;
- // A.show();
- // A.changeCI(5);
- // A.show();
- // Plorg B("Q", 2);
- // B.show();
- // return 0;
- //}
- //
- //#include <iostream>
- //#include <fstream>
- //#include <cmath>
- //#include <cstdlib>
- //#include <ctime>
- //using namespace std;
- //
- //namespace VECTOR
- //{
- // class Vector
- // {
- // public:
- // enum Mode {RECT, POL};
- // private:
- // double x;
- // double y;
- // Mode mode;
- //
- // void set_x(double n1, double n2);
- // void set_y(double n1, double n2);
- // public:
- // Vector();
- // Vector(double n1, double n2, Mode form = RECT);
- // void reset(double n1, double n2, Mode form = RECT);
- // ~Vector();
- // double xval() const { return x; }
- // double yval() const { return y; }
- // double magval() const { return sqrt(x * x + y * y); }
- // double angval() const { return (x == 0 && y == 0) ? 0.0 : atan2(y, x); }
- // void polar_mode();
- // void rect_mode();
- //
- // Vector operator+(const Vector& b) const;
- // Vector operator-(const Vector& b) const;
- // Vector operator-() const;
- // Vector operator*(double n) const;
- //
- // friend Vector operator*(double n, const Vector& a);
- // friend ostream& operator << (ostream& os, const Vector& v);
- // };
- //}
- //
- //namespace VECTOR
- //{
- // const double Rad_to_deg = 45.0 / atan(1.0);
- //
- // void Vector::set_x(double n1, double n2)
- // {
- // x = n1 * cos(n2);
- // }
- // void Vector::set_y(double n1, double n2)
- // {
- // y = n1 * sin(n2);
- // }
- // Vector::Vector()
- // {
- // x = y = 0.0;
- // mode = RECT;
- // }
- // Vector::Vector(double n1, double n2, Mode form)
- // {
- // mode = form;
- // if (form == RECT)
- // {
- // x = n1;
- // y = n2;
- // }
- // else if (form == POL)
- // {
- // set_x(n1, n2);
- // set_y(n1, n2);
- // }
- // else
- // {
- // cout << "Incorrect 3rd argument to Vector() -- ";
- // cout << "vector set to 0\n";
- // x = y = 0.0;
- // mode = RECT;
- // }
- // }
- // void Vector::reset(double n1, double n2, Mode form)
- // {
- // mode = form;
- // if (form == RECT)
- // {
- // x = n1;
- // y = n2;
- // }
- // else if (form == POL)
- // {
- // set_x(n1, n2);
- // set_y(n1, n2);
- // }
- // else
- // {
- // cout << "Incorrect 3rd argument to Vector() -- ";
- // cout << "vector set to 0\n";
- // x = y = 0.0;
- // mode = RECT;
- // }
- // }
- //
- // Vector::~Vector()
- // {
- // }
- // void Vector::polar_mode()
- // {
- // mode = POL;
- // }
- // void Vector::rect_mode()
- // {
- // mode = RECT;
- // }
- // Vector Vector::operator+(const Vector& b) const
- // {
- // return Vector(x + b.x, y + b.y);
- // }
- // Vector Vector::operator-(const Vector& b) const
- // {
- // return Vector(x - b.x, y - b.y);
- // }
- // Vector Vector::operator-() const
- // {
- // return Vector(-x, -y);
- // }
- // Vector Vector::operator*(double n) const
- // {
- // return Vector(n * x, n * y);
- // }
- // Vector operator*(double n, const Vector& a)
- // {
- // return a * n;
- // }
- // ostream& operator<<(ostream& os, const Vector& v)
- // {
- // if (v.mode == Vector::RECT)
- // os << "(x, y) = (" << v.x << ", " << v.y << ")";
- // else if (v.mode == Vector::POL)
- // os << "(m, a) = (" << v.magval() << ", " << v.angval() * Rad_to_deg << ")";
- // return os;
- // }
- //}
- //
- //int main()
- //{
- // using VECTOR::Vector;
- //
- // srand(time(0));
- // double direction;
- // Vector step;
- // Vector result(0.0, 0.0);
- // unsigned long steps = 0;
- // double target;
- // double dstep;
- // int N;
- //
- // cout << "Enter target distance (q to quit): ";
- // while (cin >> target)
- // {
- // cout << "Enter step length: ";
- // if (!(cin >> dstep))
- // break;
- // cout << "Enter N: ";
- // if (!(cin >> N))
- // break;
- // cout << "Target Distance: " << target << ", Step Size: " << dstep << ", N = "<< N << endl;
- // int count = 0;
- // while (count < N)
- // {
- // while (result.magval() < target)
- // {
- // direction = rand() % 10;
- // step.reset(dstep, direction, Vector::POL);
- // result = result + step;
- // ++steps;
- // }
- // result.rect_mode();
- // cout << count + 1 << ") After " << steps << " steps, the subject "
- // "has the following location:\n";
- // cout << result << endl;
- // result.polar_mode();
- // cout << " or\n" << result << endl;
- //
- // cout << "Average outward distance per step = "
- // << result.magval() / steps << endl << endl;
- // ++count;
- // }
- //
- // steps = 0;
- // result.reset(0.0, 0.0);
- // cout << "Enter target distance (q to quit): ";
- // }
- // cout << "Bye!\n";
- // cin.clear();
- // while (cin.get() != '\n')
- // continue;
- // return 0;
- //}
- //#include <iostream>
- //
- //class Time
- //{
- //private:
- // int hours;
- // int minutes;
- //public:
- // Time();
- // Time(int h, int m = 0);
- // void AddMin(int m);
- // void AddHr(int h);
- // void Reset(int h = 0, int m = 0);
- // friend Time operator+(const Time& t1, const Time& t2);
- // friend Time operator-(const Time& t1, const Time& t2);
- // friend Time operator*(const Time& t, double mult);
- // friend Time operator*(double m, const Time& t) { return t * m; }
- // friend std::ostream& operator << (std::ostream& os, const Time& t);
- //};
- //
- //Time::Time()
- //{
- // hours = minutes = 0;
- //}
- //
- //Time::Time(int h, int m)
- //{
- // hours = h;
- // minutes = m;
- //}
- //
- //void Time::AddMin(int m)
- //{
- // minutes += m;
- // hours += minutes / 60;
- // minutes %= 60;
- //}
- //
- //void Time::AddHr(int h)
- //{
- // hours += h;
- //}
- //
- //Time operator+(const Time& t1, const Time& t2)
- //{
- // Time sum;
- // sum.minutes = t1.minutes + t2.minutes;
- // sum.hours = t1.hours + t2.hours + sum.minutes / 60;
- // sum.minutes %= 60;
- // return sum;
- //}
- //
- //Time operator-(const Time& t1, const Time& t2)
- //{
- // Time diff;
- // int tot1, tot2;
- // tot1 = t2.minutes + 60 * t2.hours;
- // tot2 = t1.minutes + 60 * t1.hours;
- // diff.minutes = (tot2 - tot1) % 60;
- // diff.hours = (tot2 - tot1) / 60;
- // return diff;
- //}
- //
- //Time operator*(const Time& t, double mult)
- //{
- // Time result;
- // long totalminutes = t.hours * mult * 60 + t.minutes * mult;
- // result.hours = totalminutes / 60;
- // result.minutes = totalminutes % 60;
- // return result;
- //}
- //
- //std::ostream& operator<<(std::ostream& os, const Time& t)
- //{
- // os << t.hours << " hours, " << t.minutes << " minutes";
- // return os;
- //}
- //
- //int main()
- //{
- // using std::cout;
- // using std::endl;
- //
- // Time aida(3, 35);
- // Time tosca(2, 48);
- // Time temp;
- // cout << "Aida and Tosca:\n ";
- // cout << aida << "; " << tosca << endl;
- // temp = aida + tosca;
- // cout << "Aida + Tosca: " << temp << endl;
- // temp = aida * 1.17;
- // cout << "Aida * 1.17: " << temp << endl;
- // cout << "10.0 * Tosca: " << 10.0 * tosca << endl;
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //class Stonewt
- //{
- //private:
- // int dollars;
- // int cents;
- //public:
- // enum Mode {D, C};
- // Mode mode;
- // Stonewt();
- // Stonewt(int cent);
- // Stonewt(int dollar, int cent);
- // ~Stonewt();
- // Stonewt operator+(const Stonewt& s) const;
- // Stonewt operator-(const Stonewt& s) const;
- // Stonewt operator*(int mult) const;
- // bool operator>(const Stonewt& s) const;
- // bool operator<(const Stonewt& s) const;
- // bool operator>=(const Stonewt& s) const;
- // bool operator<=(const Stonewt& s) const;
- // bool operator==(const Stonewt& s) const;
- // bool operator!=(const Stonewt& s) const;
- // friend ostream& operator<<(ostream& os, const Stonewt& s);
- //};
- //
- //bool Stonewt::operator!=(const Stonewt& s) const
- //{
- // return !(*this == s);
- //}
- //
- //bool Stonewt::operator==(const Stonewt& s) const
- //{
- // return dollars * 100 + cents == s.dollars * 100 + cents;
- //}
- //
- //bool Stonewt::operator<=(const Stonewt& s) const
- //{
- // return s >= *this;
- //}
- //
- //bool Stonewt::operator>=(const Stonewt& s) const
- //{
- // return dollars * 100 + cents >= s.dollars * 100 + cents;
- //}
- //
- //bool Stonewt::operator<(const Stonewt& s) const
- //{
- // return s > *this;
- //}
- //
- //bool Stonewt::operator>(const Stonewt& s) const
- //{
- // return dollars * 100 + cents > s.dollars * 100 + cents;
- //}
- //
- //Stonewt Stonewt::operator*(int mult) const
- //{
- // return Stonewt(dollars * mult, cents * mult);
- //}
- //
- //Stonewt Stonewt::operator-(const Stonewt& s) const
- //{
- // return Stonewt(dollars - s.dollars, cents - s.cents);
- //}
- //
- //Stonewt Stonewt::operator+(const Stonewt& s) const
- //{
- // return Stonewt(dollars + s.dollars, cents + s.cents);
- //}
- //
- //ostream& operator<<(ostream& os, const Stonewt& s)
- //{
- // if (s.mode == s.D)
- // os << s.dollars << " dollars, " << s.cents << " cents\n";
- // else if (s.mode == s.C)
- // os << s.dollars * 100 + s.cents << " cents\n";
- // return os;
- //}
- //
- //Stonewt::Stonewt(int cent)
- //{
- // mode = D;
- // dollars = cent / 100;
- // cents = cent % 100;
- //}
- //
- //Stonewt::Stonewt(int dol, int cent)
- //{
- // mode = D;
- // dollars = dol;
- // cents = cent;
- //}
- //
- //Stonewt::Stonewt()
- //{
- // mode = D;
- // dollars = cents = 0;
- //}
- //
- //Stonewt::~Stonewt()
- //{
- //}
- //
- //int main()
- //{
- // Stonewt st[6]{ {1, 10}, {3, 30}, {5, 50,}, {2, 20}, {6, 60}, {4, 40} };
- // Stonewt min = st[0], max = st[5];
- // Stonewt temp = st[1];
- // for (int i = 0; i < 6; ++i)
- // {
- // if (st[i] < min)
- // min = st[i];
- // if (st[i] > max)
- // max = st[i];
- // if (st[i] >= temp)
- // cout << st[i];
- // }
- //
- // cout << "min = " << min;
- // cout << "max = " << max;
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //class Complex
- //{
- // float real;
- // float imag;
- //
- //public:
- // Complex(float r = 0, float i = 0);
- //
- // Complex operator+(const Complex& C) const;
- // Complex operator-(const Complex& C) const;
- // Complex operator*(const Complex& C) const;
- // Complex operator*(const float mult) const;
- // Complex operator-() const;
- // friend Complex operator*(const float mult, const Complex& C);
- //
- // friend istream& operator>>(istream& is, Complex& C);
- // friend ostream& operator<<(ostream& os, const Complex& C);
- //};
- //
- //istream& operator>>(istream& is, Complex& C)
- //{
- // cout << "Enter real: ";
- // is >> C.real;
- // cout << "Enter im: ";
- // is >> C.imag;
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Complex& C)
- //{
- // os << "Real = " << C.real << "\tImag = " << C.imag << endl;
- // return os;
- //}
- //
- //Complex::Complex(float r, float i)
- //{
- // real = r;
- // imag = i;
- //}
- //
- //Complex Complex::operator+(const Complex& C) const
- //{
- // return Complex(real + C.real, imag + C.imag);
- //}
- //
- //Complex Complex::operator-(const Complex& C) const
- //{
- // return Complex(real - C.real, imag - C.imag);
- //}
- //
- //Complex Complex::operator*(const Complex& C) const
- //{
- // return Complex(real * C.real - imag * C.imag, real * C.imag + imag * C.real);
- //}
- //
- //Complex Complex::operator*(const float mult) const
- //{
- // return Complex(real * mult, imag * mult);
- //}
- //
- //Complex Complex::operator-() const
- //{
- // return Complex(-real, -imag);
- //}
- //
- //Complex operator*(const float mult, const Complex& C)
- //{
- // return C * mult;
- //}
- //
- //int main()
- //{
- // Complex a(3.0, 4.0);
- // Complex c;//(0.0, 0.0);
- // cout << "a: " << a;
- // cin >> c;
- // cout << "c: " << c;
- // cout << "-c: " << -c;
- // cout << "a + c" << a + c;
- // cout << "a - c" << a - c;
- // cout << "a * c" << a * c;
- // cout << "2 * c" << 2 * c;
- // cout << "c * 2" << c * 2;
- // cout << c;
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <cstring>
- //#include <string>
- //#include <cstdlib>
- //
- //using namespace std;
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //class Cow
- //{
- // char name[20];
- // char* hobby;
- // double weight;
- //public:
- // Cow();
- // Cow(const char* nm, const char* ho, double wt);
- // Cow(const Cow& c);
- // ~Cow();
- // Cow& operator=(const Cow& c);
- // void ShowCow() const;
- //};
- //
- //Cow::Cow()
- //{
- // name[0] = '\0';
- // hobby = new char [1];
- // hobby[0] = '\0';
- // weight = 0.0;
- //}
- //
- //Cow::Cow(const char* nm, const char* ho, double wt)
- //{
- // strncpy(name, nm, 20);
- // size_t len = strlen(ho);
- // hobby = new char[len + 1];
- // strncpy(hobby, ho, len);
- // hobby[len] = '\0';
- // weight = wt;
- //}
- //
- //Cow::Cow(const Cow& c)
- //{
- // weight = c.weight;
- // strncpy(name, c.name, 20);
- // name[strlen(c.name)] = '\0';
- // delete [] hobby;
- // size_t len = strlen(c.hobby);
- // hobby = new char[len + 1];
- // strncpy(hobby, c.hobby, len);
- // hobby[len] = '\0';
- //}
- //
- //Cow::~Cow()
- //{
- // weight = 0.0;
- // name[0] = '\0';
- // delete[] hobby;
- // hobby = nullptr;
- //}
- //
- //Cow& Cow::operator=(const Cow& c)
- //{
- // if (this == &c)
- // return *this;
- // weight = c.weight;
- // strncpy(name, c.name, 20);
- // name[strlen(c.name)] = '\0';
- // delete[] hobby;
- // int len = strlen(c.hobby);
- // hobby = new char[len + 1];
- // strncpy(hobby, c.hobby, len);
- // hobby[len] = '\0';
- // return *this;
- //}
- //
- //void Cow::ShowCow() const
- //{
- // cout << "\nName = " << name << "\tweight = " << weight << "\thobby = " << hobby;
- //}
- //
- //int main()
- //{
- // Cow A;
- // A.ShowCow();
- // Cow B("Felicia", "Chess", 20.0);
- // B.ShowCow();
- // A = B;
- // A.ShowCow();
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <cctype>
- //#include <cstring>
- //
- //using namespace std;
- //
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //class String
- //{
- //private:
- // char* str;
- // int len;
- // static int numOfStrings;
- //public:
- // String();
- // String(const char* s);
- // String(const String&);
- // ~String();
- // int length() const { return len; }
- // static int HowMany();
- //
- // void stringlow();
- // void stringup();
- // int howManyChars(char ch);
- //
- // String& operator=(const String&);
- // String& operator=(const char*);
- // char& operator[](int i);
- // const char& operator[](int i) const;
- // String operator+(const String& st);
- // String operator+(const char* str);
- //
- // friend String operator+(const char* str, const String& st);
- // friend bool operator<(const String& st, const String& st2);
- // friend bool operator>(const String& st, const String& st2);
- // friend bool operator==(const String& st, const String& st2);
- // friend ostream& operator<<(ostream& os, const String& st);
- // friend istream& operator>>(istream& is, String& st);
- //};
- //
- //int String::numOfStrings = 0;
- //
- //String operator+(const char* str, const String& st)
- //{
- // String temp;
- // temp.len = st.len + strlen(str);
- // temp.str = new char[temp.len + 1];
- // strncpy(temp.str, str, strlen(str));
- // temp.str[strlen(str)] = '\0';
- // strncat(temp.str, st.str, st.len);
- // temp.str[temp.len] = '\0';
- // return temp;
- //}
- //
- //String String::operator+(const char* st)
- //{
- // String temp;
- // temp.len = len + strlen(st);
- // temp.str = new char[temp.len + 1];
- // strncpy(temp.str, str, len);
- // temp.str[len] = '\0';
- // strncat(temp.str, st, strlen(st));
- // temp.str[temp.len] = '\0';
- // return temp;
- //}
- //
- //void String::stringlow()
- //{
- // int i = 0;
- // while (str[i] != '\0')
- // {
- // if(isupper(str[i]))
- // str[i] = tolower(str[i]);
- // ++i;
- // }
- //}
- //
- //void String::stringup()
- //{
- // int i = 0;
- // while (str[i] != '\0')
- // {
- // if (islower(str[i]))
- // str[i] = toupper(str[i]);
- // ++i;
- // }
- //}
- //
- //int String::howManyChars(char ch)
- //{
- // int i = 0;
- // int count = 0;
- // while (str[i] != '\0')
- // {
- // if (str[i] == ch)
- // ++count;
- // ++i;
- // }
- // return count;
- //}
- //
- //String String::operator+(const String& st)
- //{
- // String temp;
- // temp.len = len + st.len;
- // temp.str = new char[temp.len + 1];
- // strncpy(temp.str, str, len);
- // temp.str[len] = '\0';
- // strncat(temp.str, st.str, st.len);
- // temp.str[temp.len] = '\0';
- // return temp;
- //}
- //
- //int String::HowMany()
- //{
- // return numOfStrings;
- //}
- //
- //String::String(const char* s)
- //{
- // len = strlen(s);
- // str = new char[len + 1];
- // strncpy(str, s, len);
- // str[len] = '\0';
- // ++numOfStrings;
- //}
- //
- //String::String()
- //{
- // len = 1;
- // str = new char[len + 1];
- // str[0] = str[1] = '\0';
- // ++numOfStrings;
- //}
- //
- //String::String(const String& st)
- //{
- // len = st.len;
- // str = new char[len + 1];
- // strncpy(str, st.str, len);
- // ++numOfStrings;
- //}
- //
- //String::~String()
- //{
- // --numOfStrings;
- // delete[] str;
- // len = 4;
- // str = nullptr;
- //}
- //
- //String& String::operator=(const String& st)
- //{
- // if (this == &st)
- // return *this;
- // delete[] str;
- // len = st.len;
- // str = new char[len + 1];
- // strncpy(str, st.str, len);
- // str[len] = '\0';
- // return *this;
- //}
- //
- //String& String::operator=(const char* s)
- //{
- // delete[] str;
- // len = strlen(s);
- // str = new char[len + 1];
- // strncpy(str, s, len);
- // str[len] = '\0';
- // return *this;
- //}
- //
- //char& String::operator[](int i)
- //{
- // return str[i];
- //}
- //
- //const char& String::operator[](int i) const
- //{
- // return str[i];
- //}
- //
- //bool operator<(const String& st1, const String& st2)
- //{
- // return (strcmp(st1.str, st2.str) < 0);
- //}
- //
- //bool operator>(const String& st1, const String& st2)
- //{
- // return st2.str < st1.str;
- //}
- //
- //bool operator==(const String& st1, const String& st2)
- //{
- // return (strcmp(st1.str, st2.str) == 0);
- //}
- //
- //ostream& operator<<(ostream& os, const String& st)
- //{
- // os << st.str;
- // return os;
- //}
- //
- //istream& operator>>(istream& is, String& st)
- //{
- // char temp[100];
- // is.get(temp, 100);
- // while (is.get() != '\n')
- // continue;
- // st = temp;
- // return is;
- //}
- //
- //int main()
- //{
- //
- // String s1(" and I am a C++ student.");
- // String s2 = "Please enter your name: ";
- // String s3;
- // cout << s2;
- // cin >> s3;
- // s2 = "My name is " + s3;
- // cout << s2 << ".\n";
- // s2 = s2 + s1;
- // s2.stringup();
- // cout << "The string\n" << s2 << "\ncontains " << s2.howManyChars('A') << " 'A' characters in it.\n";
- // s1 = "red";
- // String rgb[3] = { String(s1), String("green"), String("blue") };
- // cout << "Enter the name of a primaty color for mixing light: ";
- // String ans;
- // bool success = false;
- // while (cin >> ans)
- // {
- // ans.stringlow();
- // for (int i = 0; i < 3; ++i)
- // {
- // if (ans == rgb[i])
- // {
- // cout << "That's right!\n";
- // success = true;
- // break;
- // }
- // }
- // if (success)
- // break;
- // else
- // cout << "Try agein!\n";
- // }
- // cout << "Bye\n";
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //using namespace std;
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //class Stock
- //{
- // char *company;
- // int shares;
- // double share_val;
- // double total_val;
- // void set_tot() { total_val = shares * share_val; }
- //public:
- // Stock();
- // Stock(const char* co, long n = 0, double pr = 0.0);
- // ~Stock();
- // void buy(long num, double price);
- // void sell(long num, double price);
- // void update(double price);
- // void show() const;
- // friend ostream& operator<<(ostream& os, const Stock& s);
- // const Stock& topval(const Stock& s) const;
- //};
- //
- //ostream& operator<<(ostream& os, const Stock& s)
- //{
- // os << "Company: " << s.company;
- // os << " Shares: " << s.shares << endl;
- // os << " Share price: $" << s.share_val;
- // os << " Total worth: $" << s.total_val << endl;
- // return os;
- //}
- //
- //Stock::Stock()
- //{
- // company = new char[8];
- // strcpy(company, "no name");
- // shares = 0;
- // share_val = 0.0;
- // total_val = 0.0;
- //}
- //
- //Stock::Stock(const char* co, long n, double pr)
- //{
- // int len = strlen(co);
- // company = new char[len + 1];
- // strncpy(company, co, len);
- // company[len] = '\0';
- // if (n < 0)
- // {
- // cout << "Number of shares can't be negative; " << company << " shares set to 0.\n";
- // shares = 0;
- // }
- // else
- // shares = n;
- // share_val = pr;
- // set_tot();
- //}
- //
- //Stock::~Stock()
- //{
- // delete[] company;
- // company = nullptr;
- //}
- //
- //void Stock::buy(long num, double price)
- //{
- // if (num < 0)
- // cout << "Number of shares purchased can't be negative. Transaction is aborted.\n";
- // else
- // {
- // shares += num;
- // share_val = price;
- // set_tot();
- // }
- //}
- //
- //void Stock::sell(long num, double price)
- //{
- // if (num < 0)
- // cout << "Number can't be negative. Abort\n";
- // else if (num > shares)
- // cout << "Too much. Abort\n";
- // else
- // {
- // shares -= num;
- // share_val = price;
- // set_tot();
- // }
- //}
- //
- //void Stock::update(double price)
- //{
- // share_val = price;
- // set_tot();
- //}
- //
- //void Stock::show() const
- //{
- // cout << "Company: " << company;
- // cout << " Shares: " << shares << endl;
- // cout << " Share price: $" << share_val;
- // cout << " Total worth: $" << total_val << endl;
- //}
- //
- //const Stock& Stock::topval(const Stock& s) const
- //{
- // if (s.total_val > total_val)
- // return s;
- // else
- // return *this;
- //}
- //
- //const int STKS = 4;
- //
- //int main()
- //{
- // Stock stocks[STKS] = {
- // Stock("NanoSmart", 12, 20.0),
- // Stock("Boffo Objects", 200, 2.0),
- // Stock("Monolithic Obelisks", 130, 3.25),
- // Stock("Fleep Enterprises", 60, 6.5)
- // };
- // cout << "Stock holdings:\n";
- // for (int st = 0; st < STKS; ++st)
- // cout << stocks[st];
- //
- // const Stock* top = &stocks[0];
- // for (int st = 1; st < STKS; ++st)
- // top = &top->topval(stocks[st]);
- //
- // cout << "Most valuable holding: \n";
- // cout << *top;
- //}
- //#include <iostream>
- //using namespace std;
- //typedef unsigned long Item;
- //
- //class Stack
- //{
- // enum {MAX = 10};
- // Item* pitems;
- // int size;
- // int top;
- //public:
- // Stack(int n = 10);
- // Stack(const Stack& st);
- // ~Stack();
- // bool isempty() const;
- // bool isfull() const;
- // bool push(const Item& item);
- // bool pop(Item& item);
- // Stack& operator=(const Stack& st);
- //};
- //
- //Stack::Stack(int n)
- //{
- // pitems = new Item[n];
- // size = 0;
- //}
- //
- //Stack::Stack(const Stack& st)
- //{
- // size = st.size;
- // delete[] pitems;
- // pitems = new Item[size];
- // for (int i = 0; i < size; ++i)
- // pitems[i] = st.pitems[i];
- // top = pitems[size - 1];
- //}
- //
- //Stack::~Stack()
- //{
- // delete[] pitems;
- // pitems = nullptr;
- //}
- //
- //bool Stack::isempty() const
- //{
- // return size == 0;
- //}
- //
- //bool Stack::isfull() const
- //{
- // return size == Stack::MAX;
- //}
- //
- //bool Stack::push(const Item& item)
- //{
- // if (size == Stack::MAX)
- // return false;
- // Stack temp(*this);
- // delete[] pitems;
- // size = temp.size + 1;
- // pitems = new Item[size];
- // for (int i = 0; i < size - 1; ++i)
- // pitems[i] = temp.pitems[i];
- // pitems[size - 1] = item;
- // top = size;
- // return true;
- //}
- //
- //bool Stack::pop(Item& item)
- //{
- // if (size == 0)
- // return false;
- // Stack temp(*this);
- // item = pitems[size - 1];
- // delete[] pitems;
- // size -= 1;
- // pitems = new Item[size];
- // for (int i = 0; i < size; ++i)
- // pitems[i] = temp.pitems[i];
- // return true;
- //}
- //
- //Stack& Stack::operator=(const Stack& st)
- //{
- // if (this == &st)
- // return *this;
- // size = st.size;
- // delete[] pitems;
- // pitems = new Item[size];
- // for (int i = 0; i < size; ++i)
- // pitems[i] = st.pitems[i];
- // top = pitems[size - 1];
- // return *this;
- //}
- //
- //int main()
- //{
- // Stack st;
- // char ch;
- // unsigned long po;
- // cout << "A, p, q\n";
- // while (cin >> ch && toupper(ch) != 'Q')
- // {
- // while (cin.get() != '\n')
- // continue;
- // if (!isalpha(ch))
- // {
- // cout << '\a';
- // continue;
- // }
- // switch (ch)
- // {
- // case'A':
- // case'a':
- // cout << "Enter a PO: ";
- // cin >> po;
- // if (st.isfull())
- // cout << "stack already full\n";
- // else
- // st.push(po);
- // break;
- // case'P':
- // case'p':
- // if (st.isempty())
- // cout << "stack already empty\n";
- // else
- // {
- // st.pop(po);
- // cout << "PO #" << po << " popped\n";
- // }
- // break;
- // }
- // cout << "Pjkg";
- // }
- // cout << "Bye\n";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //class Cd
- //{
- // char* performers;
- // char* label;
- // int selections;
- // double playtime;
- //public:
- // Cd(const char* s1, const char* s2, int n, double x);
- // Cd(const Cd& d);
- // Cd();
- // virtual ~Cd();
- // virtual void Report() const;
- // Cd& operator=(const Cd& d);
- //};
- //
- //class Classic : public Cd
- //{
- // char* name;
- //public:
- // Classic();
- // Classic(const Classic& d);
- // Classic(const char* s1, const char* s2, const char* s3, int n, double x);
- // Classic& operator=(const Classic& d);
- // void Report() const final;
- // ~Classic();
- //};
- //
- //Classic::Classic() : Cd()
- //{
- // const char* name_ = "none";
- // name = new char[strlen(name_) + 1];
- // strncpy(name, name_, strlen(name_));
- // name[strlen(name_)] = '\0';
- //}
- //
- //Classic::~Classic()
- //{
- // delete[] name;
- // name = nullptr;
- //}
- //
- //Classic::Classic(const char* s1, const char* s2, const char* s3, int n, double x) :
- // Cd(s1, s2, n, x)
- //{
- // name = new char[strlen(s3) + 1];
- // strncpy(name, s3, strlen(s3));
- // name[strlen(s3)] = '\0';
- //}
- //
- //Cd::Cd(const char* s1, const char* s2, int n, double x)
- //{
- // performers = new char[strlen(s1) + 1];
- // strncpy(performers, s1, strlen(s1));
- // performers[strlen(s1)] = '\0';
- // label = new char[strlen(s2) + 1];
- // strncpy(label , s2, strlen(s2));
- // label[strlen(s2)] = '\0';
- // selections = n;
- // playtime = x;
- //}
- //
- //Cd::Cd(const Cd& d)
- //{
- // performers = new char[strlen(d.performers) + 1];
- // strncpy(performers, d.performers, strlen(d.performers));
- // performers[strlen(d.performers)] = '\0';
- // label = new char[strlen(d.label) + 1];
- // strncpy(label, d.label, strlen(d.label));
- // label[strlen(d.label)] = '\0';
- // selections = d.selections;
- // playtime = d.playtime;
- //}
- //
- //Cd::Cd()
- //{
- // const char* name_ = "none";
- // performers = new char[strlen(name_) + 1];
- // strncpy(performers, name_, strlen(name_));
- // performers[strlen(name_)] = '\0';
- // label = new char[strlen(name_) + 1];
- // strncpy(label, name_, strlen(name_));
- // label[strlen(name_)] = '\0';
- // selections = 0;
- // playtime = 0.0;
- //}
- //
- //void Cd::Report() const
- //{
- // cout << "Performers = " << performers << "\nLabel = " << label
- // << "\nSelections = " << selections << "\nPlaytime = " << playtime;
- //}
- //
- //void Classic::Report() const
- //{
- // Cd::Report();
- // cout << "\nName = " << name << endl;
- //}
- //
- //Cd& Cd::operator=(const Cd& d)
- //{
- // if (this == &d)
- // return *this;
- // delete[] performers;
- // performers = new char[strlen(d.performers) + 1];
- // strncpy(performers, d.performers, strlen(d.performers));
- // performers[strlen(d.performers)] = '\0';
- // delete[] label;
- // label = new char[strlen(d.label) + 1];
- // strncpy(label, d.label, strlen(d.label));
- // label[strlen(d.label)] = '\0';
- // selections = d.selections;
- // playtime = d.playtime;
- // return *this;
- //}
- //
- //Classic& Classic::operator=(const Classic& d)
- //{
- // if (this == &d)
- // return *this;
- // Cd::operator=(d);
- // delete[] name;
- // name = new char[strlen(d.name) + 1];
- // strncpy(name, d.name, strlen(d.name));
- // name[strlen(d.name)] = '\0';
- // return *this;
- //}
- //
- //Classic::Classic(const Classic& d) : Cd(d)
- //{
- // name = new char[strlen(d.name) + 1];
- // strncpy(name, d.name, strlen(d.name));
- // name[strlen(d.name)] = '\0';
- //}
- //
- //Cd::~Cd()
- //{
- // delete[] performers;
- // performers = nullptr;
- // delete[] label;
- // label = nullptr;
- //}
- //
- //void Bravo(const Cd& disk)
- //{
- // disk.Report();
- //}
- //
- //int main()
- //{
- // Cd c1("Beatles", "Capitol", 14, 35.5 );
- // Classic c2 = Classic("Piano Sonata in B flat, Fantasia in C",
- // "Alfred Brendel", "Phillips", 2, 57.17);
- // Cd* pcd = &c1;
- // cout << "\nUsing object directly: \n";
- // c1.Report();
- // cout << endl;
- // c2.Report();
- // cout << "\nUsing pointer: \n";
- // pcd->Report();
- // cout << endl;
- // pcd = &c2;
- // pcd->Report();
- // cout << "\nCalling a function with a Cd reference: \n";
- // Bravo(c1);
- // cout << endl;
- // Bravo(c2);
- // cout << "\nTesting assignment: \n";
- // Classic copy;
- // copy = c2;
- // cout << endl;
- // copy.Report();
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //class AbsDma
- //{
- //protected:
- // char* label;
- // int rating;
- //public:
- // AbsDma(const char* l = "none", int r = 0);
- // AbsDma(const AbsDma& ra);
- // virtual ~AbsDma();
- // AbsDma& operator=(const AbsDma& ra);
- // virtual void View() const = 0;
- //};
- //
- //class baseDma : public AbsDma
- //{
- //public:
- // baseDma(const char* l = "none", int r = 0);
- // baseDma(const baseDma& rb);
- // ~baseDma();
- // baseDma& operator=(const baseDma& ra);
- // void View() const;
- //};
- //
- //class hasDma : public AbsDma
- //{
- // char* style;
- //public:
- // hasDma(const char* s = "none", const char* l = "none", int r = 0);
- // hasDma(const hasDma& rh, const char* s);
- // ~hasDma();
- // hasDma& operator=(const hasDma& rs);
- // void View() const;
- //};
- //
- //class lacksDma : public AbsDma
- //{
- //private:
- // static const int COL_LEN = 40;
- // char color[COL_LEN];
- //public:
- // lacksDma(const char* col = "none", const char* lab = "none", int r = 0);
- // lacksDma(const lacksDma& ra, const char* col = "none");
- // ~lacksDma();
- // lacksDma& operator=(const lacksDma& rs);
- // void View() const;
- //};
- //
- //AbsDma::AbsDma(const char* l, int r)
- //{
- // int size = strlen(l);
- // label = new char[size + 1];
- // strncpy(label, l, size);
- // label[size] = '\0';
- // rating = r;
- //}
- //
- //AbsDma::~AbsDma()
- //{
- // delete[]label;
- // label = nullptr;
- //}
- //
- //AbsDma::AbsDma(const AbsDma& ra)
- //{
- // int size = strlen(ra.label);
- // label = new char[size + 1];
- // strncpy(label, ra.label, size);
- // label[size] = '\0';
- // rating = ra.rating;
- //}
- //
- //AbsDma& AbsDma::operator=(const AbsDma& ra)
- //{
- // if (this == &ra)
- // return *this;
- // delete[] label;
- // int size = strlen(ra.label);
- // label = new char[size + 1];
- // strncpy(label, ra.label, size);
- // label[size] = '\0';
- // rating = ra.rating;
- // return *this;
- //}
- //
- //baseDma::baseDma(const char *l, int r) : AbsDma(l, r)
- //{}
- //
- //baseDma::baseDma(const baseDma& rb) : AbsDma(rb)
- //{}
- //
- //baseDma::~baseDma()
- //{}
- //
- //baseDma& baseDma::operator=(const baseDma& ra)
- //{
- // if (this == &ra)
- // return *this;
- // AbsDma::operator=(ra);
- // return *this;
- //}
- //
- //void baseDma::View() const
- //{
- // cout << "Label = " << label << endl << " Rating = " << rating << endl;
- //}
- //
- //lacksDma::lacksDma(const char* col, const char* lab, int r) : AbsDma(lab, r)
- //{
- // strncpy(color, col, COL_LEN);
- // color[strlen(col)] = '\0';
- //}
- //
- //lacksDma::lacksDma(const lacksDma& ra, const char* col) : AbsDma(ra)
- //{
- // strncpy(color, col, COL_LEN);
- // color[strlen(col)] = '\0';
- //}
- //
- //lacksDma::~lacksDma()
- //{
- // color[0] = '\0';
- //}
- //
- //lacksDma& lacksDma::operator=(const lacksDma& rs)
- //{
- // if (this == &rs)
- // return *this;
- // AbsDma::operator=(rs);
- // strncpy(color, rs.color, COL_LEN);
- // color[strlen(rs.color)] = '\0';
- // return *this;
- //}
- //
- //void lacksDma::View() const
- //{
- // cout << "Label = " << label << endl << " Rating = " << rating << " Color = " << color << endl;
- //}
- //
- //hasDma::hasDma(const char* s, const char* l, int r) : AbsDma(l, r)
- //{
- // int size = strlen(s);
- // style = new char[size + 1];
- // strncpy(style, s, size);
- // style[size] = '\0';
- //}
- //
- //hasDma::hasDma(const hasDma& rh, const char* s) : AbsDma(rh)
- //{
- // int size = strlen(s);
- // style = new char[size + 1];
- // strncpy(style, s, size);
- // style[size] = '\0';
- //}
- //
- //hasDma::~hasDma()
- //{
- // delete[] style;
- // style = nullptr;
- //}
- //
- //hasDma& hasDma::operator=(const hasDma& rh)
- //{
- // if (this == &rh)
- // return *this;
- // AbsDma::operator=(rh);
- // delete[] style;;
- // int size = strlen(rh.style);
- // style = new char[size + 1];
- // strncpy(style, rh.style, size);
- // style[size] = '\0';
- // return *this;
- //}
- //
- //void hasDma::View() const
- //{
- // cout << "Label = " << label << endl << " Rating = " << rating << " Style = " << style << endl;
- //}
- //
- //void Show(const AbsDma *r)
- //{
- // r->View();
- //}
- //
- //int main()
- //{
- // baseDma shirt("Portabelly", 8), shirt2;
- // lacksDma balloon("red", "Blimpo", 4), balloon2;
- // hasDma map("Mercerator", "Buffalo Keys", 5), map2;
- //
- // cout << "\n-----------------------------Basic--------------------------------------\n";
- //
- // shirt.View();
- // balloon.View();
- // map.View();
- //
- // cout << "\n---------------------------------Second----------------------------------\n";
- //
- // shirt2.View();
- // balloon2.View();
- // map2.View();
- //
- // cout << "\n-------------------------------Dorivnie-----------------------------------\n";
- //
- // shirt2 = shirt;
- // balloon2 = balloon;
- // map2 = map;
- //
- // shirt2.View();
- // balloon2.View();
- // map2.View();
- //
- // cout << "\n-------------------------------Pointer--------------------------------\n";
- //
- // AbsDma * PA[3] = { &shirt, &balloon, &map };
- // for (int i = 0; i < 3; ++i)
- // PA[i]->View();
- //
- // cout << "\n-------------------------------Function-------------------------------\n";
- //
- // for (int i = 0; i < 3; ++i)
- // Show(PA[i]);
- //
- // cout << "\n----------------------------------Pointer 2---------------------------\n";
- //
- // AbsDma* pAbs[3];
- //
- // pAbs[0] = new baseDma("Portabelly", 8);
- // pAbs[1] = new lacksDma("red", "Blimpo", 4);
- // pAbs[2] = new hasDma("Mercerator", "Buffalo Keys", 5);
- //
- // for (int i = 0; i < 3; ++i)
- // pAbs[i]->View();
- //
- // cout << "\n-------------------------------------End------------------------------\n";
- //
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //#define _crt_secure_no_warnings
- //#pragma warning(disable:4996)
- //
- //class Port
- //{
- // char* brand;
- // char style[20];
- // int bottles;
- //public:
- // Port(const char* br = "none", const char* st = "none", int bot = 0);
- // Port(const Port& p);
- // virtual ~Port();
- // Port& operator=(const Port& p);
- // Port& operator+=(int b);
- // Port& operator-=(int b);
- // int BottleCount() const;
- // virtual void Show() const;
- // friend ostream& operator<<(ostream& os, const Port& p);
- //};
- //
- //class VintagePort : public Port
- //{
- // char* nickname;
- // int year;
- //public:
- // VintagePort();
- // VintagePort(const char* br, int b, const char* nn = "none", int y = 0);
- // VintagePort(const VintagePort& vp);
- // ~VintagePort();
- // VintagePort& operator=(const VintagePort& vp);
- // void Show() const;
- // friend ostream& operator<<(ostream& os, const VintagePort& vp);
- //};
- //
- //Port::Port(const char* br, const char* st, int bot)
- //{
- // int size = strlen(br);
- // brand = new char[size + 1];
- // strncpy(brand, br, size);
- // brand[size] = '\0';
- // strncpy(style, st, 20);
- // style[strlen(st)] = '\0';
- // bottles = bot;
- //}
- //
- //Port::Port(const Port& p)
- //{
- // int size = strlen(p.brand);
- // brand = new char[size + 1];
- // strncpy(brand, p.brand, size);
- // brand[size] = '\0';
- // strncpy(style, p.style, 20);
- // style[strlen(p.style)] = '\0';
- // bottles = p.bottles;
- //}
- //
- //Port::~Port()
- //{
- // delete[] brand;
- // brand = nullptr;
- // style[0] = '\0';
- // bottles = 0;
- //}
- //
- //Port& Port::operator=(const Port& p)
- //{
- // if (this == &p)
- // return *this;
- // delete[] brand;
- // int size = strlen(p.brand);
- // brand = new char[size + 1];
- // strncpy(brand, p.brand, size);
- // brand[size] = '\0';
- // strncpy(style, p.style, 20);
- // style[strlen(p.style)] = '\0';
- // bottles = p.bottles;
- // return *this;
- //}
- //
- //int Port::BottleCount() const
- //{
- // return bottles;
- //}
- //
- //void Port::Show() const
- //{
- // cout << endl;
- // cout << "Brand : " << brand << endl;
- // cout << "Kind : " << style << endl;
- // cout << "Bottles : " << bottles << endl;
- //}
- //
- //ostream& operator<<(ostream& os, const Port& p)
- //{
- // os << endl << p.brand << ", " << p.style << ", " << p.bottles;
- // return os;
- //}
- //
- //Port& Port::operator+=(int b)
- //{
- // bottles += b;
- // return *this;
- //}
- //
- //Port& Port::operator-=(int b)
- //{
- // bottles -= b;
- // return *this;
- //}
- //
- //VintagePort::VintagePort() : Port()
- //{
- // nickname = new char[1];
- // nickname[0] = '\0';
- // year = 0;
- //}
- //
- //VintagePort::VintagePort(const char* br, int b, const char* nn, int y) : Port(br, "vintage", b)
- //{
- // int size = strlen(nn);
- // nickname = new char[size + 1];
- // strncpy(nickname, nn, size);
- // nickname[size] = '\0';
- // year = y;
- //}
- //
- //VintagePort::VintagePort(const VintagePort& vp) : Port(vp)
- //{
- // int size = strlen(vp.nickname);
- // nickname = new char[size + 1];
- // strncpy(nickname, vp.nickname, size);
- // nickname[size] = '\0';
- // year = vp.year;
- //}
- //
- //VintagePort::~VintagePort()
- //{
- // delete[] nickname;
- // nickname = nullptr;
- //}
- //
- //VintagePort& VintagePort::operator=(const VintagePort& vp)
- //{
- // if (this == &vp)
- // return *this;
- // Port::operator=(vp);
- // delete[] nickname;
- // int size = strlen(vp.nickname);
- // nickname = new char[size + 1];
- // strncpy(nickname, vp.nickname, size);
- // nickname[size] = '\0';
- // year = vp.year;
- // return *this;
- //}
- //
- //void VintagePort::Show() const
- //{
- // Port::Show();
- // cout << "Nickname : " << nickname << endl;
- // cout << "Year : " << year << endl;
- //}
- //
- //ostream& operator<<(ostream& os, const VintagePort& vp)
- //{
- // os << dynamic_cast<const Port&>(vp);
- // os << ", " << vp.nickname << ", " << vp.year;
- // return os;
- //}
- //
- //int main()
- //{
- // Port A("Alfa", "tawny", 5);
- // cout << A << endl;
- // A.Show();
- // Port B;
- // cout << B;
- // B.Show();
- // B = A;
- // cout << B;
- // B.Show();
- // VintagePort C("Bravo", 7, "The noble", 1934);
- // cout << C << endl;
- // C.Show();
- // VintagePort D;
- // cout << D;
- // D.Show();
- // D = C;
- // cout << D;
- // D.Show();
- //
- // cout << endl << endl << endl << endl << endl;
- //
- // A = C;
- // cout << A;
- //
- // cout << endl << endl << endl << endl << endl;
- //
- //
- // B += 5;
- // cout << B;
- // B -= 3;
- // cout << B;
- //
- // C += 4;
- // cout << C;
- // C -= 2;
- // cout << C;
- //
- //
- // return 0;
- //}
- //#include <iostream>
- //using std::cout;
- //struct Triangle
- //{
- // double length = 2.0; // нестатическая инициализация членов
- // double width = 2.0;
- //};
- //
- //int main()
- //{
- // Triangle z{ 3.0, 3.0 }; // uniform-инициализация
- // Triangle p;
- // cout << z.length << "\t" << z.width << std::endl;
- // cout << p.length << "\t" << p.width << std::endl;
- // return 0;
- //
- // struct Employee
- // {
- // short id;
- // int age;
- // double salary;
- // };
- //
- // Employee john;
- // john = { 5, 27, 45000.0 }; // только C++11
- //}
- //#include <iostream>
- //
- //using std::cin;
- //using std::cout;
- //using std::endl;
- //
- //int getNum()
- //{
- // int x;
- // while (true)
- // {
- // cin >> x;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Enter another num: ";
- // }
- // else if (x < 0)
- // {
- // cout << "Bad input. Enter another num: ";
- // }
- // else
- // return x;
- // }
- //}
- //
- //char getChoice()
- //{
- // char ch;
- // while (true)
- // {
- // cin >> ch;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Enter another char: ";
- // }
- // else if (ch != 'q' && ch != 'c')
- // cout << "Enter another char: ";
- // else
- // return ch;
- // }
- //}
- //
- //void beatNum(int num)
- //{
- // int x = num;
- // int count = 1;
- // while (x > 10)
- // {
- // x /= 10;
- // ++count;
- // }
- // int* arr = new int[count];
- // for (int i = count - 1; i >= 0; --i)
- // {
- // arr[i] = num % 10;
- // num /= 10;
- // }
- // for (int i = 0; i < count; ++i)
- // cout << i + 1 << " num = " << arr[i] << endl;
- //}
- //
- //int main()
- //{
- // char choice = 'c';
- // while (choice == 'c')
- // {
- // cout << "Enter the num: ";
- // int num = getNum();
- // cout << "Your num = " << num << endl;
- // beatNum(num);
- // cout << "Enter 'q' to quit or 'c' to continue: ";
- // choice = getChoice();
- // cout << "Your ch = " << choice << endl;
- // }
- //
- // return 0;
- //}
- //
- //#include <iostream>
- //using namespace std;
- //
- //void getValues(int& a, int& b, int& f)
- //{
- // while (true)
- // {
- // cout << "Enter a, b and f";
- // cin >> a >> b >> f;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Re-enter the numbers: ";
- // }
- // else
- // break;
- // }
- //}
- //
- //int formula(const int& a, const int& b, const int& f)
- //{
- // return (a + b - f / a) + f * a * a - (a + b);
- //}
- //
- //int main()
- //{
- // int a, b, f;
- // getValues(a, b, f);
- // cout << "x = (a + b - f / a) + f * a * a - (a + b) = ";
- // cout << formula(a, b, f);
- //}
- //#include <iostream>
- //#include <cctype>
- //using namespace std;
- //char getChar()
- //{
- // char ch;
- // cout << "Enter char: ";
- // while (true)
- // {
- // cin >> ch;
- // cin.ignore(32767, '\n');
- // if (!isalpha(ch))
- // cout << "Bad input. ";
- // else
- // return ch;
- // }
- //}
- //int main()
- //{
- // char ch = getChar();
- // cout << static_cast<char>(toupper(ch));
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //float getMetres()
- //{
- // float val;
- // cout << "Enter m: ";
- // while (true)
- // {
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Enter again: ";
- // }
- // else if (val < 0)
- // cout << "Bad input. Only > 0 : ";
- // else
- // return val;
- // }
- //}
- //float mToK(float m)
- //{
- // return m / 1000;
- //}
- //int main()
- //{
- // float m = getMetres();
- // float k = mToK(m);
- // cout << m << " = " << k;
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //using namespace std;
- //
- //int main()
- //{
- // string name, surname, fathername;
- // cout << "Enter name = ";
- // cin >> name;
- // cout << "Enter surname = ";
- // cin >> surname;
- // cout << "Enter fathername = ";
- // cin >> fathername;
- // int size = name.size() + surname.size() + fathername.size();
- // for (int i = 0; i < size + 6; ++i)
- // cout << "*";
- // cout << endl << "* " << name << " " << surname << " " << fathername << " *" << endl;
- // for (int i = 0; i < size + 6; ++i)
- // cout << "*";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int val = 0;
- // cout << "Enter num: ";
- // while (true)
- // {
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else
- // return val;
- // }
- //}
- //
- //void compareNums(const int x, const int y)
- //{
- // if (x > y)
- // cout << " X > Y ";
- // else if (x < y)
- // cout << " X < Y ";
- // else
- // cout << " X == Y ";
- //}
- //
- //int main()
- //{
- // int x = getNum();
- // int y = getNum();
- // compareNums(x, y);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getnum()
- //{
- // int val = 0;
- // cout << "enter num: ";
- // while (true)
- // {
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "bad input. ";
- // }
- // else
- // return val;
- // }
- //}
- //
- //void changeNums(int& x, int& y, int& z, const int n)
- //{
- // x += n;
- // y += n;
- // z += n;
- //}
- //
- //int main()
- //{
- // int x = getnum();
- // int y = getnum();
- // int z = getnum();
- // int n = getnum();
- //
- // if (x == y || y == z || x == z)
- // {
- // changeNums(x, y, z, n);
- // cout << x << " " << y << " " << z << " " << endl;
- // }
- // else
- // cout << "no equal";
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNumOfX()
- //{
- // int val = -1;
- // while (true)
- // {
- // cout << "Enter the num of X: ";
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else if (val < 1)
- // cout << "Only > 0";
- // else
- // return val;
- // }
- //}
- //
- //double getNums()
- //{
- // double val = 0.0;
- // while (true)
- // {
- // cout << "Enter the nums: ";
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else
- // return val;
- // }
- //}
- //
- //void calcX(double* x, double* Z, double* B, double* A, double* betta, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // x[i] = Z[i] * Z[i] * Z[i] - B[i] + (A[i] * A[i]) / (tan(betta[i]) * tan(betta[i]));
- //}
- //
- //double calcY(double* x, int size)
- //{
- // double sum = 0.0;
- // for (int i = 0; i < size; ++i)
- // sum += x[i];
- // return sum;
- //}
- //
- //void getArr(double* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // arr[i] = getNums();
- //}
- //
- //int main()
- //{
- // int size = getNumOfX();
- // double* x = new double[size];
- // double* Z = new double[size];
- // getArr(Z, size);
- // double* B = new double[size];
- // getArr(B, size);
- // double* A = new double[size];
- // getArr(A, size);
- // double* betta = new double[size];
- // getArr(betta, size);
- // calcX(x, Z, B, A, betta, size);
- // double y = calcY(x, size);
- // cout << endl << " Y = " << y;
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int val = -1;
- // while (true)
- // {
- // cout << "Enter the num: ";
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else if (val < 1)
- // cout << "Only > 0";
- // else
- // return val;
- // }
- //}
- //
- //float calc(int k, int N)
- //{
- // float sum = 0.0;
- // float sum2 = 1.0;
- // for (int i = 1; i <= N; ++i)
- // {
- // sum2 = 1.0;
- // for (int j = 1; j <= k; ++j)
- // sum2 *= i;
- // sum += sum2;
- // }
- // return sum;
- //}
- //
- //int main()
- //{
- // int k = getNum();
- // int N = getNum();
- // float result = calc(k, N);
- // cout << result;
- // return 0;
- //}
- //
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int val = 0;
- // while (true)
- // {
- // cout << "Enter the nums: ";
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else
- // return val;
- // }
- //}
- //
- //void find(int& max, int& min, int num)
- //{
- // int x = max = min = num % 10;
- // while (num > 10)
- // {
- // num /= 10;
- // x = num % 10;
- // if (min > x)
- // min = x;
- // else if (max < x)
- // max = x;
- // }
- //}
- //
- //int main()
- //{
- // int num = getNum();
- // int min, max;
- // find(max, min, num);
- // cout << "Max = " << max << " min = " << min;
- // return 0;
- //}
- //
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cout << "Enter num: ";
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else if (num < 0)
- // cout << "Only > 0";
- // else
- // return num;
- // }
- //}
- //
- //bool palindrom(int num)
- //{
- // int x = num, count = 1;
- // while (x > 9)
- // {
- // x /= 10;
- // ++count;
- // }
- // cout << endl << count;
- // int* arr = new int[count] {0};
- // x = num;
- // for (int i = 0; x > 0; ++i)
- // {
- // arr[i] = x % 10;
- // x /= 10;
- // }
- //
- // for (int i = 0; i < count / 2; ++i)
- // if (arr[i] != arr[count - i - 1])
- // return false;
- // return true;
- //}
- //
- //int main()
- //{
- // int num = getNum();
- // if (palindrom(num))
- // cout << endl << "yes";
- // else
- // cout << endl << "no";
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getSize()
- //{
- // int size = 0;
- // while (true)
- // {
- // cin >> size;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Re-enter: ";
- // }
- // else if (size < 1)
- // cout << "Bad input. Re-enter: ";
- // else
- // return size;
- // }
- //
- // return size;
- //}
- //
- //float getNumForArr()
- //{
- // float val = 0.0f;
- // while (true)
- // {
- // cin >> val;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Re-enter: ";
- // }
- // else
- // return val;
- // }
- //}
- //
- //void fillArray(float* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // cout << "Enter " << i + 1 << " element: ";
- // arr[i] = getNumForArr();
- // }
- //}
- //
- //float ser(float* arr, int size)
- //{
- // float sum = 0.0f;
- // for (int i = 0; i < size; ++i)
- // sum += arr[i];
- // return sum / size;
- //}
- //
- //int main()
- //{
- // cout << "Enter the size of array: ";
- // int sizeOfArray = getSize();
- // float* arr = new float[sizeOfArray];
- // fillArray(arr, sizeOfArray);
- // cout << ser(arr, sizeOfArray);
- // return 0;
- //}
- //
- //#include <iostream>
- //using namespace std;
- //int main()
- //{
- // int num = 0;
- // cin >> num;
- // for (int i = 1; i <= 10; ++i)
- // cout << i << " * " << num << " = " << i * num << endl;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // cout << "Enter a num: ";
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //char getChoice()
- //{
- // char choice;
- // cout << "Enter your choice (q - quit, c - continue): ";
- // while (true)
- // {
- // cin >> choice;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if(choice != 'q' && choice != 'c')
- // cout << "Bad input. Try again. ";
- // else
- // return choice;
- // }
- //}
- //
- //char getOperation()
- //{
- // char operation;
- // cout << "Enter your operation (+, -, /, *): ";
- // while (true)
- // {
- // cin >> operation;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (operation != '+' && operation != '-' && operation != '*' && operation != '/')
- // cout << "Bad input. Try again. ";
- // else
- // return operation;
- // }
- //}
- //
- //int add(int x, int y)
- //{
- // return x + y;
- //}
- //
- //int subtract(int x, int y)
- //{
- // return x - y;
- //}
- //
- //int multiply(int x, int y)
- //{
- // return x * y;
- //}
- //
- //int divide(int x, int y)
- //{
- // return x / y;
- //}
- //
- //typedef int (*arithmeticFcn)(int x, int y);
- //
- //arithmeticFcn getArithmeticFcn(char operation)
- //{
- // switch (operation)
- // {
- // case '+': return add;
- // case '-': return subtract;
- // case '*': return multiply;
- // case '/': return divide;
- // }
- //}
- //
- //int main()
- //{
- // char choice = 'c', operation;
- // int x, y;
- // choice = getChoice();
- //
- // while (choice != 'q')
- // {
- // x = getNum();
- // y = getNum();
- // operation = getOperation();
- // arithmeticFcn fptr = getArithmeticFcn(operation);
- // cout << fptr(x, y) << endl;
- // choice = getChoice();
- // }
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // cout << "Enter a num: ";
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //char getChoice()
- //{
- // char choice;
- // cout << "Enter your choice (q - quit, c - continue): ";
- // while (true)
- // {
- // cin >> choice;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if(choice != 'q' && choice != 'c')
- // cout << "Bad input. Try again. ";
- // else
- // return choice;
- // }
- //}
- //
- //char getOperation()
- //{
- // char operation;
- // cout << "Enter your operation (+, -, /, *): ";
- // while (true)
- // {
- // cin >> operation;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (operation != '+' && operation != '-' && operation != '*' && operation != '/')
- // cout << "Bad input. Try again. ";
- // else
- // return operation;
- // }
- //}
- //
- //int add(int x, int y)
- //{
- // return x + y;
- //}
- //
- //int subtract(int x, int y)
- //{
- // return x - y;
- //}
- //
- //int multiply(int x, int y)
- //{
- // return x * y;
- //}
- //
- //int divide(int x, int y)
- //{
- // return x / y;
- //}
- //
- //typedef int (*arithmeticFcn)(int x, int y);
- //
- //struct arithmeticStruct
- //{
- // char oper;
- // arithmeticFcn fptr;
- //};
- //
- //const arithmeticStruct arithmeticArr[4] { {'+', add}, {'-', subtract}, {'*', multiply}, {'/', divide} };
- //
- //arithmeticFcn getArithmeticFcn(char operation)
- //{
- // for (auto &x : arithmeticArr)
- // if (x.oper == operation)
- // return x.fptr;
- //}
- //
- //int main()
- //{
- // char choice = 'c', operation;
- // int x, y;
- // choice = getChoice();
- //
- // while (choice != 'q')
- // {
- // x = getNum();
- // y = getNum();
- // operation = getOperation();
- // arithmeticFcn fptr = getArithmeticFcn(operation);
- // cout << fptr(x, y) << endl;
- // choice = getChoice();
- // }
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //using namespace std;
- //
- //int main()
- //{
- // ifstream fin;
- // fin.open("in.txt");
- // if (!fin.is_open())
- // exit(1);
- // char ch;
- // int c1{ 0 }, c2{ 0 };
- // while (!fin.eof())
- // {
- // ch = fin.get();
- // if (ch == '{')
- // ++c1;
- // else if (ch == '}')
- // ++c2;
- // }
- // if (c1 == c2)
- // cout << "YES";
- // else
- // cout << "NO";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again: ";
- // }
- // else if (num < 1 || num > 10)
- // cout << "Only > 0 && < 10, try again: ";
- // else
- // return num;
- // }
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again: ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //int** creatreMatrix(int rows, int cols)
- //{
- // int** matrix = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // *(matrix + i) = new int[cols];
- // return matrix;
- //}
- //
- //int* createVector(int size)
- //{
- // int* vec = new int[size];
- // return vec;
- //}
- //
- //void fillMatrix(int** matrix, int rows, int cols)
- //{
- // for(int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // {
- // cout << "Enter [" << i << "][" << j << "] = ";
- // *(*(matrix + i) + j) = getNum();
- // }
- //}
- //
- //void fillVector(int* vec, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // cout << "Enter [" << i << "] = ";
- // *(vec + i) = getNum();
- // }
- //}
- //
- //void printMatrix(int** matrix, int rows, int cols)
- //{
- // for (int i = 0; i < rows; ++i)
- // {
- // for (int j = 0; j < cols; ++j)
- // cout << *(*(matrix + i) + j) << " ";
- // cout << endl;
- // }
- // cout << endl;
- //}
- //
- //void printVector(const int* vec, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << *(vec + i) << " ";
- // cout << endl << endl;
- //}
- //
- //int* calcResultVector(int** matrix, int* vec, int rows, int cols)
- //{
- // int* res = createVector(rows);
- // for (int i = 0; i < rows; ++i)
- // {
- // int sum = 0;
- // for (int j = 0; j < cols; ++j)
- // sum += *(*(matrix + i) + j) * *(vec + j);
- // *(res + i) = sum;
- // }
- // return res;
- //}
- //
- //int findMax(int* vec, int rows)
- //{
- // int max = vec[0];
- // for (int i = 0; i < rows; ++i)
- // if (*(vec + i) > max)
- // max = *(vec + i);
- // return max;
- //}
- //
- //void freeVec(int* vec)
- //{
- // delete[] vec;
- // vec = nullptr;
- //}
- //
- //void freeMatrix(int** matrix, int rows)
- //{
- // for (int i = 0; i < rows; ++i)
- // delete[]matrix[i];
- // delete[] matrix;
- // matrix = nullptr;
- //}
- //
- //int main()
- //{
- // cout << "Enter the number of rows: ";
- // int rows = getSize();
- //
- // cout << "Enter the number of columns: ";
- // int cols = getSize();
- //
- // int** matrix = creatreMatrix(rows, cols);
- // cout << "Now enter these elements: " << endl;
- // fillMatrix(matrix, rows, cols);
- //
- // int* vec = createVector(cols);
- // cout << "Now enter the elements of vector: " << endl;
- // fillVector(vec, cols);
- //
- // printMatrix(matrix, rows, cols);
- // printVector(vec, cols);
- //
- // int* resultVec = createVector(rows);
- // resultVec = calcResultVector(matrix, vec, rows, cols);
- //
- // printVector(resultVec, rows);
- //
- // int max = findMax(resultVec, rows);
- // cout << "Max = " << max;
- //
- // freeVec(vec);
- // freeVec(resultVec);
- // freeMatrix(matrix, rows);
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // cout << "Enter a num: ";
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again: ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //void copyArr(int* source, int* target, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // target[i] = source[i];
- //}
- //
- //void print(const int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << arr[i] << " ";
- // cout << endl;
- //}
- //
- //int main()
- //{
- // size_t size = 1;
- // int* arr = new int[size];
- // int temp;
- // temp = getNum();
- // arr[0] = temp;
- // print(arr, size);
- //
- //
- // while ((temp = getNum()) >= 0)
- // {
- // int* tempArr = new int[size];
- // copyArr(arr, tempArr, size);
- // delete[] arr;
- // arr = new int[size + 1];
- // copyArr(tempArr, arr, size);
- // delete[] tempArr;
- // arr[size] = temp;
- // ++size;
- // print(arr, size);
- // }
- //
- // delete [] arr;
- // return 0;
- //}
- //
- //
- //
- //
- //#include <iostream>
- //#include <string>
- //using namespace std;
- //
- //struct human
- //{
- // int age;
- // string name;
- //};
- //
- //int getAge()
- //{
- // int num { 0 };
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore();
- // cout << "Bad input. Try again: ";
- // }
- // else if (num < 0)
- // cout << "Only n>=0. Try again: ";
- // else
- // return num;
- // }
- //}
- //
- //int getChoice()
- //{
- // int num{ 0 };
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore();
- // cout << "Bad input. Try again: ";
- // }
- // else if (num != 1 && num != 0)
- // cout << "Only 0or1. Try again: ";
- // else
- // return num;
- // }
- //}
- //
- //human getInfo()
- //{
- // human temp;
- // cout << "Enter the age: ";
- // temp.age = getAge();
- // cout << "Enter the name: ";
- // cin >> temp.name;
- // return temp;
- //}
- //
- //void copyHuman(human* source, human* target, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // target[i] = source[i];
- //}
- //
- //void showInfo(human* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << i << " element : " << arr[i].name << " " << arr[i].age << endl;
- //}
- //
- //int main()
- //{
- // int size = 1;
- // human* humanArr = new human[size];
- // humanArr[0] = getInfo();
- // int choice = 1;
- // cout << "Enter another info - 1, exit - 0";
- //
- // while ((choice = getChoice()) == 1)
- // {
- // human* tempHuman = new human[size];
- // copyHuman(humanArr, tempHuman, size);
- // delete[] humanArr;
- // humanArr = new human[size + 1];
- // copyHuman(tempHuman, humanArr, size);
- // humanArr[size] = getInfo();
- // ++size;
- // delete[] tempHuman;
- // showInfo(humanArr, size);
- // cout << "Enter another info - 1, exit - 0";
- // }
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //double getNum()
- //{
- // double num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again: ";
- // }
- // else if (num < 0.0)
- // cout << "Only > 0";
- // else
- // return num;
- // }
- //}
- //
- //const double eps = 0.0001;
- //
- //double squareRoot(double x)
- //{
- // double Y1 = x;
- // double Y2 = 0.5 * (Y1 + (3.0 * x) / (2.0 * Y1 * Y1 + x / Y1));
- // while (abs(Y2 - Y1) > eps)
- // {
- // Y1 = Y2;
- // Y2 = 0.5 * (Y1 + (3.0 * x) / (2.0 * Y1 * Y1 + x / Y1));
- // }
- // return Y2;
- //}
- //
- //int main()
- //{
- // cout << "Enter x : ";
- // double x = getNum();
- // cout << "Square root " << squareRoot(x);
- // return 0;
- //}
- //#include <iostream>
- //#include <cctype>
- //using namespace std;
- //
- //char getChoice()
- //{
- // char choice;
- // cout << "Enter your choice: ";
- // while (true)
- // {
- // cin >> choice;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again : ";
- // }
- // else if (choice != '1' && choice != '2' && choice != '3' && choice != '4'
- // && choice != '5' && choice != 'f')
- // cout << "Only 1, 2, 3, 4, 5 or f. Try again : ";
- // else
- // return choice;
- // }
- //}
- //
- //void showMenu()
- //{
- // cout << "To convert a string to capital letters press: 1" << endl <<
- // "To convert a string to lowercase nf press : 2" << endl <<
- // "To convert a string with a Capital Letter press : 3" << endl <<
- // "To convert the string to the first lowercase character press : 4" << endl <<
- // "To convert a string as in a normal sentence, press : 5" << endl <<
- // "To exit press : f" << endl;
- //}
- //
- //void toUp(const char* str, int size)
- //{
- // cout << endl << endl;
- // for (int i = 0; i < size; ++i)
- // cout.put(toupper(str[i]));
- // cout << endl << endl;
- //}
- //
- //void toDown(const char* str, int size)
- //{
- // cout << endl << endl;
- // for (int i = 0; i < size; ++i)
- // cout.put(tolower(str[i]));
- // cout << endl << endl;
- //}
- //
- //void toFirstUp(const char* str, int size)
- //{
- // cout << endl << endl;
- // cout.put(toupper(str[0]));
- // for (int i = 1; i < size; ++i)
- // {
- // if (str[i - 1] == ' ' && str[i] != ' ')
- // cout.put(toupper(str[i]));
- // else
- // cout.put(tolower(str[i]));
- // }
- // cout << endl << endl;
- //}
- //
- //void toFirstLower(const char* str, int size)
- //{
- // cout << endl << endl;
- // cout.put(tolower(str[0]));
- // for (int i = 1; i < size; ++i)
- // {
- // if (str[i - 1] == ' ' && str[i] != ' ')
- // cout.put(tolower(str[i]));
- // else
- // cout.put(toupper(str[i]));
- // }
- // cout << endl << endl;
- //}
- //
- //void toNormal(const char* str, int size)
- //{
- // cout << endl << endl;
- // for (int i = 0; i < size; ++i)
- // cout.put(str[i]);
- // cout << endl << endl;
- //}
- //
- //int main()
- //{
- // const int size{ 255 };
- // char str[size]{};
- // int sizeOfStr = 0;
- // cout << "Enter the string: ";
- // while ((str[sizeOfStr] = cin.get()) != '\n' && sizeOfStr < size)
- // ++sizeOfStr;
- // str[sizeOfStr] = '\0';
- // char choice = '1';
- // while (choice != 'f')
- // {
- // showMenu();
- // choice = getChoice();
- // switch (choice)
- // {
- // case '1': toUp(str, sizeOfStr); break;
- // case '2': toDown(str, sizeOfStr); break;
- // case '3': toFirstUp(str, sizeOfStr); break;
- // case '4': toFirstLower(str, sizeOfStr); break;
- // case '5': toNormal(str, sizeOfStr); break;
- // case 'f': break;
- // }
- // }
- // return 0;
- //}
- //#include <iostream>
- //#include <ctime>
- //#include <cstdlib>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again: ";
- // }
- // else if (num < 0)
- // cout << "Only > 0";
- // else
- // return num;
- // }
- //}
- //
- //double** allocMemory(const int size)
- //{
- // double** arr = new double* [size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = new double[size];
- // return arr;
- //}
- //
- //void fillArray(double** arr, const int size, const int left, const int right)
- //{
- // srand(static_cast<unsigned int>(time(0)));
- // for (int i = 0; i < size; ++i)
- // {
- // for (int j = 0; j < size; ++j)
- // arr[i][j] = ((left * 1000) + (rand() % ((right - left) * 1000))) / 1000.0;
- // }
- //}
- //
- //void showArray(double** arr, const int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // for (int j = 0; j < size; ++j)
- // cout << arr[i][j] << "\t";
- // cout << endl;
- // }
- //}
- //
- //int findMax(double** arr, int size, double &min)
- //{
- // min = arr[0][0];
- // int index = 0;
- // for (int i = 0; i < size; ++i)
- // for (int j = 0; j < size; ++j)
- // if (arr[i][j] < min)
- // {
- // min = arr[i][j];
- // index = i;
- // }
- // return index;
- //}
- //
- //void showMin(double min, int minIndex)
- //{
- // cout << endl << "Number of row with min num = " << minIndex;
- // cout << endl << "Min element = " << min << endl << endl;
- //}
- //
- //void swapRows(double** arr, int first, int second)
- //{
- // double* temp = arr[first];
- // arr[first] = arr[second];
- // arr[second] = temp;
- //}
- //
- //int main()
- //{
- // cout << "Enter a : ";
- // int a = getNum();
- // cout << "Enter b : ";
- // int b = getNum();
- // if (a > b)
- // swap(a, b);
- // const int size = 10;
- // double** arr = allocMemory(size);
- // fillArray(arr, size, a, b);
- // showArray(arr, size);
- // double min;
- // int minIndex = findMax(arr, size, min);
- // showMin(min, minIndex);
- // swapRows(arr, 0, minIndex);
- // showArray(arr, size);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (num < 1)
- // cout << "Bad input. Try again. ";
- // else
- // return num;
- // }
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //int** createMatrix(int rows, int cols)
- //{
- // int** arr = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // arr[i] = new int[cols];
- // return arr;
- //}
- //
- //void fillMatrix(int** arr, int rows, int cols)
- //{
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // {
- // cout << "Enter [" << i << "][" << j << "] = ";
- // arr[i][j] = getNum();
- // }
- //}
- //
- //void copyArr(int** source, int* target, int rows, int cols)
- //{
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // target[i * cols + j] = source[i][j];
- //}
- //
- //void showArr(int** arr, int rows, int cols)
- //{
- // for (int i = 0; i < rows; ++i)
- // {
- // for (int j = 0; j < cols; ++j)
- // cout << arr[i][j] << " ";
- // cout << endl;
- // }
- //}
- //
- //void showArr(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << arr[i] << " ";
- // cout << endl;
- //}
- //
- //void deleteArr(int** arr, int rows)
- //{
- // for (int i = 0; i < rows; ++i)
- // {
- // delete[]arr[i];
- // arr[i] = nullptr;
- // }
- // delete[]arr;
- // arr = nullptr;
- //}
- //
- //void deleteArr(int* arr)
- //{
- // delete[]arr;
- // arr = nullptr;
- //}
- //
- //int main()
- //{
- // cout << "Enter the num of rows: ";
- // int rows = getSize();
- // cout << "Enter the num of cols: ";
- // int cols = getSize();
- // cout << "Now fill the matrix: ";
- // int ** arr = createMatrix(rows, cols);
- // fillMatrix(arr, rows, cols);
- // int* newArr = new int[rows * cols];
- // copyArr(arr, newArr, rows, cols);
- // showArr(arr, rows, cols);
- // showArr(newArr, rows * cols);
- // deleteArr(arr, rows);
- // deleteArr(newArr);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getHours()
- //{
- // int h;
- // while (true)
- // {
- // cin >> h;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again : ";
- // }
- // else if (h > 23|| h < 0)
- // cout << "Bad input. Try again : ";
- // else
- // return h;
- // }
- //}
- //
- //int getMinutesOrSeconds()
- //{
- // int h;
- // while (true)
- // {
- // cin >> h;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again : ";
- // }
- // else if (h > 59 || h < 0)
- // cout << "Bad input. Try again : ";
- // else
- // return h;
- // }
- //}
- //
- //int getSecondsForMinus()
- //{
- // int h;
- // while (true)
- // {
- // cin >> h;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again : ";
- // }
- // else if (h < 0)
- // cout << "Bad input. Try again : ";
- // else
- // return h;
- // }
- //}
- //
- //struct time
- //{
- // int hours;
- // int minutes;
- // int seconds;
- //};
- //
- //void calculateRestOfTime(time &T, int secondsToMinus)
- //{
- // if (secondsToMinus < T.seconds)
- // T.seconds -= secondsToMinus;
- // else if ((T.seconds + T.minutes * 60) > secondsToMinus)
- // {
- // T.minutes -= secondsToMinus / 60;
- // T.seconds -= secondsToMinus % 60;
- // }
- // else
- // {
- // int total = T.hours * 3600 + T.minutes * 60 + T.seconds;
- // total -= secondsToMinus;
- // T.seconds = total % 60;
- // T.minutes = total / 60;
- // T.hours = T.minutes / 60;
- // T.minutes = T.minutes % 60;
- // }
- //}
- //
- //void showTime(time T)
- //{
- // cout << T.hours << ":" << T.minutes << ":" << T.seconds << endl;
- //}
- //
- //int minusTimeBetweenPeriods(time T1, time T2)
- //{
- // int t1 = T1.hours * 3600 + T1.minutes * 60 + T1.seconds;
- // int t2 = T2.hours * 3600 + T2.minutes * 60 + T2.seconds;
- // return abs(t2 - t1);
- //}
- //
- //int main()
- //{
- // time T;
- // cout << "Enter the time\n>>Enter hours: ";
- // T.hours = getHours();
- // cout << "Enter minutes: ";
- // T.minutes = getMinutesOrSeconds();
- // cout << "Enter seconds: ";
- // T.seconds = getMinutesOrSeconds();
- // cout << "Your time: ";
- // showTime(T);
- // cout << "Enter seconds to minus: ";
- // int secondsToMinus = getSecondsForMinus();
- // calculateRestOfTime(T, secondsToMinus);
- // cout << "Your new time: ";
- // showTime(T);
- //
- //
- // time T1;
- // cout << "Enter the time\n>>Enter hours: ";
- // T1.hours = getHours();
- // cout << "Enter minutes: ";
- // T1.minutes = getMinutesOrSeconds();
- // cout << "Enter seconds: ";
- // T1.seconds = getMinutesOrSeconds();
- // cout << "Your time: ";
- // showTime(T1);
- //
- // time T2;
- // cout << "Enter the time\n>>Enter hours: ";
- // T2.hours = getHours();
- // cout << "Enter minutes: ";
- // T2.minutes = getMinutesOrSeconds();
- // cout << "Enter seconds: ";
- // T2.seconds = getMinutesOrSeconds();
- // cout << "Your time: ";
- // showTime(T2);
- //
- // int res = minusTimeBetweenPeriods(T1, T2);
- // cout << "Num of seconds between this periods: " << res;
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //#include <string>
- //using namespace std;
- //
- //class Worker
- //{
- // string name;
- // int experience;
- // int salaryPerHour;
- // int workHours;
- //public:
- // Worker();
- // Worker(string name_, int experience_, int salaryPerHour_, int workHours_);
- // ~Worker();
- // friend istream& operator>>(istream& is, Worker &Man);
- // friend ostream& operator<<(ostream& os, const Worker &Man);
- // friend ofstream& operator<<(ofstream& ofs, const Worker &Man);
- // float calcPremium() const;
- // float calcSalary() const;
- //};
- //
- //Worker::Worker()
- //{
- // name = "none";
- // experience = salaryPerHour = workHours = 0;
- //}
- //
- //Worker::Worker(string name_, int experience_, int salaryPerHour_, int workHours_)
- //{
- // name = name_;
- // experience = experience_;
- // salaryPerHour = salaryPerHour_;
- // workHours = workHours_;
- //}
- //
- //Worker::~Worker()
- //{
- // name = "none";
- // experience = salaryPerHour = workHours = 0;
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (num < 0)
- // cout << "Only > 0 . Try again. ";
- // else
- // return num;
- // }
- //}
- //
- //float Worker::calcSalary() const
- //{
- // return salaryPerHour * workHours;
- //}
- //
- //float Worker::calcPremium() const
- //{
- // float res = 0;
- // if (experience < 1)
- // res = 0.0f;
- // else if (experience < 3)
- // res = 0.05f;
- // else if (experience < 5)
- // res = 0.08f;
- // else
- // res = 0.15f;
- // return res * calcSalary();
- //}
- //
- //istream& operator>>(istream& is, Worker &Man)
- //{
- // cout << "Enter worker's name: ";
- // is >> Man.name;
- // cout << "Enter worker's experience: ";
- // Man.experience = getNum();
- // cout << "Enter worker's hourly wag: ";
- // Man.salaryPerHour = getNum();
- // cout << "Entre how much hours " << Man.name << " has worked: ";
- // Man.workHours = getNum();
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Worker &Man)
- //{
- // os << "Name " << Man.name << endl;
- // os << "Experience is " << Man.experience << endl;
- // os << "Hourly wage is " << Man.salaryPerHour << endl;
- // os << Man.experience << " has worked " << Man.workHours << " hours" << endl;
- // os << "Salary is " << Man.calcSalary() << endl;
- // os << "Premy is " << Man.calcPremium() << endl;
- // return os;
- //}
- //
- //ofstream& operator<<(ofstream& ofs, const Worker& Man)
- //{
- // ofs << "Name " << Man.name << endl;
- // ofs << "Experience is " << Man.experience << endl;
- // ofs << "Hourly wage is " << Man.salaryPerHour << endl;
- // ofs << Man.experience << " has worked " << Man.workHours << " hours" << endl;
- // ofs << "Salary is " << Man.calcSalary() << endl;
- // ofs << "Premy is " << Man.calcPremium() << endl;
- // return ofs;
- //}
- //
- //int main()
- //{
- // ofstream ofs;
- // ofs.open("out.txt");
- // if (ofs.fail())
- // return 1;
- // Worker Man1("Danila", 5, 100, 3000);
- // Worker Man2;
- //
- // cout << endl << Man1 << endl << endl;
- //
- // cin >> Man2;
- // cout << endl << endl << Man2 << endl;
- //
- // ofs << Man1 << endl << endl << Man2;
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getSize()
- //{
- // cout << "Enter the size of matrix: ";
- // int size;
- // while (true)
- // {
- // cin >> size;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (size < 2)
- // cout << "Only n> 1. Try again. ";
- // else
- // return size;
- // }
- //}
- //
- //int getNum()
- //{
- // int size;
- // while (true)
- // {
- // cin >> size;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else
- // return size;
- // }
- //}
- //
- //int** createArray(int size)
- //{
- // int** arr = new int* [size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = new int[size];
- // return arr;
- //}
- //
- //void findMax(int &col, int &row, int** arr, int size)
- //{
- // int max = abs(arr[0][0]);
- // for (int i = 0; i < size; ++i)
- // for (int j = 0; j < size; ++j)
- // if (abs(arr[i][j]) > max)
- // {
- // max = abs(arr[i][j]);
- // row = i;
- // col = j;
- // }
- //}
- //
- //void fillMatrix(int** arr, int size)
- //{
- // for(int i = 0; i < size; ++i)
- // for (int j = 0; j < size; ++j)
- // {
- // cout << "Enter [" << i << "][" << j << "] = ";
- // arr[i][j] = getNum();
- // }
- //}
- //
- //void showMatrix(int** arr, int size)
- //{
- // cout << endl << endl;
- // for (int i = 0; i < size; ++i)
- // {
- // for (int j = 0; j < size; ++j)
- // cout << arr[i][j] << " ";
- // cout << endl;
- // }
- //}
- //
- //void swapRowsAndCols(int** arr, int col, int row, int size)
- //{
- // if (row != (size - 1))
- // {
- // int* temp = arr[size - 1];
- // arr[size - 1] = arr[row];
- // arr[row] = temp;
- // temp = nullptr;
- // }
- //
- // showMatrix(arr, size);
- //
- // if (col != (size - 1))
- // for (int i = 0; i < size; ++i)
- // {
- // int temp = arr[i][size - 1];
- // arr[i][size - 1] = arr[i][col];
- // arr[i][col] = temp;
- // }
- //}
- //
- //void deleteMatrix(int** arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // delete[] arr[i];
- // arr[i] = nullptr;
- // }
- // delete [] arr;
- // arr = nullptr;
- //}
- //
- //int main()
- //{
- // int size = getSize();
- // int row = 0, col = 0;
- // int** arr = createArray(size);
- // fillMatrix(arr, size);
- // showMatrix(arr, size);
- // findMax(col, row, arr, size);
- // swapRowsAndCols(arr, col, row, size);
- // showMatrix(arr, size);
- // deleteMatrix(arr, size);
- // return 0;
- //}
- //#include <iostream>
- //#include <cstdlib>
- //#include <ctime>
- //
- //using namespace std;
- //
- //int getStr(char *str)
- //{
- // int count = 0;
- // char ch;
- // while ((ch = cin.get()) != '\n')
- // str[count++] = ch;
- // str[count] = '\0';
- // return count;
- //}
- //
- //bool isConsonant(char ch)
- //{
- // char consonants[] = "bcdfghjklmnpqrstvwxz";
- // return strchr(consonants, ch) ? true : false;
- //}
- //
- //bool isVowel(char ch)
- //{
- // char vowels[] = "aeyuio";
- // return strchr(vowels, ch) ? true : false;
- //}
- //
- //char consonantOnVowel()
- //{
- // char vowels[13] = "AEYUIOaeyuio";
- // srand(time(0));
- // int n = 1 + rand() % 12;
- // return vowels[n];
- //}
- //
- //void changeString(char* str, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // if (isConsonant(tolower(str[i])))
- // cout << consonantOnVowel();
- // else if (isVowel(tolower(str[i])))
- // cout << static_cast<int> (str[i]);
- // else
- // cout << str[i];
- // cout << " ";
- // }
- //}
- //
- //int main()
- //{
- // char str[256];
- // cout << "Enter the string of characters: ";
- // int size = getStr(str);
- // changeString(str, size);
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //void showMenu()
- //{
- // cout << "Menu:\n"
- // "1 - To enter the string\n"
- // "2 - To process the data\n"
- // "3 - To see result\n"
- // "0 - Exit\n";
- //}
- //
- //int getStr(char *str)
- //{
- // int count = 0;
- // char ch;
- // cout << "Enter your string: ";
- // while ((ch = cin.get()) != '\n')
- // str[count++] = ch;
- // str[count] = '\n';
- // return count;
- //}
- //int getChoice()
- //{
- // int choice;
- // cout << "Enter your choice: ";
- // while (true)
- // {
- // cin >> choice;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (choice != 1 && choice != 2 && choice != 3 && choice != 0)
- // cout << "Bad input. Try again. ";
- // else
- // return choice;
- // }
- //}
- //
- //int countRepeats(char* str, int size)
- //{
- // cout << "\nProcessing the data...\n";
- // int count = 0;
- // for (int i = 0; i < size - 1; ++i)
- // if (str[i] == str[i + 1])
- // ++count;
- // return count;
- //}
- //
- //int main()
- //{
- // char str[256]{ "none" };
- // int choice = getChoice();
- // showMenu();
- //
- // int count = 0;
- // int size = 0;
- // while (choice != 0)
- // {
- // switch (choice)
- // {
- // case 1: size = getStr(str); break;
- // case 2: count = countRepeats(str, size); break;
- // case 3: cout << "There are " << count << " repeats\n";
- // }
- // showMenu();
- // choice = getChoice();
- // }
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <ctime>
- //using namespace std;
- //
- //int getNum()
- //{
- // int choice;
- // while (true)
- // {
- // cin >> choice;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again : ";
- // }
- // else if (choice != 1 && choice != 0)
- // cout << "Only 1 or 0.";
- // else
- // return choice;
- // }
- //}
- //
- //void hint()
- //{
- // srand(time(0));
- // int choice = rand() % 3;
- // switch (choice)
- // {
- // case 0: cout << "lox"; break;
- // case 1: cout << "Lox"; break;
- // case 2: cout << "LoxLox"; break;
- // }
- //}
- //
- //int main()
- //{
- // cout << "Enter the year of birth of Hohol is 1809(yes- 1, no - 0): ";
- // int choice = getNum();
- // while (choice != 1)
- // {
- // cout << "Think better: ";
- // hint();
- // cout << "Enter the year of birth of Hohol is 1809(yes- 1, no - 0): ";
- // choice = getNum();
- // }
- //
- // string cel = "You are right!", name;
- // cout << cel << "\nEnter your name: ";
- // cin >> name;
- // string cel2 = ", pozdr, whe csvety y vas ";
- // cel = name + cel2;
- // cel = cel + name;
- // string m = "This music for ua";
- // cel += m;
- // cout << cel;
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //void addRightDigit(int d, int& k)
- //{
- // k = k * 10 + d;
- //}
- //
- //int main()
- //{
- // int k = 4, d = 5;
- // cout << k << endl << d;
- // addRightDigit(d, k);
- // d = 2;
- // cout << endl << k << endl << d;
- // addRightDigit(d, k);
- // cout << endl << k;
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //float getNum()
- //{
- // float num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again. ";
- // }
- // else if (num < 0.0)
- // cout << "Only positive nums: ";
- // else
- // return num;
- // }
- //}
- //
- //void fillMatrix(float** matrix, int numOfSport, int tries)
- //{
- // for (int i = 0; i < numOfSport; ++i)
- // {
- // cout << "for " << i + 1 << " sportsmen: ";
- // for (int j = 0; j < tries; ++j)
- // matrix[i][j] = getNum();
- // }
- //}
- //
- //float** allocMemory(int numOfSp, int tries)
- //{
- // float** matrix = new float* [numOfSp];
- // for (int i = 0; i < numOfSp; ++i)
- // matrix[i] = new float[tries];
- // return matrix;
- //}
- //
- //void freeMemory(float** arr, int num)
- //{
- // for (int i = 0; i < num; ++i)
- // {
- // delete[] arr[i];
- // arr[i] = nullptr;
- // }
- // delete[] arr;
- // arr = nullptr;
- //}
- //
- //void findBest(float** arr, int numOfSp, int tries)
- //{
- // cout << "\nBest result of sportsmens: \n";
- // for (int i = 0; i < numOfSp; ++i)
- // {
- // cout << "Num of sp - " << i + 1 << endl;
- // float best = arr[i][0];
- // int tr = 1;
- // for (int j = 0; j < tries; ++j)
- // if (arr[i][j] > best)
- // {
- // tr = j + 1;
- // best = arr[i][j];
- // }
- // cout << "Num of try - " << tr << endl;
- // }
- //}
- //
- //int main()
- //{
- // const int numOfSportsmens = 5;
- // const int tries = 3;
- // float **results = allocMemory(numOfSportsmens, tries);
- // cout << "Enter the results of competition: \n";
- // fillMatrix(results, numOfSportsmens, tries);
- // findBest(results, numOfSportsmens, tries);
- // freeMemory(results, numOfSportsmens);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int findChastnoe(int delimoe, int delitel)
- //{
- // int n = delitel;
- // int count = 1;
- // while ((n += delitel) <= delimoe)
- // ++count;
- // return count;
- //}
- //
- //int findOstatok(int delimoe, int delitel, int chastnoe)
- //{
- // int temp = 0;
- // for (int i = 0; i < chastnoe; ++i)
- // temp += delitel;
- // return delimoe - temp;
- //}
- //
- //int main()
- //{
- // int delimoe, delitel;
- // cout << "Enter delimoe: ";
- // cin >> delimoe;
- // cout << "Enter delitel: ";
- // cin >> delitel;
- // if (delimoe > delitel)
- // {
- // int chastnoe = findChastnoe(delimoe, delitel);
- // int ostatok = findOstatok(delimoe, delitel, chastnoe);
- // cout << "Chastnoe = " << chastnoe << endl << "Ostatok = " << ostatok;
- // }
- // else
- // cout << "LOX";
- // return 0;
- //}
- //#include <iostream>
- //#include <cstdlib>
- //#include <ctime>
- //
- //using namespace std;
- //
- //int** createMatrix(int size)
- //{
- // int** arr = new int* [size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = new int[size];
- // return arr;
- //}
- //
- //void fillMatrix(int** matrix, int size)
- //{
- // srand(static_cast<unsigned>(time(0)));
- // for (int i = 0; i < size; ++i)
- // for (int j = 0; j < size; ++j)
- // matrix[i][j] = 1 + rand() % 100;
- //}
- //
- //void showMatrix( int** matrix, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // for (int j = 0; j < size; ++j)
- // cout << matrix[i][j] << " ";
- // cout << endl;
- // }
- // cout << endl << endl << endl << endl << endl;
- //}
- //
- //void nullColInMatrix(int** matrix, int size, int colToNull)
- //{
- // for (int i = 0; i < size; ++i)
- // matrix[i][colToNull] = 0;
- //}
- //
- //int main()
- //{
- // const int size = 8;
- // int** matrix = createMatrix(size);
- // fillMatrix(matrix, size);
- //
- // showMatrix(matrix, size);
- //
- // int colToNull = 1;
- // nullColInMatrix(matrix, size, colToNull);
- // showMatrix(matrix, size);
- //
- // colToNull = 3;
- // nullColInMatrix(matrix, size, colToNull);
- // showMatrix(matrix, size);
- //
- // colToNull = 5;
- // nullColInMatrix(matrix, size, colToNull);
- // showMatrix(matrix, size);
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int calc(int num, int razr)
- //{
- // int countNumbers = 0;
- // int newNum = num;
- // while (newNum > 0)
- // {
- // ++countNumbers;
- // newNum /= 10;
- // }
- // if (countNumbers < razr)
- // return 0;
- // int i = 0;
- // --countNumbers;
- // newNum = 0;
- // while (i < razr)
- // {
- // int n = num / static_cast<int>(pow(10, countNumbers)) % 10;
- // newNum = newNum * 10 + n;
- // ++i; --countNumbers;
- // }
- // return newNum;
- //}
- //
- //
- //
- //int main()
- //{
- // cout << "Enter the num : ";
- // int num = 0;
- // cin >> num;
- // cout << "How many show : ";
- // int razr;
- // cin >> razr;
- // cout << calc(num, razr);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //bool slon(int x1, int y1, int x2, int y2)
- //{
- // bool res = false;
- // if (abs(x1 - x2) == 2 && abs(y1 - y2) == 1)
- // res = true;
- // else if (abs(y1 - y2) == 2 && abs(x1 - x2) == 1)
- // res = true;
- // return res;
- //}
- //
- //int main()
- //{
- // int x1, y1, x2, y2;
- // cout << "Enter x1: ";
- // cin >> x1;
- // cout << "Enter y1: ";
- // cin >> y1;
- // cout << "Enter x2: ";
- // cin >> x2;
- // cout << "Enter y2: ";
- // cin >> y2;
- // if (slon(x1, y1, x2, y2))
- // cout << "YES\n";
- // else
- // cout << "NO\n";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //bool slon(int x1, int y1, int x2, int y2)
- //{
- // bool res = false;
- // if (abs(x1 - x2) == abs(y1 - y2))
- // res = true;
- // return res;
- //}
- //
- //int main()
- //{
- // int x1, y1, x2, y2;
- // cout << "Enter x1: ";
- // cin >> x1;
- // cout << "Enter y1: ";
- // cin >> y1;
- // cout << "Enter x2: ";
- // cin >> x2;
- // cout << "Enter y2: ";
- // cin >> y2;
- // if (slon(x1, y1, x2, y2))
- // cout << "YES\n";
- // else
- // cout << "NO\n";
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //bool status(int num)
- //{
- // if (num % 2 == 0 || num % 3 == 0)
- // return true;
- // else
- // return false;
- //}
- //
- //int main()
- //{
- // int num;
- // cin >> num;
- // if (status(num))
- // cout << "YES";
- // else
- // cout << "NO";
- // return 0;
- //}
- //#include <iostream>
- //#include <cstdlib>
- //#include <ctime>
- //using namespace std;
- //
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- //
- // }
- // else if (num <= 1)
- // cout << "Bad input. ";
- // else
- // return num;
- // }
- //}
- //
- //int** allocMemory(int rows, int cols)
- //{
- // int** arr = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // arr[i] = new int[cols];
- // return arr;
- //}
- //
- //void fillMatrix(int** arr, int rows, int cols)
- //{
- // srand(static_cast<unsigned>(time(0)));
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // arr[i][j] = -10 + rand() % 20;
- //}
- //
- //void showMatrix(int** arr, int rows, int cols)
- //{
- // for (int i = 0; i < rows; ++i)
- // {
- // for (int j = 0; j < cols; ++j)
- // {
- // cout.width(5);
- // cout << arr[i][j];
- // }
- // cout << endl;
- // }
- //}
- //
- //void showRes(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << arr[i] << " ";
- // cout << endl;
- //}
- //
- //
- //int * copyRes(int* arr, int count)
- //{
- // int* newArr = new int[count];
- // for (int i = 0; i < count; ++i)
- // newArr[i] = arr[i];
- // return newArr;
- //}
- //
- //void deleteArr(int* arr)
- //{
- // delete[] arr;
- // arr = nullptr;
- //}
- //
- //int* findSumInPosCols(int** arr, int rows, int cols, int &resSize)
- //{
- // int* res = new int[cols] {0};
- // int countOfSuccess = 0;
- // for (int j = 0; j < cols; ++j)
- // {
- // bool suc = true;
- // int sum = 0;
- // for (int i = 0; i < rows; ++i)
- // {
- // if (arr[i][j] < 0)
- // {
- // suc = false;
- // break;
- // }
- // else
- // sum += arr[i][j];
- // }
- // if(suc)
- // res[countOfSuccess++] = sum;
- // }
- // resSize = countOfSuccess;
- // int* newArr = copyRes(res, countOfSuccess);
- // deleteArr(res);
- // return newArr;
- //}
- //
- //void deleteMatrix(int** arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // delete [] arr[i];
- // arr[i] = nullptr;
- // }
- // delete[] arr;
- // arr = nullptr;
- //}
- //
- //int main()
- //{
- // int rows, cols;
- // cout << "Enter the number of rows: ";
- // rows = getSize();
- // cout << "Enter the number of columns: ";
- // cols = getSize();
- // int** arr = allocMemory(rows, cols);
- // fillMatrix(arr, rows, cols);
- // showMatrix(arr, rows, cols);
- // int resSize = 0;
- // int* res = findSumInPosCols(arr, rows, cols, resSize);
- // showRes(res, resSize);
- // deleteMatrix(arr, rows);
- // deleteArr(res);
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else if (num < 1)
- // cout << "Bad input. ";
- // else
- // return num;
- // }
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //void fillArray(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // arr[i] = getNum();
- //}
- //
- //void showArray(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cout << arr[i] << " ";
- //}
- //
- //void copyArr(int* source, int* target, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // target[i] = source[i];
- //}
- //
- //void deleteNum(int* arr, int &size, int numToDelete)
- //{
- // int* newArr = new int[size - 1];
- // for (int i = 0, count = 0; i < size; ++i)
- // if (i != numToDelete)
- // newArr[count++] = arr[i];
- // --size;
- // delete arr;
- // arr = new int[size];
- // copyArr(newArr, arr, size);
- //}
- //
- //int main()
- //{
- // int size;
- // cout << "Enter the size - ";
- // size = getSize();
- // int* arr = new int[size];
- // fillArray(arr, size);
- // showArray(arr, size);
- // cout << "Enter the num of element to delete - ";
- // int numToDelete = getNum();
- // if (numToDelete < size)
- // {
- // deleteNum(arr, size, numToDelete);
- // showArray(arr, size);
- // }
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //
- //using namespace std;
- //
- //int main()
- //{
- // cout << "Enter file path: ";
- // string filePath;
- // cin >> filePath;
- // ifstream ifs;
- // ifs.open(filePath);
- // if (ifs.fail() || !ifs.is_open())
- // return -1;
- // char ch;
- // int count = 0;
- // string temp = "";
- // while (!ifs.eof())
- // {
- // ch = ifs.get();
- // bool succ = true;
- // ++count;
- //
- // for (int i = 0; i < count; ++i)
- // if (ch == temp[i])
- // {
- // succ = false;
- // break;
- // }
- // if (succ)
- // cout << ch;
- // temp += ch;
- //
- // }
- // return 0;
- //}
- //#include <iostream>
- //#include <cstring>
- //using namespace std;
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //int main()
- //{
- // cout << "Enter the string of numbers: ";
- // char str[256];
- // cin.getline(str, 256);
- // cout << str;
- // char* pch = strtok(str, ",");
- // int sum = 0;
- // while (pch != NULL)
- // {
- // sum += atoi(pch);
- // pch = strtok(NULL, ",");
- // }
- // cout << endl << endl << sum << endl;
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again - ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again - ";
- // }
- // else if (num <= 1)
- // cout << "Bad input. Try again - ";
- // else
- // return num;
- // }
- //}
- //
- //class Matrix
- //{
- // int rows;
- // int cols;
- // int** arr;
- //public:
- // Matrix();
- // Matrix(int r, int c);
- // Matrix(Matrix& matrix);
- // ~Matrix();
- // Matrix& operator=(Matrix& matrix);
- // Matrix operator+(Matrix& matrix);
- // //Matrix operator*(Matrix& matrix);
- // friend istream& operator>>(istream& is, const Matrix& matrix);
- // friend ostream& operator<<(ostream& os, const Matrix& matrix);
- //
- //};
- //
- //Matrix::Matrix() : rows(0), cols(0)
- //{
- // arr = nullptr;
- //}
- //
- //Matrix::Matrix(int r, int c) : rows(r), cols(c)
- //{
- // arr = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // arr[i] = new int[cols];
- //}
- //
- //Matrix::~Matrix()
- //{
- // for (int i = 0; i < rows; ++i)
- // {
- // delete[] arr[i];
- // arr[i] = nullptr;
- // }
- // delete[] arr;
- // arr = nullptr;
- //}
- //
- //Matrix::Matrix(Matrix& matrix)
- //{
- // rows = matrix.rows;
- // cols = matrix.cols;
- // arr = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // arr[i] = new int[cols];
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // arr[i][j] = matrix.arr[i][j];
- //}
- //
- //Matrix& Matrix::operator=(Matrix& matrix)
- //{
- // if (&matrix == this)
- // return *this;
- // for (int i = 0; i < rows; ++i)
- // {
- // delete[] arr[i];
- // arr[i] = nullptr;
- // }
- // delete[] arr;
- // rows = matrix.rows;
- // cols = matrix.cols;
- // arr = new int* [rows];
- // for (int i = 0; i < rows; ++i)
- // arr[i] = new int[cols];
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // arr[i][j] = matrix.arr[i][j];
- // return *this;
- //}
- //
- //Matrix Matrix::operator+(Matrix& matrix)
- //{
- // if (rows != matrix.rows || cols != matrix.cols)
- // {
- // Matrix res;
- // return res;
- // }
- // Matrix res(rows, cols);
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // res.arr[i][j] = arr[i][j] + matrix.arr[i][j];
- // return res;
- //}
- //
- ////Matrix Matrix::operator*(Matrix& matrix)
- ////{
- //// if (cols != matrix.rows)
- //// return;
- //// Matrix res(rows, matrix.cols);
- //// for (int i = 0; i < res.rows; ++i)
- //// {
- //// for (int j = 0; j < res.cols; ++j)
- //// ;
- //// }
- ////}
- //
- //istream& operator>>(istream& is, const Matrix& matrix)
- //{
- // cout << "\nEnter the elements of matrix: \n";
- // for (int i = 0; i < matrix.rows; ++i)
- // for (int j = 0; j < matrix.cols; ++j)
- // {
- // cout << "Enter [" << i << "][" << j << "] - ";
- // matrix.arr[i][j] = getNum();
- // }
- // cout << endl;
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Matrix& matrix)
- //{
- // os << endl << "Your matrix : \n";
- // for (int i = 0; i < matrix.rows; ++i)
- // {
- // for (int j = 0; j < matrix.cols; ++j)
- // os << matrix.arr[i][j] << " ";
- // os << endl;
- // }
- // os << endl;
- // return os;
- //}
- //
- //int main()
- //{
- // Matrix M1(2, 3);
- // cin >> M1;
- // int M2rows, M2cols;
- //
- // cout << "Enter rows - ";
- // M2rows = getSize();
- // cout << "Enter cols - ";
- // M2cols = getSize();
- //
- // Matrix M2(M2rows, M2cols);
- // cin >> M2;
- //
- // cout << M1 << M2 << M1 + M2;
- //
- //
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <cstring>
- //#include <string>
- //using namespace std;
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //int main()
- //{
- // char str[256];
- // cin.getline(str, 256);
- // int count = 0;
- // int max = 0;
- // string res = "";
- // char* pcd = strtok(str, " .");
- //
- // while (pcd != NULL)
- // {
- // ++count;
- // if (strlen(pcd) > res.size())
- // {
- // res = pcd;
- // max = count;
- // }
- // pcd = strtok(NULL, " .");
- // }
- // cout << endl << endl << res << endl << max;
- // return 0;
- //}
- //#include <iostream>
- //#include <cstring>
- //#include <string>
- //using namespace std;
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //int main()
- //{
- // char str[256];
- // cin.getline(str, 256);
- // int count = 0;
- // int max = 1;
- //
- // char* pcd = strtok(str, " .");
- // string res = pcd;
- // while (pcd != NULL)
- // {
- // ++count;
- // if (strlen(pcd) < res.size())
- // {
- // res = pcd;
- // max = count;
- // }
- // pcd = strtok(NULL, " .");
- // }
- // cout << endl << endl << res << endl << max;
- // return 0;
- //}
- //#include <iostream>
- //#include <cstring>
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //using namespace std;
- //int main()
- //{
- // const int size = 256;
- // char str[size];
- // int i = 0;
- // while ((str[i++] = cin.get()) != '.' && i < size);
- // str[i] = '\0';
- // cout << endl << endl << str << endl << endl;
- // char* pcd = strtok(str, " ");
- // string res = "";
- // while (pcd != NULL)
- // {
- // if (strlen(pcd) > 1)
- // {
- // res += " ";
- // res += &pcd[1];
- // }
- // pcd = strtok(NULL, " ");
- // }
- // cout << res;
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int lengthString(char* str)
- //{
- // if (str == NULL)
- // return 0;
- // int count = 0;
- // while (str[count] != '\0')
- // ++count;
- // return count;
- //}
- //
- //char* reverseString(char* source)
- //{
- // if (source == NULL)
- // exit(1);
- // char* target = new char[lengthString(source)];
- // for (int i = lengthString(source) - 1, j = 0; i >= 0; --i, ++j)
- // target[j] = source[i];
- // target[lengthString(source)] = '\0';
- // return target;
- //}
- //
- //int balanceBrackets(char* str)
- //{
- // if (str == NULL)
- // return 0;
- // bool noBrackets = true;
- // bool balanced = true;
- // int countSquare = 0, countRound = 0, countFigure = 0;
- // int i = 0;
- // while (str[i] != '\0')
- // {
- // if (str[i] == '{')
- // {
- // ++countFigure;
- // noBrackets = false;
- // }
- // else if (str[i] == '}')
- // {
- // --countFigure;
- // noBrackets = false;
- // }
- // else if (str[i] == '(')
- // {
- // ++countRound;
- // noBrackets = false;
- // }
- // else if (str[i] == ')')
- // {
- // --countRound;
- // noBrackets = false;
- // }
- // else if (str[i] == '[')
- // {
- // ++countSquare;
- // noBrackets = false;
- // }
- // else if (str[i] == ']')
- // {
- // --countSquare;
- // noBrackets = false;
- // }
- // ++i;
- // }
- // if (noBrackets)
- // return -1;
- // if (countFigure != 0 || countRound != 0 || countSquare != 0)
- // return 0;
- // return 1;
- //}
- //
- //int occurenceSubstring(char* str, char* subStr)
- //{
- // if (str == NULL || subStr == NULL)
- // return 0;
- // int i = 0, pos = 0;
- // bool found = true;
- // while (str[i] != '\0')
- // {
- // if (str[i] == subStr[0])
- // {
- // found = true;
- // for (int j = i, count = 0; count < lengthString(subStr); ++j, ++count)
- // if (str[j] != subStr[count])
- // {
- // found = false;
- // break;
- // }
- // if (found)
- // {
- // pos = i + 1;
- // break;
- // }
- // }
- // ++i;
- // }
- // return pos;
- //}
- //
- //char* insertnString(char* str1, char* str2, int n)
- //{
- // if (str1 == NULL || str2 == NULL)
- // exit(1);
- // int size = lengthString(str1) + lengthString(str2) + 1;
- // if (n > size)
- // exit(1);
- // char* newStr = new char[size];
- // for (int i = 0; i < n - 1; ++i)
- // newStr[i] = str1[i];
- // for (int i = n - 1, j = 0; j < lengthString(str2); ++j, ++i)
- // newStr[i] = str2[j];
- // for (int i = lengthString(str2) + n - 1, j = n - 1; i < size; ++i, ++j)
- // newStr[i] = str1[j];
- // newStr[size] = '\0';
- // return newStr;
- //}
- //
- //char* cutString(char* str, int pos, int k)
- //{
- // int size = lengthString(str);
- // if (pos + k > size)
- // exit(1);
- // char* newStr = new char[k + 1];
- // for (int i = pos - 1, j = 0; j < k; ++j, ++i)
- // newStr[j] = str[i];
- // newStr[k] = '\0';
- // return newStr;
- //}
- //
- //int main()
- //{
- // char str[] = "cppstudio.com";
- // cout << cutString(str, 4, 6);
- // return 0;
- //}
- //#include <iostream>
- //#include <ctime>
- //#include <cstdlib>
- //
- //using namespace std;
- //
- //int** createMatrix(int size)
- //{
- // int** arr = new int* [size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = new int[size];
- // return arr;
- //}
- //
- //void fillMatrix(int** arr, int size)
- //{
- // srand(static_cast<unsigned>(time(0)));
- // for (int i = 0; i < size; ++i)
- // for (int j = 0; j < size; ++j)
- // arr[i][j] = rand() % 100;
- //}
- //
- //int findMin(int** arr, int size, int& minI, int& minJ)
- //{
- // int min = arr[1][0];
- // for(int i = 0; i < size; ++i)
- // for(int j = 0; j < i; ++j)
- // if (arr[i][j] < min)
- // {
- // min = arr[i][j];
- // minI = i;
- // minJ = j;
- // }
- // return min;
- //}
- //
- //int findMax(int** arr, int size, int& maxI, int& maxJ)
- //{
- // int max = arr[0][1];
- // for (int i = 0; i < size; ++i)
- // for (int j = i + 1; j < size; ++j)
- // if (arr[i][j] > max)
- // {
- // max = arr[i][j];
- // maxI = i;
- // maxJ = j;
- // }
- // return max;
- //}
- //
- //void showMatrix(int** arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // {
- // for (int j = 0; j < size; ++j)
- // {
- // cout.width(4);
- // cout << arr[i][j] << " ";
- // }
- // cout << endl;
- // }
- //}
- //
- //void swapElements(int** matrix, int minI, int minJ, int maxI, int maxJ)
- //{
- // int temp = matrix[minI][minJ];
- // matrix[minI][minJ] = matrix[maxI][maxJ];
- // matrix[maxI][maxJ] = temp;
- //}
- //
- //int getSize()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. ";
- // }
- // else if (num <= 1)
- // cout << "Bad input. ";
- // else
- // return num;
- // }
- //}
- //
- //int main()
- //{
- // cout << "Enter the size of square matrix: ";
- // int size = getSize();
- // int **matrix = createMatrix(size);
- // fillMatrix(matrix, size);
- // showMatrix(matrix, size);
- // int max = matrix[0][0], maxI = 0, maxJ = 1, min = matrix[0][0], minI = 1, minJ = 0;
- // min = findMin(matrix, size, minI, minJ);
- // max = findMax(matrix, size, maxI, maxJ);
- //
- // cout << "\n\nMin[" << minI << "][" << minJ << "] = " << min << endl;
- // cout << "\nMax[" << maxI << "][" << maxJ << "] = " << max << endl << endl;
- //
- // swapElements(matrix, minI, minJ, maxI, maxJ);
- // showMatrix(matrix, size);
- // return 0;
- //}
- //#include <iostream>
- //
- //using namespace std;
- //
- //class Array
- //{
- // int* pArr;
- // int size;
- //public:
- // Array();
- // Array(int size_);
- // Array(const Array& arr);
- // ~Array();
- // int findElementByKey(int key) const;
- // void sortByHigher();
- // void sortByLower();
- // int getSize() const;
- //
- // friend istream& operator>>(istream& is, Array& arr);
- // friend ostream& operator<<(ostream& os, const Array& arr);
- //
- // Array operator+(const Array& arr) const;
- // Array operator-(int num) const;
- // Array& operator=(const Array& arr);
- // void operator+=(int num);
- // int operator==(const Array& arr) const;
- // int& operator[](int position);
- // Array operator-(const Array& arr) const;
- //};
- //
- //int Array::getSize() const
- //{
- // return size;
- //}
- //
- //Array::Array()
- //{
- // pArr = nullptr;
- // size = 0;
- //}
- //
- //Array::Array(int size_) : size(size_)
- //{
- // pArr = new int[size];
- //}
- //
- //Array::Array(const Array& arr)
- //{
- // size = arr.size;
- // pArr = new int[size];
- // for (int i = 0; i < size; ++i)
- // pArr[i] = arr.pArr[i];
- //}
- //
- //Array::~Array()
- //{
- // size = 0;
- // delete[] pArr;
- // pArr = nullptr;
- //}
- //
- //int Array::findElementByKey(int key) const
- //{
- // for (int i = 0; i < size; ++i)
- // if (pArr[i] == key)
- // return i;
- // return -1;
- //}
- //
- //void Array::sortByHigher()
- //{
- // int temp;
- // for(int i = 0; i < size - 1; ++i)
- // for(int j = i + 1; j < size; ++j)
- // if (pArr[i] > pArr[j])
- // {
- // temp = pArr[i];
- // pArr[i] = pArr[j];
- // pArr[j] = temp;
- // }
- //}
- //
- //void Array::sortByLower()
- //{
- // int temp;
- // for (int i = 0; i < size - 1; ++i)
- // for (int j = i + 1; j < size; ++j)
- // if (pArr[i] < pArr[j])
- // {
- // temp = pArr[i];
- // pArr[i] = pArr[j];
- // pArr[j] = temp;
- // }
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again - ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //istream& operator>>(istream& is, Array& arr)
- //{
- // for (int i = 0; i < arr.size; ++i)
- // {
- // cout << "Enter [" << i << "] - ";
- // arr.pArr[i] = getNum();
- // }
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Array& arr)
- //{
- // for (int i = 0; i < arr.size; ++i)
- // os << arr.pArr[i] << " ";
- // os << endl;
- // return os;
- //}
- //
- //Array Array::operator+(const Array& arr) const
- //{
- // if (size != arr.size)
- // exit(1);
- // Array res(size);
- // for (int i = 0; i < size; ++i)
- // res.pArr[i] = pArr[i] + arr.pArr[i];
- // return res;
- //}
- //
- //Array& Array::operator=(const Array& arr)
- //{
- // if (this == &arr)
- // return *this;
- // delete[] pArr;
- // pArr = nullptr;
- // size = arr.size;
- // pArr = new int[size];
- // for (int i = 0; i < size; ++i)
- // pArr[i] = arr.pArr[i];
- // return *this;
- //}
- //
- //int Array::operator==(const Array& arr) const
- //{
- // if (size != arr.size)
- // return -1;
- // int equal = 1;
- // for(int i = 0; i < size; ++i)
- // if (pArr[i] != arr.pArr[i])
- // {
- // equal = 0;
- // break;
- // }
- // return equal;
- //}
- //
- //void Array::operator+=(int num)
- //{
- // int* temp = new int[static_cast<size_t>(size) + 1];
- // for (int i = 0; i < size; ++i)
- // temp[i] = pArr[i];
- // temp[size] = num;
- // delete[] pArr;
- // ++size;
- // pArr = new int[size];
- // for (int i = 0; i < size; ++i)
- // pArr[i] = temp[i];
- //}
- //
- //Array Array::operator-(int num) const
- //{
- // int key = this->findElementByKey(num);
- // if (key == -1)
- // {
- // Array res;
- // return res;
- // }
- // Array res(size - 1);
- // for (int i = 0, j = 0; i < size; ++i)
- // if (i != key)
- // res.pArr[j++] = pArr[i];
- // return res;
- //}
- //
- //int& Array::operator[](int pos)
- //{
- // if (pos >= size)
- // exit(1);
- // return pArr[pos];
- //}
- //
- //Array Array::operator-(const Array& arr) const
- //{
- // if (size != arr.size)
- // exit(1);
- // Array res(size);
- // for (int i = 0; i < size; ++i)
- // res.pArr[i] = pArr[i] - arr.pArr[i];
- // return res;
- //}
- //
- //class Matrix
- //{
- // Array* pMatr;
- // int size;
- //public:
- // Matrix();
- // Matrix(int size_);
- // Matrix(const Matrix& matrix);
- // ~Matrix();
- // friend istream& operator>>(istream& is, Matrix& matrix);
- // friend ostream& operator<<(ostream& os, const Matrix& matrix);
- // void showMatrix() const;
- // void fillMatrix();
- // int findElementByKey(int key) const;
- // Matrix operator+(const Matrix& matrix) const;
- // Matrix& operator+=(const Matrix& matrix);
- // Matrix operator-(const Matrix& matrix) const;
- // Matrix& operator=(const Matrix& matrix);
- // int operator==(const Matrix& matrix) const;
- // Array& operator[](int num);
- //};
- //
- //Matrix::Matrix()
- //{
- // pMatr = nullptr;
- // size = 0;
- //}
- //
- //Matrix::Matrix(int size_) : size(size_)
- //{
- // pMatr = new Array[size];
- // for (int i = 0; i < size; ++i)
- // pMatr[i] = Array(size);
- //}
- //
- //Matrix::Matrix(const Matrix& matrix)
- //{
- // size = matrix.size;
- // pMatr = new Array[size];
- // for (int i = 0; i < size; ++i)
- // pMatr[i] = matrix.pMatr[i];
- //}
- //
- //Matrix::~Matrix()
- //{
- // delete[] pMatr;
- // pMatr = nullptr;
- //}
- //
- //istream& operator>>(istream& is, Matrix& matrix)
- //{
- // cout << endl;
- // for (int i = 0; i < matrix.size; ++i)
- // {
- // cout << "Enter the elements of row " << i << " - \n";
- // is >> matrix.pMatr[i];
- // }
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Matrix& matrix)
- //{
- // os << endl;
- // for (int i = 0; i < matrix.size; ++i)
- // os << matrix.pMatr[i];
- // os << endl;
- // return os;
- //}
- //
- //int Matrix::findElementByKey(int key) const
- //{
- // for (int i = 0; i < size; ++i)
- // if (pMatr[i].findElementByKey(key) != -1)
- // return i;
- // return -1;
- //}
- //
- //void Matrix::showMatrix() const
- //{
- // cout << endl;
- // for (int i = 0; i < size; ++i)
- // cout << pMatr[i] << endl;
- //
- //}
- //
- //void Matrix::fillMatrix()
- //{
- // for (int i = 0; i < size; ++i)
- // cin >> pMatr[i];
- //}
- //
- //Matrix Matrix::operator+(const Matrix& matrix) const
- //{
- // if (size != matrix.size)
- // exit(1);
- // Matrix res(size);
- // for (int i = 0; i < size; ++i)
- // res.pMatr[i] = pMatr[i] + matrix.pMatr[i];
- // return res;
- //}
- //
- //Matrix& Matrix::operator+=(const Matrix& matrix)
- //{
- // if (size != matrix.size)
- // exit(1);
- // for (int i = 0; i < size; ++i)
- // pMatr[i] = pMatr[i] + matrix.pMatr[i];
- // return *this;
- //}
- //
- //Matrix Matrix::operator-(const Matrix& matrix) const
- //{
- // if (size != matrix.size)
- // exit(1);
- // Matrix res(size);
- // for (int i = 0; i < size; ++i)
- // res.pMatr[i] = pMatr[i] - matrix.pMatr[i];
- // return res;
- //}
- //
- //Matrix& Matrix::operator=(const Matrix& matrix)
- //{
- // if (this == &matrix)
- // return *this;
- // delete[] pMatr;
- // size = matrix.size;
- // pMatr = new Array[size];
- // for (int i = 0; i < size; ++i)
- // pMatr[i] = matrix.pMatr[i];
- // return *this;
- //}
- //
- //int Matrix::operator==(const Matrix& matrix) const
- //{
- // if (size != matrix.size)
- // return -1;
- // for (int i = 0; i < size; ++i)
- // if ((pMatr[i] == matrix.pMatr[i]) == 0)
- // return 0;
- // return 1;
- //}
- //
- //Array& Matrix::operator[](int num)
- //{
- // if (num >= size)
- // exit(1);
- // return pMatr[num];
- //}
- //
- //int main()
- //{
- // Matrix M1(2);
- // cin >> M1;
- // cout << M1;
- // Matrix M2(2);
- // cin >> M2;
- // cout << M2;
- // Matrix M3 = M1 + M2;
- // Matrix M4 = M1 - M2;
- // cout << M3 << endl << "M4: \n" << M4;
- // M3 += M4;
- // cout << M3;
- // if (M3 == M1)
- // cout << "\nEqual\n";
- // else
- // cout << "\nNot equal\n";
- // M3 = M1;
- // if (M3 == M1)
- // cout << "\nEqual\n";
- // else
- // cout << "\nNot equal\n";
- // cout << M3[0];
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //class Many
- //{
- // int* arr;
- // int size;
- //public:
- // Many();
- // Many(int size_);
- // Many(const Many& many);
- //
- // int getSize();
- //
- // friend istream& operator>>(istream& is, Many& many);
- // friend ostream& operator<<(ostream& os, const Many& many);
- //
- // bool elementPresent(int num, int maxPos) const;
- // bool elementPresent(int num) const;
- //
- // Many operator+(int num) const;
- // Many& operator+=(int num);
- //
- // Many& operator=(const Many& many);
- //
- // Many operator+(const Many& many) const;
- // Many& operator+=(const Many& many);
- //
- // Many operator-(int num) const;
- // Many operator-(const Many& many) const;
- //
- // bool operator==(const Many& many) const;
- //};
- //
- //Many::Many()
- //{
- // arr = nullptr;
- // size = 0;
- //}
- //
- //Many::Many(int size_)
- //{
- // size = size_;
- // arr = new int[size];
- //}
- //
- //Many::Many(const Many& many)
- //{
- // size = many.size;
- // arr = new int[size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = many.arr[i];
- //}
- //
- //int Many::getSize()
- //{
- // return size;
- //}
- //
- //int getNum()
- //{
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // cout << "Bad input. Try again - ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //bool Many::elementPresent(int num, int maxPos) const
- //{
- // for (int i = 0; i < maxPos; ++i)
- // if (arr[i] == num)
- // return true;
- // return false;
- //}
- //
- //bool Many::elementPresent(int num) const
- //{
- // for (int i = 0; i < size; ++i)
- // if (arr[i] == num)
- // return true;
- // return false;
- //}
- //
- //Many& Many::operator=(const Many& many)
- //{
- // if (this == &many)
- // return *this;
- // delete[] arr;
- // size = many.size;
- // arr = new int[size];
- // for(int i = 0; i < size; ++i)
- // arr[i] = many.arr[i];
- // return *this;
- //}
- //
- //Many Many::operator+(int num) const
- //{
- // if (this->elementPresent(num))
- // return *this;
- // Many res(size + 1);
- // for (int i = 0; i < size; ++i)
- // res.arr[i] = arr[i];
- // res.arr[size] = num;
- // return res;
- //}
- //
- //Many& Many::operator+=(int num)
- //{
- // if (this->elementPresent(num, size))
- // return *this;
- // int* temp = new int[size + 1];
- // for (int i = 0; i < size; ++i)
- // temp[i] = arr[i];
- // temp[size] = num;
- // delete[] arr;
- // ++size;
- // for (int i = 0; i < size; ++i)
- // arr[i] = temp[i];
- // return *this;
- //}
- //
- //Many Many::operator+(const Many& many) const
- //{
- // int *temp = new int[size + many.size];
- // for (int i = 0; i < size; ++i)
- // temp[i] = arr[i];
- // int count = size;
- // for (int i = 0, j = size; i < many.size; ++i)
- // if (!elementPresent(many.arr[i]))
- // {
- // temp[j++] = many.arr[i];
- // ++count;
- // }
- // Many res(count);
- // for (int i = 0; i < count; ++i)
- // res.arr[i] = temp[i];
- // return res;
- //}
- //
- //Many& Many::operator+=(const Many& many)
- //{
- // if (this == &many)
- // return *this;
- // int* temp = new int[size + many.size];
- // for (int i = 0; i < size; ++i)
- // temp[i] = arr[i];
- // int count = size;
- // for (int i = 0, j = size; i < many.size; ++i)
- // if (!elementPresent(many.arr[i]))
- // {
- // temp[j++] = many.arr[i];
- // ++count;
- // }
- // delete[] arr;
- // size = count;
- // arr = new int[size];
- // for (int i = 0; i < size; ++i)
- // arr[i] = temp[i];
- // return *this;
- //}
- //
- //istream& operator>>(istream& is, Many& many)
- //{
- // cout << "Enter the elements of many: " << endl;
- // for (int i = 0; i < many.size; ++i)
- // {
- // cout << "Enter [" << i << "] - ";
- // int temp = getNum();
- // while (many.elementPresent(temp, i))
- // {
- // cout << "Element is already present in many. Enter another - ";
- // temp = getNum();
- // }
- // many.arr[i] = temp;
- // }
- // return is;
- //}
- //
- //ostream& operator<<(ostream& os, const Many& many)
- //{
- // os << endl << endl;
- // for (int i = 0; i < many.size; ++i)
- // os << many.arr[i] << " ";
- // os << endl << endl;
- // return os;
- //}
- //
- //Many Many::operator-(int num) const
- //{
- // if (!elementPresent(num, size))
- // {
- // Many res;
- // return res;
- // }
- // Many res(size - 1);
- // for (int i = 0, j = 0; i < size; ++i)
- // if (arr[i] != num)
- // res.arr[j++] = arr[i];
- // return res;
- //}
- //
- //Many Many::operator-(const Many& many) const
- //{
- // int* temp = new int[size];
- // int count = 0;
- // for(int i = 0; i < size; ++i)
- // if (!many.elementPresent(arr[i], many.size))
- // temp[count++] = arr[i];
- // Many res(count);
- // for (int i = 0; i < res.size; ++i)
- // res.arr[i] = temp[i];
- // return res;
- //}
- //
- //bool Many::operator==(const Many& many) const
- //{
- // if (size != many.size)
- // return false;
- // for (int i = 0; i < size; ++i)
- // if (!many.elementPresent(arr[i], size))
- // return false;
- // return true;
- //}
- //
- //int main()
- //{
- // Many M1(5), M2(5);
- // cin >> M1 >> M2;
- // cout << M1 << M2;
- // Many M3;
- //
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //class Prism
- //{
- // double volume;
- // double height;
- // int numOfLines;
- // double lineLength;
- // double squareOfMain;
- //
- //public:
- // double getVolume() const { return volume; };
- // void setVolume(double V) { volume = V; };
- //
- // double getHeight() const { return height; };
- // void setHeight(double H) { height = H; };
- //
- // int getNumOfLines() const { return numOfLines; };
- // void setNumOfLines(int num) { numOfLines = num; };
- //
- // double getLineLength() const { return lineLength; };
- // void setLineLength(double LL) { lineLength = LL; };
- //
- // double getSquareOfMain() const { return squareOfMain; };
- // void setSquare(double Sq) { squareOfMain = Sq; };
- //};
- //
- //int main()
- //{
- // Prism p;
- // p.setHeight(5.5);
- // cout << p.getHeight();
- // p.setNumOfLines(2);
- // cout << p.getNumOfLines();
- // p.setSquare(23);
- // cout << p.getSquareOfMain();
- // cout << p.getVolume();
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //#define _CRT_SECURE_NO_WARNINGS
- //#pragma warning(disable:4996)
- //
- //class String
- //{
- // char** strArr;
- // int numOfStr;
- // int size;
- //public:
- // String();
- // String(int size_, int numOfStr_);
- // void setString(int pos);
- // void showString(int pos) const;
- // void showString() const;
- // void addStrings(int pos1, int pos2);
- // int foundString(const char* str) const;
- //};
- //
- //String::String()
- //{
- // size = numOfStr = 0;
- // strArr = nullptr;
- //}
- //
- //String::String(int size_, int numOfStr_)
- //{
- // size = size_;
- // numOfStr = numOfStr_;
- // strArr = new char* [numOfStr];
- // for (int i = 0; i < numOfStr; ++i)
- // strArr[i] = new char[size];
- //}
- //
- //void String::setString(int pos)
- //{
- // if (pos >= numOfStr)
- // return;
- // cout << "Enter str " << pos << " - ";
- // cin.getline(strArr[pos], size, '\n');
- //}
- //
- //void String::showString(int pos) const
- //{
- // cout << endl << strArr[pos] << endl;
- //}
- //
- //void String::showString() const
- //{
- // cout << endl;
- // for(int pos = 0; pos < numOfStr; ++pos)
- // cout << strArr[pos] << endl;
- //}
- //
- //void String::addStrings(int pos1, int pos2)
- //{
- // int strlength = strlen(strArr[pos1]) + strlen(strArr[pos2]);
- // if (strlength >= size)
- // return;
- // for (int i = strlen(strArr[pos1]), j = 0; j < strlen(strArr[pos2]); ++i, ++j)
- // strArr[pos1][i] = strArr[pos2][j];
- // strArr[pos1][strlength] = '\0';
- //}
- //
- //int String::foundString(const char* str) const
- //{
- // for (int i = 0; i < numOfStr; ++i)
- // if (strncmp(strArr[i], str, size) == 0)
- // return i;
- // return -1;
- //}
- //
- //int main()
- //{
- // String str(256, 4);
- // for (int i = 0; i < 4; ++i)
- // str.setString(i);
- // for (int i = 0; i < 4; ++i)
- // str.showString(i);
- // str.showString();
- // cout << endl << str.foundString("LOX");
- // cout << endl << str.foundString("L1O2X3");
- // str.addStrings(0, 1);
- // str.showString(0);
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <string>
- //using namespace std;
- //
- //struct Znak
- //{
- // string name;
- // string zodiac;
- // int bday[3];
- //};
- //
- //void fillZnak(Znak book[], int numOfZnaks)
- //{
- // for (int i = 0; i < numOfZnaks; ++i)
- // {
- // cout << "Enter name: ";
- // cin >> book[i].name;
- // cout << "Enter znak: ";
- // cin >> book[i].zodiac;
- // cout << "Enter date of birth: ";
- // cin >> book[i].bday[0] >> book[i].bday[1] >> book[i].bday[2];
- // }
- //}
- //
- //void showZnaks(Znak book[], int numOfZnaks)
- //{
- // cout << endl;
- // for (int i = 0; i < numOfZnaks; ++i)
- // {
- // cout << book[i].name << endl;
- // cout << book[i].zodiac << endl;
- // cout << book[i].bday[0] << "." << book[i].bday[1] << "." << book[i].bday[2] << endl;
- // cout << endl;
- // }
- //
- //}
- //
- //void sortZnaks(Znak book[], int numOfZnaks)
- //{
- // for(int i = 0; i < numOfZnaks - 1; ++i)
- // for (int j = 0; j < numOfZnaks; ++j)
- // if (book[i].bday[1] > book[j].bday[1])
- // {
- // Znak temp = book[i];
- // book[i] = book[j];
- // book[j] = temp;
- // }
- //}
- //
- //void showZnaksWithMonth(Znak book[], int numOfZnaks, int month)
- //{
- // for(int i = 0; i < numOfZnaks; ++i)
- // if (book[i].bday[1] == month)
- // {
- // cout << book[i].name << endl;
- // cout << book[i].zodiac << endl;
- // cout << book[i].bday[0] << "." << book[i].bday[1] << "." << book[i].bday[2] << endl;
- // cout << endl;
- // }
- //}
- //
- //int main()
- //{
- // const int numOfZnaks = 8;
- // Znak book[numOfZnaks];
- // fillZnak(book, numOfZnaks);
- // showZnaks(book, numOfZnaks);
- // sortZnaks(book, numOfZnaks);
- // showZnaks(book, numOfZnaks);
- // cout << "Enter the number of month - ";
- // int month;
- // cin >> month;
- // showZnaksWithMonth(book, numOfZnaks, month);
- // return 0;
- //}
- //#include <iostream>
- //#include <vector>
- //#include <algorithm>
- //using namespace std;
- //
- //int main()
- //{
- // int arr[6][8] =
- // { -3, 39, 76, -24, -62, -56, 8, - 90,
- // -83, 54, 41, -77, -10, -5, -48, 52,
- // 24, -48, -82, 34, -31, 52, 68, 63,
- // -54, -97, -44, 9, 36, 0, 95, -12,
- // 91, -33, 68, 17, 27, 9, - 20, -20,
- // -12, 17, -44, 41, -19, 32, -10, -5
- // };
- // vector <int> pos;
- // for (int i = 0; i < 6; ++i)
- // for (int j = 0; j < 8; ++j)
- // if (arr[i][j] >= 0)
- // pos.push_back(arr[i][j]);
- // sort(pos.begin(), pos.end());
- // for (vector<int>::const_iterator i = pos.begin(); i != pos.end(); ++i)
- // cout << *i << ' ';
- // return 0;
- //}
- //#include <iostream>
- //using namespace std;
- //
- //int findMin(double* arr, int size)
- //{
- // double min = arr[0];
- // int index = 0;
- // for(int i = 0; i < size; ++i)
- // if (arr[i] < min)
- // {
- // min = arr[i];
- // index = i;
- // }
- // return index;
- //}
- //
- //double proiz(double* arr, int size)
- //{
- // bool start = false;
- // double pro = 1.0;
- // for (int i = 0; i < size; ++i)
- // {
- // if (arr[i] < 0 && start == true)
- // break;
- // if (start)
- // pro *= arr[i];
- // if (arr[i] < 0)
- // start = true;
- // }
- // return pro;
- //}
- //
- //void fillArr(double* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cin >> arr[i];
- //}
- //
- //void preobr(double* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // if (abs(arr[i]) < 1)
- // cout << arr[i] << " ";
- // for (int i = 0; i < size; ++i)
- // if (abs(arr[i]) >= 1)
- // cout << arr[i] << " ";
- //}
- //
- //int main()
- //{
- // cout << "Enter the size - ";
- // int size;
- // cin >> size;
- // double* arr = new double[size];
- // fillArr(arr, size);
- // cout << "Num of min = " << findMin(arr, size);
- // cout << "Proisvidenie = " << proiz(arr, size);
- // preobr(arr, size);
- // return 0;
- //}
- //#include <iostream>
- //#include <fstream>
- //using namespace std;
- //
- //void fillArr(int* arr, int size)
- //{
- // for (int i = 0; i < size; ++i)
- // cin >> arr[i];
- //}
- //
- //bool isPresent(const int* arr, int maxSize, int num)
- //{
- // for (size_t i = 0; i < maxSize; i++)
- // if (arr[i] == num)
- // return true;
- // return false;
- //}
- //
- //int arrayUnique(int* array, int size)
- //{
- // int count = 0;
- // int* temp = new int[size];
- // for (int i = 0; i < size; ++i)
- // if (!isPresent(array, i, array[i]))
- // temp[count++] = array[i];
- // for (int i = 0; i < count; ++i)
- // array[i] = temp[i];
- // return count;
- //}
- //
- //int main()
- //{
- // cout << "Enter the size - ";
- // int size;
- // cin >> size;
- // int* arr = new int[size];
- // cout << "Now fill the arr: ";
- // fillArr(arr, size);
- // int length = arrayUnique(arr, size);
- // for (size_t i = 0; i < length; i++)
- // {
- // cout << arr[i] << " ";
- // }
- // return 0;
- //}
- //#include <iostream>
- //#include <ctime>
- //#include <cstdlib>
- //using namespace std;
- //
- //int** createArr(int rows, int cols)
- //{
- // int** arr = new int* [rows];
- // for (int j = 0; j < cols; ++j)
- // arr[j] = new int[cols];
- // return arr;
- //}
- //
- //void fillArr(int** arr, int rows, int cols)
- //{
- // srand(static_cast<unsigned>(time(0)));
- // for (int i = 0; i < rows; ++i)
- // for (int j = 0; j < cols; ++j)
- // arr[i][j] = -100 + rand() % 200;
- //}
- //
- //void showArr(int** arr, int rows, int cols)
- //{
- // cout << endl;
- // for (int i = 0; i < rows; ++i)
- // {
- // for (int j = 0; j < cols; ++j)
- // {
- // cout.width(5);
- // cout << arr[i][j] << " ";
- // }
- // cout << endl;
- // }
- // cout << endl;
- //}
- //
- //int* fillCharact(int** arr, int rows, int cols)
- //{
- // int* crah = new int[cols] {0};
- // for (int i = 0; i < cols; ++i)
- // {
- // int sum = 0;
- // for (int j = 0; j < rows; ++j)
- // {
- // if (arr[j][i] < 0 && arr[j][i] % 2)
- // sum += abs(arr[j][i]);
- // }
- // crah[i] = sum;
- // }
- // return crah;
- //}
- //
- //void swapCols(int** arr, int rows, int cols, int* crah)
- //{
- // for(int i = 0; i < cols - 1; ++i)
- // for (int j = i; j < cols; ++j)
- // {
- // if (crah[i] > crah[j])
- // {
- // int temp = crah[i];
- // crah[i] = crah[j];
- // crah[j] = temp;
- // for (int k = 0; k < rows; ++k)
- // {
- // int temp = arr[k][i];
- // arr[k][i] = arr[k][j];
- // arr[k][j] = temp;
- // }
- // }
- // }
- //}
- //
- //void showChar(int* arr, int cols)
- //{
- // for (int j = 0; j < cols; ++j)
- // {
- // cout.width(5);
- // cout << arr[j] << " ";
- // }
- // cout << endl;
- //}
- //
- //int main()
- //{
- // cout << "Enter the num of rows - ";
- // int rows;
- // cin >> rows;
- // cout << "Enter the num of cols - ";
- // int cols;
- // cin >> cols;
- // int** arr = createArr(rows, cols);
- // fillArr(arr, rows, cols);
- // showArr(arr, rows, cols);
- // int* charact = fillCharact(arr, rows, cols);
- // showChar(charact, cols);
- // swapCols(arr, rows, cols, charact);
- // showArr(arr, rows, cols);
- // return 0;
- //}
- //#include <iostream>
- //
- //int getInt()
- //{
- // using std::cin;
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // std::cout << "Bad input. Try again. - ";
- // }
- // else
- // return num;
- // }
- //}
- //
- //int getDrib()
- //{
- // using std::cin;
- // int num;
- // while (true)
- // {
- // cin >> num;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // std::cout << "Bad input. Try again. - ";
- // }
- // else if (num <= 0)
- // std::cout << "Bad input. Only > 0. - ";
- // else
- // return num;
- // }
- //}
- //
- //class Fraction
- //{
- // int integer;
- // int numerator;
- // int denominator;
- //
- //public:
- //
- // static int numOfFractions;
- //
- // Fraction();
- // Fraction(int numerator_, int denominator_, int integer_ = 0);
- // Fraction(const Fraction& frac);
- // ~Fraction();
- //
- // static int getNumOfFractions();
- //
- // Fraction& operator=(const Fraction& frac);
- //
- // Fraction operator+(const Fraction& frac) const;
- // Fraction& operator+=(const Fraction& frac);
- //
- // Fraction operator-(const Fraction& frac) const;
- // Fraction& operator-=(const Fraction& frac);
- //
- // Fraction operator*(const Fraction& frac) const;
- // Fraction& operator*=(const Fraction& frac);
- //
- // Fraction operator/(const Fraction& frac) const;
- // Fraction& operator/=(const Fraction& frac);
- //
- // bool operator==(const Fraction& frac) const;
- // bool operator>(const Fraction& frac) const;
- // bool operator<(const Fraction& frac) const;
- // bool operator>=(const Fraction& frac) const;
- // bool operator<=(const Fraction& frac) const;
- //
- // friend std::istream& operator>>(std::istream& is, Fraction& frac);
- // friend std::ostream& operator<<(std::ostream& os, const Fraction& frac);
- //};
- //
- //int Fraction::numOfFractions = 0;
- //int Fraction::getNumOfFractions() { return numOfFractions; }
- //
- //Fraction::Fraction() : integer(0), numerator(1), denominator(1) {++numOfFractions;}
- //Fraction::Fraction(int numerator_, int denominator_, int integer_) : integer(integer_), denominator(denominator_), numerator(numerator_) {++numOfFractions;}
- //Fraction::Fraction(const Fraction& frac) : integer(frac.integer), numerator(frac.numerator), denominator(frac.denominator) { ++numOfFractions; }
- //Fraction::~Fraction() {--numOfFractions;}
- //
- //Fraction& Fraction::operator=(const Fraction& frac)
- //{
- // if (this == &frac)
- // return *this;
- // integer = frac.integer;
- // numerator = frac.numerator;
- // denominator = frac.denominator;
- // ++numOfFractions;
- // return (*this);
- //}
- //
- //Fraction Fraction::operator+(const Fraction& frac) const
- //{
- // int integ, den, nom;
- // if (denominator != frac.denominator)
- // {
- // den = denominator * frac.denominator;
- // nom = ((denominator * integer + numerator) * frac.denominator + (frac.denominator * frac.integer + frac.numerator) * denominator);
- // integ = nom / (denominator * frac.denominator);
- // if (nom < 0)
- // nom = -nom;
- // nom %= (denominator * frac.denominator);
- // }
- // else
- // {
- // den = denominator;
- // nom = (denominator * integer + numerator) + (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // }
- // Fraction res(nom, den, integ);
- // return res;
- //}
- //Fraction& Fraction::operator+=(const Fraction& frac)
- //{
- // int integ, den, nom;
- // if (denominator != frac.denominator)
- // {
- // den = denominator * frac.denominator;
- // nom = ((denominator * integer + numerator) * frac.denominator + (frac.denominator * frac.integer + frac.numerator) * denominator);
- // integ = nom / (denominator * frac.denominator);
- // if (nom < 0)
- // nom = -nom;
- // nom %= (denominator * frac.denominator);
- // }
- // else
- // {
- // den = denominator;
- // nom = (denominator * integer + numerator) + (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // }
- // integer = integ;
- // denominator = den;
- // numerator = nom;
- // return *this;
- //}
- //
- //Fraction Fraction::operator-(const Fraction& frac) const
- //{
- // int integ, den, nom;
- // if (denominator != frac.denominator)
- // {
- // den = denominator * frac.denominator;
- // nom = ((denominator * integer + numerator) * frac.denominator - (frac.denominator * frac.integer + frac.numerator) * denominator);
- // integ = nom / (denominator * frac.denominator);
- // if (nom < 0)
- // nom = -nom;
- // nom %= (denominator * frac.denominator);
- // }
- // else
- // {
- // den = denominator;
- // nom = (denominator * integer + numerator) - (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // }
- // Fraction res(nom, den, integ);
- // return res;
- //}
- //Fraction& Fraction::operator-=(const Fraction& frac)
- //{
- // int integ, den, nom;
- // if (denominator != frac.denominator)
- // {
- // den = denominator * frac.denominator;
- // nom = ((denominator * integer + numerator) * frac.denominator - (frac.denominator * frac.integer + frac.numerator) * denominator);
- // integ = nom / (denominator * frac.denominator);
- // if (nom < 0)
- // nom = -nom;
- // nom %= (denominator * frac.denominator);
- // }
- // else
- // {
- // den = denominator;
- // nom = (denominator * integer + numerator) - (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // }
- // integer = integ;
- // numerator = nom;
- // denominator = den;
- // return *this;
- //}
- //
- //Fraction Fraction::operator*(const Fraction& frac) const
- //{
- // int integ, den, nom;
- // nom = (denominator * integer + numerator) * (frac.denominator * frac.integer + frac.numerator);
- // den = denominator * frac.denominator;
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // Fraction res(nom, den, integ);
- // return res;
- //}
- //Fraction& Fraction::operator*=(const Fraction& frac)
- //{
- // int integ, den, nom;
- // nom = (denominator * integer + numerator) * (frac.denominator * frac.integer + frac.numerator);
- // den = denominator * frac.denominator;
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // numerator = nom;
- // denominator = den;
- // integer = integ;
- // return *this;
- //}
- //
- //Fraction Fraction::operator/(const Fraction& frac) const
- //{
- // int integ, den, nom;
- // nom = (denominator * integer + numerator) * frac.denominator;
- // den = denominator * (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // Fraction res(nom, den, integ);
- // return res;
- //}
- //Fraction& Fraction::operator/=(const Fraction& frac)
- //{
- // int integ, den, nom;
- // nom = (denominator * integer + numerator) * frac.denominator;
- // den = denominator * (frac.denominator * frac.integer + frac.numerator);
- // integ = nom / den;
- // if (nom < 0)
- // nom = -nom;
- // nom %= den;
- // denominator = den;
- // numerator = nom;
- // integer = integ;
- // return *this;
- //}
- //
- //bool Fraction::operator==(const Fraction& frac) const
- //{
- // double size1 = (static_cast<double>(denominator) * static_cast<double>(integer) + static_cast<double>(numerator)) / static_cast<double>(denominator);
- // double size2 = (static_cast<double>(frac.denominator) * static_cast<double>(frac.integer) + static_cast<double>(frac.numerator)) / static_cast<double>(frac.denominator);
- // return size1 == size2 ? true : false;
- //}
- //bool Fraction::operator>(const Fraction& frac) const
- //{
- // double size1 = (static_cast<double>(denominator)* static_cast<double>(integer) + static_cast<double>(numerator)) / static_cast<double>(denominator);
- // double size2 = (static_cast<double>(frac.denominator)* static_cast<double>(frac.integer) + static_cast<double>(frac.numerator)) / static_cast<double>(frac.denominator);
- // return size1 > size2 ? true : false;
- //}
- //bool Fraction::operator<(const Fraction& frac) const
- //{
- // return frac > (*this);
- //}
- //bool Fraction::operator>=(const Fraction& frac) const
- //{
- // return ((*this) > frac || (*this) == frac) ? true : false;
- //}
- //bool Fraction::operator<=(const Fraction& frac) const
- //{
- // return frac >= (*this);
- //}
- //
- //std::istream& operator>>(std::istream& is, Fraction& frac)
- //{
- // std::cout << "Enter the values of Fraction : \n";
- // std::cout << "Enter integer - ";
- // frac.integer = getInt();
- // std::cout << "Enter numerator - ";
- // frac.numerator = getDrib();
- // std::cout << "Enter denominator - ";
- // frac.denominator = getDrib();
- // return is;
- //}
- //std::ostream& operator<<(std::ostream& os, const Fraction& frac)
- //{
- // os << "\nFraction - " << frac.integer << ", " << frac.numerator << "/" << frac.denominator << std::endl;
- // return os;
- //}
- //
- //int main()
- //{
- // using std::cout;
- // using std::cin;
- // using std::endl;
- //
- //
- // return 0;
- //}
- //#include <iostream>
- //#include <climits>
- //
- //int getCash()
- //{
- // using std::cin;
- // int cash;
- // while (true)
- // {
- // cin >> cash;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // std::cout << "Bad input. Again - ";
- // }
- // else if (cash < 0)
- // std::cout << "Bad input. Only > 0 && < " << LONG_MAX << ". ";
- // else
- // return cash;
- // }
- //}
- //int getPenny()
- //{
- // using std::cin;
- // int penny;
- // while (true)
- // {
- // cin >> penny;
- // cin.ignore(32767, '\n');
- // if (cin.fail())
- // {
- // cin.clear();
- // cin.ignore(32767, '\n');
- // std::cout << "Bad input. Again - ";
- // }
- // else if (penny < 0 || penny >= 100)
- // std::cout << "Bad input. Only > 0 && < 100. ";
- // else
- // return penny;
- // }
- //}
- //
- //const int cashToPenny = 100;
- //
- //class Money
- //{
- // int cash;
- // int penny;
- //public:
- //
- // static int howManyMoney;
- // static int getHowManyMoney();
- //
- // Money();
- // Money(int cash_, int penny_ = 0);
- // Money(const Money& mon);
- // ~Money();
- //
- // Money& operator= (const Money& mon);
- // Money operator+ (const Money& mon) const;
- // Money& operator+=(const Money& mon);
- // Money operator- (const Money& mon) const;
- // Money& operator-=(const Money& mon);
- // Money operator* (const Money& mon) const;
- // Money& operator*=(const Money& mon);
- // Money operator/ (const Money& mon) const;
- // Money& operator/=(const Money& mon);
- // Money operator* (const double mon) const;
- // Money& operator*=(const double mon);
- // Money operator/ (const double mon) const;
- // Money& operator/=(const double mon);
- //
- // bool operator==(const Money& mon) const;
- // bool operator!=(const Money& mon) const;
- // bool operator> (const Money& mon) const;
- // bool operator< (const Money& mon) const;
- // bool operator>=(const Money& mon) const;
- // bool operator<=(const Money& mon) const;
- //
- // friend std::istream& operator>>(std::istream& is, Money& mon);
- // friend std::ostream& operator<<(std::ostream& os, const Money& mon);
- //};
- //
- //int Money::howManyMoney = 0;
- //int Money::getHowManyMoney() { return howManyMoney; }
- //
- //Money::Money() : cash(0), penny(0)
- //{ ++howManyMoney; }
- //Money::Money(int cash_, int penny_) : cash(cash_), penny(penny_)
- //{ ++howManyMoney; }
- //Money::~Money()
- //{ --howManyMoney; }
- //Money::Money(const Money& mon)
- //{
- // cash = mon.cash;
- // penny = mon.penny;
- // ++howManyMoney;
- //}
- //
- //Money& Money::operator= (const Money& mon)
- //{
- // if (this == &mon)
- // return (*this);
- // cash = mon.cash;
- // penny = mon.penny;
- // ++howManyMoney;
- // return (*this);
- //}
- //Money Money::operator+ (const Money& mon) const
- //{
- // long long sum = (cash * cashToPenny + penny) + (mon.cash * cashToPenny + mon.penny);
- // Money res(sum / cashToPenny, sum % cashToPenny);
- // return res;
- //}
- //Money& Money::operator+=(const Money& mon)
- //{
- // long long sum = (cash * cashToPenny + penny) + (mon.cash * cashToPenny + mon.penny);
- // cash = sum / cashToPenny;
- // penny = sum % cashToPenny;
- // return (*this);
- //}
- //Money Money::operator- (const Money& mon) const
- //{
- // long long sum = (cash * cashToPenny + penny) - (mon.cash * cashToPenny + mon.penny);
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // Money res(cas, pen);
- // return res;
- //}
- //Money& Money::operator-=(const Money& mon)
- //{
- // long long sum = (cash * cashToPenny + penny) - (mon.cash * cashToPenny + mon.penny);
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // cash = cas;
- // penny = pen;
- // return (*this);
- //}
- //Money Money::operator* (const Money& mon) const
- //{
- // long long sum = ((cash * cashToPenny + penny) * (mon.cash * cashToPenny + mon.penny)) / cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // Money res(cas, pen);
- // return res;
- //}
- //Money& Money::operator*=(const Money& mon)
- //{
- // long long sum = ((cash * cashToPenny + penny) * (mon.cash * cashToPenny + mon.penny)) / cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // cash = cas;
- // penny = pen;
- // return (*this);
- //}
- //Money Money::operator/ (const Money& mon) const
- //{
- // double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>((mon.cash * cashToPenny + mon.penny));
- // long long sum = sum1 * cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // Money res(cas, pen);
- // return res;
- //}
- //Money& Money::operator/=(const Money& mon)
- //{
- // double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>((mon.cash * cashToPenny + mon.penny));
- // long long sum = sum1 * cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // cash = cas;
- // penny = pen;
- // return (*this);
- //}
- //Money Money::operator* (const double mon) const
- //{
- // long long sum = ((cash * cashToPenny + penny) * (mon * cashToPenny)) / cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // Money res(cas, pen);
- // return res;
- //}
- //Money& Money::operator*=(const double mon)
- //{
- // long long sum = ((cash * cashToPenny + penny) * (mon * cashToPenny)) / cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // cash = cas;
- // penny = pen;
- // return (*this);
- //}
- //Money Money::operator/ (const double mon) const
- //{
- // double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>(mon * cashToPenny);
- // long long sum = sum1 * cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // Money res(cas, pen);
- // return res;
- //}
- //Money& Money::operator/=(const double mon)
- //{
- // double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>(mon * cashToPenny);
- // long long sum = sum1 * cashToPenny;
- // long cas = sum / cashToPenny, pen = sum % cashToPenny;
- // if (pen < 0)
- // pen = -pen;
- // cash = cas;
- // penny = pen;
- // return (*this);
- //}
- //
- //
- //bool Money::operator==(const Money& mon) const
- //{
- // return ((cash * cashToPenny + penny) == (mon.cash * cashToPenny + mon.penny)) ? true : false;
- //}
- //bool Money::operator!=(const Money& mon) const
- //{
- // return !((*this) == mon);
- //}
- //bool Money::operator> (const Money& mon) const
- //{
- // return ((cash * cashToPenny + penny) > (mon.cash * cashToPenny + mon.penny)) ? true : false;
- //}
- //bool Money::operator< (const Money& mon) const
- //{
- // return mon > (*this);
- //}
- //bool Money::operator>=(const Money& mon) const
- //{
- // return ((*this) > mon || (*this) == mon) ? true : false;
- //}
- //bool Money::operator<=(const Money& mon) const
- //{
- // return mon >= (*this);
- //}
- //
- //std::istream& operator>>(std::istream& is, Money& mon)
- //{
- // std::cout << "\nEnter the amount of cash - ";
- // mon.cash = getCash();
- // std::cout << "Enter the amount of pennys - ";
- // mon.penny = getPenny();
- // return is;
- //}
- //std::ostream& operator<<(std::ostream& os, const Money& mon)
- //{
- // if(mon.penny == 0)
- // os << "\nYour money - " << mon.cash << ",00" << "\n";
- // else
- // os << "\nYour money - " << mon.cash << "," << mon.penny << "\n";
- // return os;
- //}
- //
- //int main()
- //{
- // using namespace std;
- // Money M1(8, 49);
- // Money M2(16 , 80);
- // cout << M1 / M2;
- // cout << M2 / M1;
- // cout << M1 / 2;
- // cout << M1 / 3;
- // cout << M1 / 0.5;
- // return 0;
- //}
- #include <iostream>
- #include <cmath>
- int getPoint()
- {
- using std::cin;
- int num;
- while (true)
- {
- cin >> num;
- cin.ignore(32767, '\n');
- if (cin.fail())
- {
- cin.clear();
- cin.ignore(32767, '\n');
- std::cout << "Bad input. Try again - ";
- }
- else
- return num;
- }
- }
- const int numOfPoints = 4;
- struct Point
- {
- int x;
- int y;
- };
- class Trapeze
- {
- Point Points[numOfPoints];
- static int numOfTrapezes;
- public:
- Trapeze();
- Trapeze(Point P[numOfPoints]);
- Trapeze(const Trapeze& trap);
- ~Trapeze();
- double* calcLines();
- void showLines();
- bool isRight();
- double perimeter();
- double square();
- Trapeze& operator=(const Trapeze& trap);
- friend std::istream& operator>>(std::istream& is, Trapeze& trap);
- friend std::ostream& operator<<(std::ostream& os, const Trapeze& trap);
- };
- int Trapeze::numOfTrapezes = 0;
- Trapeze::Trapeze()
- {
- for (auto& x : Points)
- x.x = x.y = 0;
- ++numOfTrapezes;
- }
- Trapeze::Trapeze(Point P[numOfPoints])
- {
- for (size_t i = 0; i < numOfPoints; ++i)
- Points[i] = P[i];
- ++numOfTrapezes;
- }
- Trapeze::Trapeze(const Trapeze& trap)
- {
- for (size_t i = 0; i < numOfPoints; ++i)
- Points[i] = trap.Points[i];
- ++numOfTrapezes;
- }
- Trapeze::~Trapeze()
- {
- --numOfTrapezes;
- }
- double* Trapeze::calcLines()
- {
- double* arr = new double[numOfPoints];
- for (int i = 0; i < numOfPoints - 1; ++i)
- arr[i] = sqrt((Points[i + 1].x - Points[i].x) * (Points[i + 1].x - Points[i].x) + (Points[i + 1].y - Points[i].y) * (Points[i + 1].y - Points[i].y));
- arr[numOfPoints - 1] = sqrt((Points[numOfPoints - 1].x - Points[0].x) * (Points[numOfPoints - 1].x - Points[0].x)
- + (Points[numOfPoints - 1].y - Points[0].y) * (Points[numOfPoints - 1].y - Points[0].y));
- return arr;
- }
- void Trapeze::showLines()
- {
- double* arr = calcLines();
- std::cout << "\nLines - ";
- for (int i = 0; i < numOfPoints; ++i)
- std::cout << arr[i] << " ";
- delete[] arr;
- }
- bool Trapeze::isRight()
- {
- bool right = false;
- double* arr = calcLines();
- if (arr[0] == arr[2] || arr[1] == arr[3])
- right = true;
- delete[]arr;
- return right;
- }
- double Trapeze::perimeter()
- {
- double* arr = calcLines();
- double P = 0.0;
- for (int i = 0; i < numOfPoints; ++i)
- P += arr[i];
- return P;
- }
- double Trapeze::square()
- {
- double* arr = calcLines();
- double square = 0.0;
- if (isRight())
- {
- double p = perimeter() / 2.0;
- if (arr[0] == arr[2])
- square = sqrt((p - arr[1]) * (p - arr[3]) * (p - arr[0]) * (p - arr[0]));
- else if (arr[1] == arr[3])
- square = sqrt((p - arr[0]) * (p - arr[2]) * (p - arr[1]) * (p - arr[1]));
- }
- else
- square = 0.0;
- delete[] arr;
- return square;
- }
- Trapeze& Trapeze::operator=(const Trapeze& trap)
- {
- for (size_t i = 0; i < numOfPoints; ++i)
- Points[i] = trap.Points[i];
- ++numOfTrapezes;
- return (*this);
- }
- std::istream& operator>>(std::istream& is, Trapeze& trap)
- {
- std::cout << "Enter the points of trapeze - \n";
- for (int i = 0; i < numOfPoints; ++i)
- {
- std::cout << "Enter x" << i << " - ";
- trap.Points[i].x = getPoint();
- std::cout << "Entet y" << i << " - ";
- trap.Points[i].y = getPoint();
- }
- return is;
- }
- std::ostream& operator<<(std::ostream& os, const Trapeze& trap)
- {
- os << "\n Your trapeze: ";
- for (int i = 0; i < numOfPoints; ++i)
- os << "(" << trap.Points[i].x << "," << trap.Points[i].y << "); ";
- return os;
- }
- int main()
- {
- using namespace std;
- Trapeze Trap[numOfPoints];
- for (int i = 0; i < numOfPoints; ++i)
- cin >> Trap[i];
- for (int i = 0; i < numOfPoints; ++i)
- cout << Trap[i];
- for (int i = 0; i < numOfPoints; ++i)
- Trap[i].showLines();
- for (int i = 0; i < numOfPoints; ++i)
- cout << Trap[i].isRight() << endl;
- for (int i = 0; i < numOfPoints; ++i)
- cout << Trap[i].perimeter() << endl;
- for (int i = 0; i < numOfPoints; ++i)
- cout << Trap[i].square() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement