Перейти к содержанию

Контрольная работа по программированию


pacman

Рекомендуемые сообщения

Ладно, сделаю тебе доброе дело.

 

c++11:

1.

#include <iostream>

struct Base {
	Base() { }
	~Base() { }
	char base_func(int a, int  {
		return (char)((a + *(a + );
	}
};

int main() {
	auto *b = new Base;
	std::cout << b->base_func(1, 2) << std::endl;
	delete b;
}
2.

#include <iostream>

struct Base {
	Base() { }
	~Base() { }
	char base_func(int a, int  {
		return (char)((a + *(a + );
	}
};

class Derived : public Base {
	int a, b;
public:
	Derived() = default;
	Derived(int a, int  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(int a, int  {
		this->a = a;
		this->b = b;
	}
	void get(int &a, int  {
		a = this->a;
		b = this->b;
	}
	int derived_func() {
		return base_func(a, ;
	}
};

int main() {
	auto *d = new Derived(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
}
3.

#include <iostream>

template <typename T>
struct Base {
	Base() { }
	~Base() { }
	char base_func(T a, T  {
		return (char)((a + *(a + );
	}
};

template <typename T>
class Derived : public Base<T> {
	T a, b;
public:
	Derived() = default;
	Derived(T a, T  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(T a, T  {
		this->a = a;
		this->b = b;
	}
	void get(T &a, T  {
		a = this->a;
		b = this->b;
	}
	T derived_func() {
		return this->base_func(a, ;
	}
};

int main() {
	auto *d = new Derived<int>(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
}
4.

#include <iostream>

class Base {
protected:
	Base() { }
public:
	virtual ~Base() { }
	virtual char base_func(int a, int  {
		return (char)((a + *(a + );
	}
	virtual int derived_func() = 0;
};

class Derived : public Base {
	int a, b;
public:
	Derived() = default;
	Derived(int a, int  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(int a, int  {
		this->a = a;
		this->b = b;
	}
	void get(int &a, int  {
		a = this->a;
		b = this->b;
	}
	virtual int derived_func() {
		return base_func(a, ;
	}
};

int main() {
	Base *d = new Derived(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
}

 

 

c++03:

1.

#include <iostream>

struct Base {
	Base() { }
	~Base() { }
	char base_func(int a, int  {
		return (char)((a + *(a + );
	}
};

int main() {
	Base *b = new Base;
	std::cout << b->base_func(1, 2) << std::endl;
	delete b;
	return 0;
}
2.

#include <iostream>

struct Base {
	Base() { }
	~Base() { }
	char base_func(int a, int  {
		return (char)((a + *(a + );
	}
};

class Derived : public Base {
	int a, b;
public:
	Derived() {};
	Derived(int a, int  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(int a, int  {
		this->a = a;
		this->b = b;
	}
	void get(int &a, int  {
		a = this->a;
		b = this->b;
	}
	int derived_func() {
		return base_func(a, ;
	}
};

int main() {
	Derived *d = new Derived(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
	return 0;
}
3.

#include <iostream>

template <typename T>
struct Base {
	Base() { }
	~Base() { }
	char base_func(T a, T  {
		return (char)((a + *(a + );
	}
};

template <typename T>
class Derived : public Base<T> {
	T a, b;
public:
	Derived() { };
	Derived(T a, T  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(T a, T  {
		this->a = a;
		this->b = b;
	}
	void get(T &a, T  {
		a = this->a;
		b = this->b;
	}
	T derived_func() {
		return this->base_func(a, ;
	}
};

int main() {
	Derived<int> *d = new Derived<int>(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
	return 0;
}
4.

#include <iostream>

class Base {
protected:
	Base() { }
public:
	virtual ~Base() { }
	virtual char base_func(int a, int  {
		return (char)((a + *(a + );
	}
	virtual int derived_func() = 0;
};

class Derived : public Base {
	int a, b;
public:
	Derived() { };
	Derived(int a, int  {
		this->a = a;
		this->b = b;
	}
	~Derived() {} 
	void put(int a, int  {
		this->a = a;
		this->b = b;
	}
	void get(int &a, int  {
		a = this->a;
		b = this->b;
	}
	virtual int derived_func() {
		return base_func(a, ;
	}
};

int main() {
	Base *d = new Derived(1, 2);
	std::cout << d->derived_func() << std::endl;
	delete d;
	return 0;
}

 

 

P. S. Не по программированию, а по C++ T_T. Учись хоть тему озаглавливать правильно.

Изменено пользователем vit9696
Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...

Важная информация

Мы разместили cookie-файлы на ваше устройство, чтобы помочь сделать этот сайт лучше. Вы можете изменить свои настройки cookie-файлов, или продолжить без изменения настроек.