Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Zadanie 1
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- struct Student
- {
- string imie,nazwisko;
- unsigned int numer;//numer indeksu;
- };
- void wczytaj(int &n,Student *&student ,istream &plik)//Wczytywanie danych z pliku do tablicy dynamicznej
- {
- for(int i=0;i<n;i++)
- {
- plik>>student[i].imie;
- plik>>student[i].nazwisko;
- plik>>student[i].numer;
- }
- }
- void wyswietl(const int &n,Student *&student)//Wyswietlanie wszystkich studentow
- {
- cout<<"***************************************\n";
- for(int i=0;i<n;i++)
- {
- cout<<"Imie : "<<student[i].imie<<"\n";
- cout<<"Nazwisko : "<<student[i].nazwisko<<"\n";
- cout<<"Nr_indexu : "<<student[i].numer<<"\n";
- }
- cout<<"***************************************\n";
- }
- void wyswietl(Student *&student)//wyswietlanie pojedynczego studenta
- {
- int a=0;
- cout<<"Dane ktorego studenta chcesz wypisac? : ";
- cin>>a;
- a=a-1;//z racji ze tablica jest numerowana od 0 to dekrementuje zmienna a o 1
- cout<<"***************************************\n";
- cout<<"Imie : "<<student[a].imie<<"\n";
- cout<<"Nazwisko : "<<student[a].nazwisko<<"\n";
- cout<<"Nr_indexu : "<<student[a].numer<<"\n";
- cout<<"***************************************\n";
- }
- Student edit(Student *&student)
- {
- int a=0,wybor=0;
- cout<<"Wybierz studenta ktorego dane chcesz edytowac : ";
- cin>>a;
- a-=1;
- cout<<"[1] - Imie \n";
- cout<<"[2] - Nazwisko \n";
- cout<<"[3] - Nr_indexu \n";
- cout<<"Wybierz ktory element chcesz edytowac : "<<endl;
- cin>>wybor;
- switch(wybor)
- {
- case 1:
- {
- cout<<"Podaj nowe Imie : ";
- cin>>student[a].imie;
- break;
- }
- case 2:
- {
- cout<<"Podaj nowe Nazwisko : ";
- cin>>student[a].nazwisko;
- break;
- }
- case 3:
- {
- cout<<"Podaj nowe Nr_indexu : ";
- cin>>student[a].numer;
- break;
- }
- }
- return student[a];
- }
- void zapisz(int &n,Student *&student)
- {
- fstream wynik;
- wynik.open("wynik.txt", ios::out);
- wynik<<n<<"\n";
- for(int i=0;i<n;i++)
- {
- wynik<<student[i].imie<<" ";
- wynik<<student[i].nazwisko<<" ";
- wynik<<student[i].numer<<"\n";
- }
- wynik.close();
- }
- int main()
- {
- ifstream plik("dane.txt");
- if(!plik.good())
- {
- cout<<"plik nie zostal wczytany"<<endl;
- }
- int n=0;
- plik>>n;
- Student * student = new Student[n];
- wczytaj(n,student,plik);
- wyswietl(student);
- wyswietl(n,student);
- edit(student);
- wyswietl(n,student);
- zapisz(n,student);
- delete [] student;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement