Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 08.05.2017, 19:26   #1
vladrrom
Пользователь
 
Регистрация: 14.12.2016
Сообщений: 54
По умолчанию Абстрактный класс - C++

Здравствуйте. Нужна помощь с кодом. Тема задания "Классы(Абстрактные)". Задания прикреплю как и код. Кому не сложно помогите, пожалуйста. Код не компилируется.

Цитата:
Задание:
1. Создать абстрактный класс Software с методами, позволяющими вывести на экран информацию о программном обеспечении, а также определить соответствие возможности использования (на момент текущей даты).
2. Создать производные классы: FreeSoftware (название, производитель), SharewareSoftware (название, производитель, дата установки, срок бесплатного использования), ProprietarySoftware (название, производитель, цена, дата установки, срок использования).
3. Создать базу (массив) из n видов программного обеспечения, вывести полную информацию из базы на экран, а также организовать поиск программного обеспечения, которое допустимо использовать на текущую дату.
Код:
Код:
#include <iostream>
#include <string>

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Date {
private:
	int year, month, day;
public:
	Date() {
		year = 1; month = 1; day = 1;
	}
	Date(int y, int m, int d) { year = y; month = m; day = d; }

	void setDate(int new_y, int new_m, int new_d){
		year = new_y;
		month = new_m;
		day = new_d;
	}

	int getYear(){
		return year;
	}
	int getMonth(){
		return month;
	}
	int getDay(){
		return day;
	}

	void Show() {
		cout << day << "." << month << "." << year << endl;
	}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Software {
protected:
	string p_name, p_manufacturer;
public:
	Software() {}
	Software(string Name, string Manufacturer) : p_name(Name), p_manufacturer(Manufacturer) {}
	virtual void Show(){
		cout << "Name " << p_name << endl;
		cout << "Manufacturer " << p_manufacturer << endl;
	}
	virtual void TimeUse(Date *dat) = 0;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FreeSoftware : public Software {
public:
	FreeSoftware() {}
	FreeSoftware(string Name, string Manufacturer) : Software(Name, Manufacturer)
	{}

	void setFreeSoftware(string new_Name, string new_Manufacturer) {
		p_name = new_Name;
		p_manufacturer = new_Manufacturer;
	}

	string getName() {
		return p_name;
	}
	string getManufacturer() {
		return p_manufacturer;
	}

	void TimeUse(Date *data) {
		cout << "Not limited" << endl;
	}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class SharewareSoftware : public Software {
private:
	Date *p_date;
	int p_freetimeuse;
public:
	SharewareSoftware() {}
	SharewareSoftware(string Name, string Manufacturer, Date *Date, int Freetime) : Software(Name, Manufacturer), p_date(Date), p_freetimeuse(Freetime)
	{}

	void setSharewareSoftware(string new_Name, string new_Manufacturer, Date *new_Date, int new_FreeTimeUse) {
		p_name = new_Name;
		p_manufacturer = new_Manufacturer;
		p_date = new_Date;
		p_freetimeuse = new_FreeTimeUse;
	}

	string getName() {
		return p_name;
	}
	string getManufacturer() {
		return p_manufacturer;
	}
	Date *getDate() {
		return p_date;
	}
	int getFreeTimeUse() {
		return p_freetimeuse;
	}

	void Show() {
		Software::Show();
		cout << "Date "; p_date->Show();
		cout << "FreeTimeUse " << p_freetimeuse << " year(s)" << endl;
	}

	void TimeUse(Date *data1) {
		if (p_date->getYear() + p_freetimeuse < data1->getYear()) {
			if (p_date->getMonth() < data1->getMonth()) {
				if (p_date->getDay() < data1->getDay()) {
					cout << "It is possible to use" << endl;
				}
				else cout << "Cant't use it" << endl;
			}
			else cout << "Cant't use it" << endl;
		}
		else cout << "Cant't use it" << endl;
	}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ProprietarySoftware : public Software {
private:
	Date *p_date;
	int p_timeuse;
	float p_price;
public:
	ProprietarySoftware(){}
	ProprietarySoftware(string Name, string Manufacturer, Date *Date, int TimeUse, float Price) : Software(Name, Manufacturer), p_date(Date), p_timeuse(TimeUse), p_price(Price)
	{}

	void setSharewareSoftware(string new_Name, string new_Manufacturer, Date *new_Date, int new_TimeUse, float new_Price) {
		p_name = new_Name;
		p_manufacturer = new_Manufacturer;
		p_date = new_Date;
		p_timeuse = new_TimeUse;
		p_price = new_Price;
	}

	string getName() {
		return p_name;
	}
	string getManufacturer() {
		return p_manufacturer;
	}
	Date *getDate() {
		return p_date;
	}
	int getTimeUse() {
		return p_timeuse;
	}
	float getPrice() {
		return p_price;
	}

	void Show() {
		Software::Show();
		cout << "Date "; p_date->Show();
		cout << "TimeUse " << p_timeuse << " year(s)" << endl;
		cout << "Price " << p_price << endl;
	}

	void TimeUse(Date *data2) {
		if ((p_date->getYear() + p_timeuse) < data2->getYear()) {
			if (p_date->getMonth() < data2->getMonth()) {
				if (p_date->getDay() < data2->getDay()) {
					cout << "It is ppssible to use" << endl;
				}
				else cout << "Cant't use it" << endl;
			}
			else cout << "Cant't use it" << endl;
		}
		else cout << "Cant't use it" << endl;
	}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
	int year, month, day;
	cout << "Enter date ";
	cout << "day "; cin >> day;
	cout << "\t month "; cin >> month;
	cout << "\t year "; cin >> year;
	Date *today = new Date(day, month, year);

	Software *objects[3];
	objects[0] = new FreeSoftware("Programma", "Sozdatel");
	objects[1] = new SharewareSoftware("Programma2", "Sozdatel2", new Date(15, 3, 2017), 2);
	objects[2] = new ProprietarySoftware("Programma3", "Sozdatel3", new Date(24, 11, 2016), 1, 100);

	for (int i = 0; i < 4; i++)
	{
		objects[i]->Show();
		cout << "Software: ";
		objects[i]->TimeUse(new Date(day, month, year));
	}
	for (int i = 0; i < 4; i++)
	{
		delete objects[i];
	}
	system("pause");
	return 0;
}
vladrrom вне форума Ответить с цитированием
Старый 09.05.2017, 11:56   #2
vladrrom
Пользователь
 
Регистрация: 14.12.2016
Сообщений: 54
По умолчанию

Тема ещё актуальна
vladrrom вне форума Ответить с цитированием
Старый 09.05.2017, 12:45   #3
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,709
По умолчанию

Так если не компилируется, то компилятор написал какие ошибки. Где они?
p51x вне форума Ответить с цитированием
Старый 09.05.2017, 15:35   #4
vladrrom
Пользователь
 
Регистрация: 14.12.2016
Сообщений: 54
По умолчанию

Начало компилироваться, изменил в коде блок main
Ошибка была в пересчете объектов. Я случайно написал до 4, а нужно было до 3.
Но проблема теперь в другом. Думаю, что это неправильно написано, но не имею представления как написать по другому
objects[i]->TimeUse(new Date(day, month, year));
vladrrom вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Абстрактный класс Сырги C# (си шарп) 3 22.11.2012 01:13
абстрактный класс meta13 C# (си шарп) 2 22.03.2012 19:14
c# абстрактный класс tanek Помощь студентам 1 22.02.2012 11:23
абстрактный класс С++ zhenya.ya Помощь студентам 0 05.11.2010 20:23
Наследование: абстрактный класс zak Общие вопросы C/C++ 4 22.12.2007 13:49