Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdlib.h>
  4. using namespace std;
  5. struct student{
  6. char nume[20],prenume[20],specializarea[20],telefon[20];
  7. int an,matricol;
  8. }s[100];
  9. int n,opt;
  10. ifstream f("studenti.txt");
  11. void citire(student v[100],int &n)
  12. {
  13. f>>n;
  14. for(int i=1;i<=n;i++)
  15. {
  16. f>>v[i].nume;
  17. f>>v[i].prenume;
  18. f>>v[i].matricol;
  19. f>>v[i].specializarea;
  20. f>>v[i].telefon;
  21. f>>v[i].an;
  22. }
  23. }
  24. void adaugare(student v[100],int &n)
  25. {
  26. ofstream f("studenti.txt");
  27. n++;
  28. cout<<"Numele: ";cin>>v[n].nume;
  29. cout<<"Prenumele: ";cin>>v[n].prenume;
  30. cout<<"Matricol: ";cin>>v[n].matricol;
  31. cout<<"Specializarea: ";cin>>v[n].specializarea;
  32. cout<<"Telefon: ";cin>>v[n].telefon;
  33. cout<<"An: ";cin>>v[n].an;
  34. //scrierea in fisier
  35. f<<n<<endl;
  36. for(int i=1;i<=n;i++)
  37. {
  38. f<<v[i].nume<<endl;
  39. f<<v[i].prenume<<endl;
  40. f<<v[i].matricol<<endl;
  41. f<<v[i].specializarea<<endl;
  42. f<<v[i].telefon<<endl;
  43. f<<v[i].an<<endl;
  44. }
  45. }
  46. void afisare(student v[100],int n)
  47. {
  48. for(int i=1;i<=n;i++)
  49. {
  50. cout<<v[i].nume<<endl;
  51. cout<<v[i].prenume<<endl;
  52. cout<<v[i].matricol<<endl;
  53. cout<<v[i].specializarea<<endl;
  54. cout<<v[i].telefon<<endl;
  55. cout<<v[i].an<<endl;
  56. cout<<endl;
  57. }
  58. }
  59. void stergere(student v[100],int &n)
  60. {
  61. int nr,i,poz;
  62. cout<<"Introduceti numarul matricol al studentului: ";
  63. cin>>nr;
  64. for(i=1;i<=n;i++)
  65. if(nr==v[i].matricol)poz=i;
  66. if(poz>n)cout<<"Nu exista numarul matricol!"<<endl<<endl;
  67. else
  68. {
  69. for(i=poz;i<n;i++)
  70. v[i]=v[i+1];
  71. n=n-1;
  72. cout<<"Studentul a fost sters."<<endl<<endl;
  73. //scrierea in fisier
  74. ofstream f("studenti.txt");
  75. f<<n<<endl;
  76. for(int i=1;i<=n;i++)
  77. {
  78. f<<v[i].nume<<endl;
  79. f<<v[i].prenume<<endl;
  80. f<<v[i].matricol<<endl;
  81. f<<v[i].specializarea<<endl;
  82. f<<v[i].telefon<<endl;
  83. f<<v[i].an<<endl;
  84. }
  85. }
  86. }
  87. int main()
  88. {citire(s,n);
  89. f.close();
  90. while(opt!=5)
  91. {
  92. system("cls");
  93. cout<<endl<<"Facultatea de Matematica"<<endl<<endl;
  94. cout<<"1.Afisare studenti"<<endl;
  95. cout<<"2.Adaugare studenti"<<endl;
  96. cout<<"3.Stergere studenti"<<endl;
  97. cout<<"4.Modificare date student"<<endl;
  98. cout<<"5.Iesire"<<endl;
  99. cout<<"Introduceti optiunea: "<<endl;
  100. cin>>opt;
  101. switch(opt)
  102. {
  103. case 1:{system("cls");
  104. cout<<("Afisarea studentilor")<<endl<<endl;
  105. afisare(s,n);
  106. break;
  107. }
  108. case 2:{system("cls");
  109. cout<<("Adaugarea unui student")<<endl<<endl;
  110. adaugare(s,n);
  111. break;
  112. }
  113. case 3:{system("cls");
  114. cout<<("Stergerea unui student")<<endl<<endl;
  115. stergere(s,n);
  116. break;
  117. }
  118. case 4:{system("cls");
  119. cout<<"Modificare date"<<endl<<endl;
  120. cout<<"Introduceti un numar matricol";
  121. int nr.matricol;
  122. cin>>nr.matricol;
  123. while(opt1!=7)
  124. {
  125. cout<<"1.Nume: "<<endl;
  126. cout<<"2.Prenume: "<<endl;
  127. cout<<"3.Nr.Matricol: "<<endl;
  128. cout<<"4.Specializare: "<<endl;
  129. cout<<"5.Telefon: "<<endl;
  130. cout<<"6.An: "<<endl;
  131. cout<<"7.Iesire: "<<endl;
  132. cout<<"Introduceti optiunea: ";
  133. cin>>opt1;
  134. }
  135. switch(opt1)
  136. {
  137. case 1:
  138. }
  139. }
  140. }
  141. }
  142.  
  143. return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement