» »

Vodenje videoteke v C++

Vodenje videoteke v C++

zila90 ::

Pozdravljeni!

Prejšnji teden smo dobili v šoli nalogo da moramo narediti program za vodenje videoteke. Navodila so naslednja:

Izdelajte prijazen uporabniški vmesnik z menijem.
Minimalne zahteve:
- vsaj trije razredi
- dedovanje
- uporaba konstruktorjev in destruktorjev.
- vsaj v enem razredu uporabite več kot en konstruktor
- uporabite inicializacijski seznam
- uporaba kazalcev, vedno ko je to smiselno
- implementiranje arhiviranje v datoteko in branje iz datoteke (ni obvezno)

Nimam ravno ne časa in ne volje da bi se spravil zraven, na googlu pa tudi ni ničesar. Tako da prosim za pomoč, če bi mi kdo napisal program!
HVALA!!!

BigWhale ::

> Nimam ravno ne časa in ne volje da bi se spravil zraven

Nimas casa za solo? Volje?

A ti zrihtam kako sluzbo pri pridajalcih hostanjev na tromostovju? ;>

zila90 ::

>A ti zrihtam kako sluzbo pri pridajalcih hostanjev na tromostovju?

Zelo smešno...aja pa hvala za pomoč ;)

infiniteLoop ::

Za prodajalca kostanjev rabis vsaj voljo (stanje na mrazu, delovni cas, ...)

Priporocam zivljenje doma pri starsih in vlecenje socialke. To ti bo pisano na kozo. :P
None of us is as dumb as all of us.

user4683 ::

100EUR

Tutankhamun ::

Ostalo pa sam naredi, kar še rabš. Pa sam ugotov kako to dela. :) Upam da ti bo kej pomagal...

class CVideo
{
public:
	CVideo (string name) : m_name (name), m_count (1) {}
	CVideo (string name, int count) : m_name (name), m_count (count) {}

	int Count () { return m_count; }
	string Name () const { return m_name; }

	void DecrementCount () { if (m_count > 0) m_count--; }
	void IncrementCount () { m_count++; }

private:
	string		m_name;
	int			m_count;
};


class CUser
{
public:
	virtual bool RentVideo (CVideo *video)
	{
		m_rentedVideos.push_back (video);
		return true;
	}

	virtual bool ReturnVideo (CVideo *video)
	{
		vRents::iterator	m_end = m_rentedVideos.end ();

		for (vRents::iterator iter = m_rentedVideos.begin (); iter < m_end; iter++)
		{
			CVideo *vid = *iter;
			if (video == vid)
			{
				m_rentedVideos.erase (iter);
				return true;
			}
		}

		return false;
	}

	virtual void ShowRented ()
	{
		vRents::iterator	m_end = m_rentedVideos.end ();

		for (vRents::iterator iter = m_rentedVideos.begin (); iter < m_end; iter++)
			cout << ((CVideo*)*iter)->Name () << endl;
	}

private:
	typedef vector <CVideo*> vRents;
	vRents	m_rentedVideos;
};


class CCustomer : CUser
{
public:
	CCustomer (string name) : CUser () { m_name = name; }
	
	bool RentVideo (CVideo *video)
	{
		if (video->Count ())
		{
			video->DecrementCount ();
			CUser::RentVideo (video);
			return true;
		}
		return false;
	}

	bool ReturnVideo (CVideo *video)
	{
		if (CUser::ReturnVideo (video))
		{
			video->IncrementCount ();
			return true;
		}

		return false;
	}

	string Name () const { return m_name; }

private:
	string		m_name;
};

class CVideoRent
{
public:
	~CVideoRent ()
	{
		vector <CVideo*>::iterator vEnd = m_videos.end ();
		vector <CUser*>::iterator uEnd = m_users.end ();

		for (vector <CVideo*>::iterator iter = m_videos.begin (); iter < vEnd; iter++)
			delete ((CVideo*)*iter);

		for (vector <CUser*>::iterator iter = m_users.begin (); iter < uEnd; iter++)
			delete ((CUser*)*iter);

		m_videos.clear ();
		m_users.clear ();
	}

	void AddUser (string name) { m_users.push_back ((CUser*) new CCustomer (name)); }
	void AddVideo (CVideo *video) { m_videos.push_back (video); }

	void DisplayAllVideos ()
	{
		vector <CVideo*>::iterator iEnd = m_videos.end ();

		for (vector <CVideo*>::iterator iter = m_videos.begin (); iter < iEnd; iter++)
			cout << ((CVideo*)*iter)->Name () << " Availability: " <<  ((CVideo*)*iter)->Count () << endl;
	}

	void DisplayAllUsers ()
	{
		vector <CUser*>::iterator iEnd = m_users.end ();

		for (vector <CUser*>::iterator iter = m_users.begin (); iter < iEnd; iter++)
			cout << ((CCustomer*)*iter)->Name () << endl;
	}

	bool RentVideo (string user, string video)
	{
		CUser *usr;
		CVideo *vid;
	
		if (!((usr = this->GetUser (user)) && (vid = this->GetVideo (video)))) return false;

		return usr->RentVideo (vid);
	};

	bool ReturnVideo (string user, string video)
	{
		CUser *usr;
		CVideo *vid;

		if (!((usr = this->GetUser (user)) && (vid = this->GetVideo (video)))) return false;

		return usr->ReturnVideo (vid);
	};

	CUser * GetUser (string name)
	{
		vector <CUser*>::iterator iEnd = m_users.end ();
		vector <CUser*>::iterator iter;

		for (iter = m_users.begin (); iter < iEnd; iter++)
		{
			CCustomer *user = (CCustomer*)*iter;
			if (!name.compare (user->Name ()))
				return (CUser*)user;
		}

		return NULL;
	}

	CVideo * GetVideo (string name)
	{
		vector <CVideo*>::iterator iEnd = m_videos.end ();
		vector <CVideo*>::iterator iter;

		for (iter = m_videos.begin (); iter < iEnd; iter++)
		{
			CVideo *video = (CVideo*)*iter;
			if (!name.compare (video->Name ()))
				return video;
		}

		return NULL;
	}

private:
	vector <CVideo*>	m_videos;
	vector <CUser*>		m_users;
};


int main(int argc, char* argv[])
{
	CVideoRent vr;

	// all users
	vr.AddUser ("david");
	vr.AddUser ("nika");
	vr.AddUser ("branko");
	vr.AddUser ("uros");
	vr.AddUser ("duska");
	vr.DisplayAllUsers ();

	// all videos
	vr.AddVideo (new CVideo ("alien", 2));
	vr.AddVideo (new CVideo ("titanic", 6));
	vr.AddVideo (new CVideo ("simpsons", 3));
	vr.AddVideo (new CVideo ("cinderela"));
	vr.AddVideo (new CVideo ("the lion king"));
	vr.DisplayAllVideos ();

	// nika rented a video
	vr.RentVideo ("nika", "titanic");
	vr.DisplayAllVideos ();

	// nika returned a video
	vr.ReturnVideo ("nika", "titanic");
	vr.DisplayAllVideos ();

	// david rented some videos
	vr.RentVideo ("david", "alien");
	vr.RentVideo ("david", "simpsons");
	vr.DisplayAllVideos ();

	// what videos david rented
	CUser *user = vr.GetUser ("david");
	if (user)
		user->ShowRented ();
	return 0;
}
AMD Phenom QUAD 9950 Black Edition, 8GB


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

C++ 2 NALOGI

Oddelek: Programiranje
121047 (815) Tutankhamun
»

c++ urejanje

Oddelek: Programiranje
51202 (1149) mchaber
»

statistika črk v stringu C++

Oddelek: Programiranje
112063 (1799) Tutankhamun
»

[Java] Preverjanje polja za iste stringe

Oddelek: Programiranje
81129 (1007) infiniteLoop
»

[JAVA] zaustavitev niti (threadov)

Oddelek: Programiranje
223161 (3161) morbo

Več podobnih tem