Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib> // Standard General Utilities Library
- #include <cstdio> // Input/Output operations (C)
- #include <iostream> // Input/Output stream objects
- #include <iomanip> // Input/Output manipulator
- using namespace std;
- class studentas {
- private:
- public:
- long id;
- double avg;
- studentas *next;
- };
- void AddFirst(studentas *first) {
- cout << "Iveskite ID: "; cin >> first->id;
- cout<< "Iveskite vidurki: "; cin >> first->avg;
- first->next = NULL;
- }
- void Add(studentas *last) {
- while (last->next != NULL)
- last = last->next;
- studentas *newlast = new studentas;
- cout << "\nIveskite ID: "; cin >> newlast->id;
- cout<< "Iveskite vidurki: "; cin >> newlast->avg;
- newlast->next = NULL;
- last->next = newlast;
- }
- void print(studentas *last) {
- while (last->next != NULL)
- {
- cout << "\nID: " << last->id << endl;
- cout <<"Vidurkis: " << last->avg << endl;
- last = last->next;
- }
- cout << "\nID: " << last->id << endl;
- cout <<"Vidurkis: " << last->avg << endl;
- }
- // Main program
- int main(int argc, char *argv[]) {
- studentas *first = new studentas;
- AddFirst(first);
- for (int i = 0; i < 2; i++)
- Add(first);
- print(first);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement