Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void test_const() {
- const int y1 = 17;
- //int& refY1 = y1;
- int x = 17, y = 27;
- const int* pcY1;
- pcY1 = &y1;
- pcY1 = &x;
- cout << pcY1 << " " << *pcY1 << endl;
- //*pcY1 = 18;
- x++;
- cout << pcY1 << " " << *pcY1 << endl;
- const int* pM;
- pM = &x;
- pM = &y;
- int* const pR = &x;
- *pR = 37;
- }
- void my_swap(int*x, int* y);
- void test_my_swap() {
- int x = 3, y = 5;
- cout << "x:" << x << " " << &x << endl;
- cout << "y:" << y << " " << &y << endl;
- my_swap(&x, &y);
- cout << "x:" << x << " " << &x << endl;
- cout << "y:" << y << " " << &y << endl;
- }
- template <typename T1, typename T2>
- void my_swap2(T1& s1, T2& s2) {
- T1 temp = s1;
- s1 = (T1)s2;
- s2 = temp;
- }
- template <typename T>
- void my_swap(T& s1, T& s2) {
- T temp = s1;
- s1 = s2;
- s2 = temp;
- }
- void test_string() {
- string name1 = "AB";
- string name2 = "AA";
- if (name1 < name2) {
- cout << name1 << " " << name2 << endl;
- }
- else {
- cout << name2 << " " << name1 << endl;
- }
- }
- void test_IvanVasiliy(){
- string name1 = "Ivan";
- string name2 = "Vasya";
- my_swap(name1, name2);
- cout << name1 << endl;
- cout << name2 << endl;
- }
- struct Car {
- string name;
- string color;
- string number;
- double price;
- double volume;
- void show() {
- cout << color << " " << name << " " << price;
- }
- };
- struct Cars {
- Car* cars;
- int num_cars = 0;
- void add(Car car) {
- Car* buff = new Car[num_cars + 1];
- for (int k = 0; k < num_cars; ++k) {
- buff[k] = cars[k];
- }
- buff[num_cars] = car;
- if (num_cars > 0)
- delete[] cars;
- cars = buff;
- num_cars++;
- }
- void show() {
- for (int k = 0; k < num_cars; ++k) {
- cars[k].show();
- cout << endl;
- }
- }
- };
- void main() {
- Cars cars;
- Car car{ "BMV", "Red", "a777po 161", 2.7, 4.4 };
- cars.add(car);
- car.name = "VAZ";
- car.color = "White";
- car.number = "x132py 161";
- car.price = 0.7;
- car.volume = 1.6;
- cars.add(car);
- car.name = "VAZ";
- car.color = "White";
- car.number = "T132py 161";
- car.price = 0.7;
- car.volume = 1.6;
- cars.add(car);
- cars.show();
- }
- void my_swap(int* x, int* y) {
- int tmp = *x;
- cout << "x:" << x << endl;
- cout << "y:" << y << endl;
- *x = *y;
- *y = tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment