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

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


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

Опубликовано

Помогите другу моему решить контрольную работу по программированию

post-17253-0-97667500-1429867932_thumb.jpg

Опубликовано (изменено)

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

 

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
  • Улыбнуло 1
  • Согласен 1

Пожалуйста, войдите, чтобы комментировать

Вы сможете оставить комментарий после входа в



Войти
×
×
  • Создать...