Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<string>
- using namespace std;
- struct book {
- string name;
- string autor;
- double price;
- int year[100];
- };
- const int n=3;
- void input(book&);
- void print(book&);
- void sortprice(book*, double);
- int main() {
- int i,n;
- cin >> n;
- book library[100];
- for ( i = 0; i < n; i++)
- {
- input(library[i]);
- cout << endl;
- }
- for (i = 0; i < n; i++)
- {
- print(library[i]);
- cout << endl;
- }
- sortprice(library, n);
- for (i = 0; i < n; i++)
- {
- print(library[i]);
- cout << endl;
- }
- return 0;
- }
- void input(book& P) {
- cout << "Vavedete imeto na kigata:"; cin>>P.name ;
- cout << "Vavedete imeto na avtora:"; cin >> P.autor;
- cout << "Vavedete price na kigata:"; cin >> P.price;
- cout << "Vavedete year na izdavane:";
- for (int i = 0; i < n; i++)
- {
- cin >> P.year[i];
- }
- }
- void print(book& P) {
- cout << "Imeto na kigata :" << P.name << endl;
- cout << "Autor na kigata :" << P.autor << endl;
- cout << "Price na kigata :" << P.price << endl;
- cout << "Kigata e izdadena :" << P.year << endl;
- }
- void sortprice(book* a, double x){
- for (int i = 0; i < n; i++)
- {
- for (int j = 1; j < n; j++)
- {
- if (a[i].year > a[j].year)
- swap(a[i], a[j]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement