Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. struct carte
  8. {
  9. char autor[51],titlu[51],editura[51];
  10. float pret;
  11. int an;
  12. };
  13.  
  14. void citire(int &n,carte v[])
  15. {
  16. ifstream f("carti.txt");
  17. int i;
  18. f>>n;
  19. for(i=1;i<=n;i++)
  20. f>>v[i].autor>>v[i].titlu>>v[i].editura>>v[i].an>>v[i].pret;
  21. f.close();
  22. }
  23.  
  24. void meniu()
  25. {
  26. cout<<"1. Listare carti"<<endl<<"2. Cautare dupa autor"<<endl;
  27. cout<<"3. Cautare dupa title"<<endl<<"4. Adaugarea unei carti"<<endl;
  28. cout<<"5. Ordonare descrecatoare dupa pret"<<endl<<"6. Iesire"<<endl;
  29. cout<<"Introduceti optiunea dvs: ";
  30. }
  31.  
  32. void listare(int n, carte v[])
  33. {
  34. for(int i=1;i<=n;i++)
  35. {
  36. cout<<v[i].autor<<" "<<v[i].titlu<<" "<<v[i].editura<<" "<<v[i].an<<" "<<v[i].pret<<endl;
  37. }
  38. }
  39.  
  40. void caut_autor(int n, carte v[])
  41. {
  42. int i, k=0;
  43. char s[51];
  44. cout<<"Ce autor cautati: ";
  45. cin>>s;
  46. for(i=1;i<=n;i++)
  47. {
  48. if(strcmp(s,v[i].autor)==0)
  49. {
  50. cout<<v[i].titlu<<endl;
  51. k++;
  52. }
  53. }
  54. if(k==0) cout<<"Autorul nu exista"<<endl;
  55. }
  56.  
  57. void caut_titlu(int n, carte v[])
  58. {
  59.  
  60. }
  61. void adauga(int n, carte v[])
  62. {
  63.  
  64. }
  65.  
  66. void ordonare(int n, carte v[])
  67. {
  68.  
  69. }
  70. int main()
  71. {
  72. carte v[101];
  73. int n, op;
  74. citire(n,v);
  75. do
  76. {
  77. meniu();
  78. cin>>op;
  79. switch(op)
  80. {
  81. case 1:
  82. listare(n,v); break;
  83. case 2:
  84. caut_autor(n,v); break;
  85. case 3:
  86. caut_titlu(n,v); break;
  87. case 4:
  88. adauga(n,v); break;
  89. case 5:
  90. ordonare(n,v); listare(n,v); break;
  91. case 6:
  92. break;
  93. default: cout<<"Optiune inexistenta"; break;
  94. }
  95. }while(op!=6);
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement