Oktató hiányában elmaradt. Mindenesetre itt a tárgy honlapja.
Programozás nyelvek 2. (C++, Java) - 1. óra
szeptember 14, 2012 08:57
Az oldal töltődik…
Oktató hiányában elmaradt. Mindenesetre itt a tárgy honlapja.
diego2.swf
diego.zip (html5 akart lenni, de nem nagyon jött össze 🙂
https://docs.google.com/document/d/1SX0tRMfup9jNVCXMm9SLYfgUPwRUIeWCark-ztk15mM/edit
main:
int main(){
int be=0;
/* vector<int > vec(10); typename vector<int>::iterator it; for(vector<int>::iterator it=vec.begin();it!=vec.end();++it){ *it }*/list<konyv> adatbazis;
do{
cout << "1. beszur" << endl;
cout << "2. torles" << endl;
cout << "11. listazas" << endl;
cout << ">: ";
cin >> be;
if(be==1){beszur(adatbazis);}
if(be==2){torol(adatbazis);}
if(be==11){listaz(adatbazis);}
} while (be<12);
return 0;
}header:
#include <iostream>#include <list>using namespace std;struct konyv{
string szerzo; string cim;int ar;
int db;
};
void beszur(list<konyv> &adatbazis){
konyv tmp;cout << "Szerzo: ";
cin >> tmp.szerzo;
cout << "Cim: ";
cin >> tmp.cim;
cout << "Ar: ";
cin >> tmp.ar;
cout << "Db: ";
cin >> tmp.db;
adatbazis.push_back(tmp);
}void torol(list<konyv> &adatbazis){
int pos;
cout << "Pozíció: ";
cin >> pos;
list<konyv>::iterator it;
it=adatbazis.begin();
adatbazis.erase((it+pos));
}void listaz(list<konyv> adatbazis){
list<konyv> adatbazis::iterator it;
for (it=adatbazis.begin() ; it != adatbazis.end(); it++){
konyv tmp=*it;
cout << tmp.szerzo << " " << tmp.cim << " " << tmp.ar << " " << tmp.db << endl;
}}https://docs.google.com/document/d/1SivPVqXB9kCiKycBCkvScJMFX84xeHjVY0WMqkMNjxs/edit
/**************************************************************** * * Purpose: Basic example of pipe. * Read and write fixed length records across a pipe. * This is about a simple as they come... * ******************************************************************/#include <sys/types.h>#include <unistd.h> /* pipe. */#include <signal.h>void Child (int Handle);
void Parent (int Handle);
void main()
{ pid_t Pid;int fd[2];
pipe(fd); /* Create two file descriptors */
Pid = fork();
if ( Pid == 0) /* Child */
{close(fd[0]);
Child(fd[1]);
puts("Child end");
}else /* Parent. */
{close(fd[1]);
Parent(fd[0]);
puts("Parent end");
}}/**************************************************************** * * The Child sends data to the parent. * ****************************************************************/void Child(int Handle)
{char Buff[]="Martin 1 abcdefghijklmnop ";
write(Handle, Buff, strlen(Buff)+1);
Buff[7] = '2';
write(Handle, Buff, strlen(Buff)+1);
Buff[7] = '3';
write(Handle, Buff, strlen(Buff)+1);
Buff[7] = '4';
write(Handle, Buff, strlen(Buff)+1);
close(Handle);
}/**************************************************************** * * Read the data sent by the child. * ****************************************************************/void Parent(int Handle)
{char Buff[50];
/* ... Read EXACTLY the number of bytes sent. ... 0 is returned when the pipe is closed by the child. */while (read(Handle,Buff, 27) > 0)
{printf("%sn", Buff);
}}https://docs.google.com/document/d/19Nl9-33m5tZruWxhdzQ9anPBUJcXwU0BxqEnrvcpsjM/edit
main:
#include <iostream>#include "verem.h"using namespace std;int main () {
Stack<int> verem;
verem.push(1);
cout << verem.top() <<endl;
return 0;
}verem.h:
#ifndef VEREM_H_INCLUDED#define VEREM_H_INCLUDED#define DEFAULT_SIZE 5template <typename t>
class Stack {public:Stack(int=DEFAULT_SIZE);
void push(t);
t pop();
t top()const {return _array[_top];}
int size()const {return _top;}
int maxSize()const {return _max;}
void clear();
bool isEmpty()const{return -1==_top;}
Stack(const Stack&);
Stack& operator = (const Stack&);
~Stack();
private:t* _array;
int _top;
int _max;
};
#endif // VEREM_H_INCLUDEDusing std::cout;
using std::endl;
template <typename t>
Stack<t>::Stack(int max_):_top(-1),_max(max_)
{if(max_>0)
_array=new t[max_];
else {cout<<"The max size must be >0!!"<<endl;
_array=new t[DEFAULT_SIZE];
_max=DEFAULT_SIZE;
}}template <typename t>
void Stack<t>::push(t item_)
{if(_top!=_max)
_array[++_top]=item_;
elsecout<<"The stack is full!!"<<endl;//Iparban is használt megoldás: throw "full"; az "xy" helyett valami exception leszármazotatt szoktak dobni.
}template <typename t>
t Stack<t>::pop()
{if(_top!=-1)
return _array[_top--];
elsecout<<"The stack is empty"<<endl;//Iparban is használt megoldás: throw "empty"; az "xy" helyett valami exception leszármazotatt szoktak dobni.
}template <typename t>
void Stack<t>::clear()
{delete[] _array;
_array=new t[_max];
_top=-1;
}template <typename t>
//deep copy meg kell írni mivel az _array dinamikusan van foglalvaStack<t>::Stack(const Stack& stack_)
{_max=stack_._max;
_top=stack_._top;
_array=new t[_max];
for(int i=0;i<=_top;++i)
_array[i]=stack_._array[i];
}template <typename t>
Stack<t>& Stack<t>::operator = (const Stack& stack_)
{delete[] _array;// Azért kell mivel itt már létezik az objektu, a copy konstruktornál feljebb még nem létezik, hanem akkor jön létre
_max=stack_._max;
_top=stack_._top;
_array=new t[_max];
for(int i=0;i<=_top;++i)
_array[i]=stack_._array[i];
return *this;
}template <typename t>
Stack<t>::~Stack()
{delete[] _array;
}