Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "carte.h"
- #include <iostream>
- #include <cstring>
- using namespace std;
- carte::carte()
- {
- titlu=NULL;
- autor=NULL;
- an=0;
- strcpy(cod,"00000");
- }
- /*
- void alocare(char *&titlu, char *&autor)
- {
- titlu=new char[strlen(titlu)+1];
- autor=new char[strlen(autor)+1];
- // cod=new char[strlen[autor]+1];
- }
- */
- //---------------------------------------------
- carte::carte(char* s1, char* s2, int x, char s[6])
- {
- titlu=new char[strlen(s1)+1];
- autor=new char[strlen(s2)+1];
- strcpy(titlu,s1);
- strcpy(autor,s2);
- an=x;
- strcpy(cod,s);
- }
- //-------------AFISAREA----------------
- void carte::afis()const
- {
- cout<<"Titlul: "<<titlu<<"\tAutorul: "<<autor<<"\tAnul: "<<an<<endl<<"\tCodul: "<<cod<<endl;
- }
- //----------------------------------------
- carte::~carte()
- {
- if(titlu!=NULL)
- delete []titlu;
- if(autor!=NULL)
- delete []autor;
- }
- //---------INITIALIZAREA----------
- void carte::init()
- {
- cout<<"Titlul: ";
- cin>>titlu;
- cout<<"Autorul: ";
- cin>>autor;
- cout<<"Anul: ";
- cin>>an;
- cout<<"Codul: ";
- cin>>cod;
- }
- //----------SORTARE------------
- bool sortare(carte c1,carte c2)
- {
- return (c1.an<c2.an);
- }
- //---------------------------
- int main(int argc, char** argv) {
- //carte ca("ceva","x",1946,"22222");
- //ca.afis();
- int n,i;
- carte *c;
- cout<<"Introduceti numarul de carti: ";
- cin>>n;
- c=new carte[n];
- for(i=0;i<n;i++)
- c[i].init();
- for(i=0;i<n;i++)
- c[i].afis();
- return 0;
- }
- -----------------------------------------------------------
- CARTE.H
- #include <iostream>
- class carte
- {
- char *titlu;
- char *autor;
- int an;
- char cod[6];
- public:
- carte();
- carte(char*, char*,int, char[6]);
- carte(const carte&);
- ~carte();
- void afis() const;
- void modif(char*, char*, int, char[6]);
- void init();
- bool sortare(carte, carte);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement