Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // just c++ small traning
- #include <iostream>
- #include <iomanip> //not needed
- #include <assert.h>
- using namespace std;
- void swapPoint(int*a, int*b);
- void swapRef(int & a, int & b);
- struct Time
- {
- int s;
- int m;
- int h;
- };
- Time clon(const Time& n);
- void Time_modef(Time& ref) // copy by ref (c++)
- {
- int sec_to_min = (ref.s / 60);
- int min_to_hour = (ref.m + sec_to_min) / 60;
- ref.s = ref.s % 60;
- ref.m = (ref.m + sec_to_min) % 60;
- ref.h = (ref.h + min_to_hour) % 24;
- /*print*/
- cout << ref.s << "," << ref.m << "," << ref.h << endl;
- }
- void Time_modef2(Time& ref)
- {
- int sec_to_min = (ref.s / 60);
- int min_to_hour = (ref.m + sec_to_min) / 60;
- ref.s = ref.s % 60;
- ref.m = (ref.m + sec_to_min) % 60;
- ref.h = (ref.h + min_to_hour) % 24;
- }
- Time* alloc_time(int ptr2)
- {
- int n;
- cout << "Enter how many values:" << endl;
- cin >> n;
- Time* array_of_structs = new Time[n];
- assert(array_of_structs);
- for (int i = 0; i < n; i++)
- {
- cout << "enter hour,min,sec:";
- cin >> array_of_structs[i].h >> array_of_structs[i].m >> array_of_structs[i].s;
- Time_modef2(array_of_structs[i]);
- ptr2 = n;
- //return array_of_structs;
- }
- for (int i = 0; i < n; i++)
- {
- cout << array_of_structs[i].h << "," << array_of_structs[i].m << "," << array_of_structs[i].s << endl;
- }
- return array_of_structs;
- }
- void main()
- {
- int temp = NULL;
- Time v1;
- v1.s = 70;
- v1.m = 128;
- v1.h = 3;
- Time_modef(v1);
- Time* v2 = alloc_time(temp);
- /* new targil 2*/
- int a = 5;
- int b = 10;
- cout << "before:" << a << "," << b << endl;
- swapPoint(&a, &b);
- cout << "after:" << a << "," << b << endl;
- int x = 5;
- int y = 10;
- cout << "before:" << x << "," << y << endl;
- swapRef(x, y);
- cout << "after:" << x << "," << y << endl;
- /*targil 2_ver b */
- Time v55;
- v55.h = 22;
- v55.m = 77;
- v55.s = 22;
- clon(v1);
- clon(v55);
- cout << "time clons:v1 & (v55 no time manipulation)" << endl;
- cout << v55.h << ":" << v55.m << ":" << v55.s << endl;
- cout << v1.h << ":" << v1.m << ":" << v1.s << endl;
- Time_modef(v55);
- cout << "time clons: (v55 with time manipulation)" << endl;
- cout << v55.h << ":" << v55.m << ":" << v55.s << endl;
- }
- void swapPoint(int* a, int* b)
- {
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- void swapRef(int& a, int& b)
- {
- int temp = a;
- a = b;
- b = temp;
- }
- Time clon(const Time& n)
- {
- Time temp_clone;
- temp_clone = n;
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement