Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include "carte.h"
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. carte::carte()
  7. {
  8. titlu=NULL;
  9. autor=NULL;
  10. an=0;
  11. strcpy(cod,"00000");
  12. }
  13.  
  14. /*
  15. void alocare(char *&titlu, char *&autor)
  16. {
  17. titlu=new char[strlen(titlu)+1];
  18. autor=new char[strlen(autor)+1];
  19. // cod=new char[strlen[autor]+1];
  20.  
  21. }
  22. */
  23. //---------------------------------------------
  24.  
  25. carte::carte(char* s1, char* s2, int x, char s[6])
  26. {
  27.  
  28.  
  29. titlu=new char[strlen(s1)+1];
  30. autor=new char[strlen(s2)+1];
  31. strcpy(titlu,s1);
  32. strcpy(autor,s2);
  33. an=x;
  34. strcpy(cod,s);
  35. }
  36. //-------------AFISAREA----------------
  37.  
  38. void carte::afis()const
  39. {
  40. cout<<"Titlul: "<<titlu<<"\tAutorul: "<<autor<<"\tAnul: "<<an<<endl<<"\tCodul: "<<cod<<endl;
  41. }
  42.  
  43. //----------------------------------------
  44. carte::~carte()
  45. {
  46. if(titlu!=NULL)
  47. delete []titlu;
  48. if(autor!=NULL)
  49. delete []autor;
  50. }
  51. //---------INITIALIZAREA----------
  52.  
  53. void carte::init()
  54. {
  55. cout<<"Titlul: ";
  56. cin>>titlu;
  57.  
  58. cout<<"Autorul: ";
  59. cin>>autor;
  60.  
  61. cout<<"Anul: ";
  62. cin>>an;
  63.  
  64. cout<<"Codul: ";
  65. cin>>cod;
  66. }
  67.  
  68. //----------SORTARE------------
  69.  
  70.  
  71. bool sortare(carte c1,carte c2)
  72. {
  73. return (c1.an<c2.an);
  74. }
  75.  
  76. //---------------------------
  77.  
  78. int main(int argc, char** argv) {
  79. //carte ca("ceva","x",1946,"22222");
  80. //ca.afis();
  81. int n,i;
  82. carte *c;
  83. cout<<"Introduceti numarul de carti: ";
  84. cin>>n;
  85.  
  86.  
  87. c=new carte[n];
  88.  
  89. for(i=0;i<n;i++)
  90. c[i].init();
  91.  
  92. for(i=0;i<n;i++)
  93. c[i].afis();
  94.  
  95.  
  96. return 0;
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103. -----------------------------------------------------------
  104. CARTE.H
  105.  
  106. #include <iostream>
  107.  
  108. class carte
  109. {
  110. char *titlu;
  111. char *autor;
  112. int an;
  113. char cod[6];
  114.  
  115. public:
  116. carte();
  117. carte(char*, char*,int, char[6]);
  118. carte(const carte&);
  119. ~carte();
  120. void afis() const;
  121. void modif(char*, char*, int, char[6]);
  122. void init();
  123. bool sortare(carte, carte);
  124. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement